-
Notifications
You must be signed in to change notification settings - Fork 214
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
Make local modules importable when running verdi run
#3700
Make local modules importable when running verdi run
#3700
Conversation
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.
I don't think this works, for 2 reasons:
sys.path.append
appends in place, so it returnsNone
- I don't think adding a key
sys.path
to the global dict does the trick
The right approach would be to add
import os
sys.path.append(os.path.abspath(os.curdir))
in update_environment
, ideally storing a copy into a variable _path
before appending, and then resetting after the yield
@giovannipizzi , thanks you are right. It just "worked" by accident. I tested it by doing the following. I created a folder
and a file
Calling
With my original "fix" the problem was solved but not for the reasons I thought. Simply the act of calling |
f6b8d37
to
fbfe381
Compare
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.
Thanks! One more thing, I think this is not enough to restore the path, since _path is just a reference and not a copy and also when restored will still have the appended content. I think it should be defined as a copy
Running a python script through `verdi run` from its local directory that imports from a module in the same directory would yield an `ModuleNotFoundError`. The problem is because the current working directory was not being passed in the `sys.path` of the exec'ed file.
fbfe381
to
4be8c8c
Compare
really sorry @giovannipizzi for the sloppyness; my head must be already at christmas dinner :) |
Fixes #3624
Running a python script through
verdi run
from its local directorythat imports from a module in the same directory would yield an
ModuleNotFoundError
. The problem is because the current workingdirectory was not being passed in the
sys.path
of the exec'ed file.