-
Notifications
You must be signed in to change notification settings - Fork 903
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
-y flag for libyosys Python scripts #4553
Conversation
31f9bfc
to
1cb7467
Compare
Any feedback on this? (The Verific test is failing because of security reasons- I'm a first-time contributor) |
That should be fixed by #4552, you may need to merge/rebase on latest main to get the fix though |
1cb7467
to
b047cb7
Compare
f971361
to
83617a6
Compare
Rebased on the wrong upstream for a second there but should be fine now :) |
0566f89
to
6c391d2
Compare
This adds a Python equivalent to the `-c` option, where scripts importing `libyosys` can be imported and used. Most of the work for this was already done to enable Python passes a couple years back, so this is a relatively small changeset.
This matches the behavior of running a Python interpreter, where the first element of sys.path is the dirname of the script being run. This allows importing of files and modules in the same directory without messing with PYTHONPATH or similar.
6c391d2
to
8dac271
Compare
* Less brittle method of adding script dirname to sys.path * Check if scriptfp successfully opens before using it * Move `log_error` to after `PyErr_Print()` is called
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested here, looks good, though I haven't vetted the usage of the CPython API and the error handling paths around it
What are the reasons/motivation for this change?
This adds a Python equivalent to the
-c
option, where scripts importinglibyosys
can be used.Most of the requisite work for this was already done to enable Python passes a couple years back, so this is a relatively small changeset, and would add another option for supporting libyosys-based scripts (that does not involve PYTHONPATH shenanigans.)
Explain how this is achieved.
Adding a new opt,
-y
(-p
and-P
were already taken,) and runningPyRun_SimpleFile
onscriptfile
. Similar to-c
for Tcl, any unprocessed arguments are passed to the script in the form ofsys.argv
.If applicable, please suggest to reviewers how they can test the change.