-
Notifications
You must be signed in to change notification settings - Fork 8
feat: set the __file__ variable for scripts loaded from files #37
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
Conversation
|
The tests related to parameter-passing are failing now because |
|
Ok, fixed all the tests except the freecad one, which was already failing. |
|
Thanks @justbuchanan . I will fix the FreeCAD test separately, it does not need to delay this PR. Are there any cases where injecting |
|
Thanks for taking a look!
Not that I'm aware of. In normal python execution, |
|
One drawback I've thought of is that when users get a stack trace, the line number will be one off from their local copy of the code since a line was injected at the start of the script. |
jmwright
left a comment
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.
Looks good @justbuchanan . Let me know if you have any thoughts on shifting the stack trace line number down by one. I think we can merge as-is since cq-cli is more of a production tool than a development tool.
|
That's a fair point about the stack trace line numbers being off by 1. Looking at this again, a better solution would probably be to pass a value for |
Implements #36.
This works by simply prepending
__file__ = <path>at the top of the script if it's loaded from an on-disk path (not stdout).I think it's debatable whether this is the most correct/pythonic approach for importing python modules (outlined in #36) as opposed to doing something like
PYTHONPATH=path/to/other/modules cq-cli .... However, I am also using__file__to find and load resources like stl/step files that exist in the project relative to the model file andPYTHONPATHdoesn't really work there.