-
Notifications
You must be signed in to change notification settings - Fork 299
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
Add pythonpath "." before loading modules #2673
Conversation
Signed-off-by: Nelson Chen <[email protected]>
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #2673 +/- ##
==========================================
- Coverage 78.91% 77.59% -1.33%
==========================================
Files 316 278 -38
Lines 24965 23394 -1571
Branches 4012 4012
==========================================
- Hits 19702 18152 -1550
+ Misses 4548 4521 -27
- Partials 715 721 +6 ☔ View full report in Codecov by Sentry. |
Signed-off-by: Nelson Chen <[email protected]>
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.
Could you also remove the PYTHONPATH from this dockerfile? Just want to make sure it works in the integration tests after we remove the PYTHONPATH.
flytekit/bin/entrypoint.py
Outdated
@@ -376,6 +376,9 @@ def _execute_task( | |||
dynamic_addl_distro, | |||
dynamic_dest_dir, | |||
) as ctx: | |||
import sys | |||
|
|||
sys.path.append(".") |
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.
nit
sys.path.append(".") | |
if "." not in sys.path: | |
sys.path.append(".") |
Signed-off-by: Nelson Chen <[email protected]>
@pingsutw I has removed the pythonpath in Dockerfile.dev. |
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.
do you know what happens if both the current working directory, as an absolute path, and this new '.' are both in the sys path? does that affect python module loading at all?
@wild-endeavor I think append "." into sys.path is not going to affect python module loading. Just to make sure that user defined Dockerfile works without pythonpath=/root |
flytekit/bin/entrypoint.py
Outdated
if "." not in sys.path: | ||
sys.path.append(".") |
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 think it's best to be explicit here and add the fully path for the current working directory:
if "." not in sys.path: | |
sys.path.append(".") | |
sys.path.append(os.getcwd()) |
Although, I do not think there is harm to include the working directory twice. If you want to make sure to not add the working directory twice:
working_dir = os.getcwd()
if all(os.path.realpath(path) != working_dir for path in sys.path):
sys.path.append(working_dir)
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.
Yes agreed. This seems safer than adding .
. I'm worried about users who use both .relative
imports as well as absolute imports. We've seen weird cases of repeat-importing of modules before.
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.
Got it. Thank you for your advice.
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.
Could we add dest_dir to PYTHONPATH as well?
Yea, that would give a better experience. In that case, I would inject it into flytekit/flytekit/bin/entrypoint.py Line 545 in 4309c5e
I'll say do it in another PR, so we can discuss |
Signed-off-by: Nelson Chen <[email protected]>
Signed-off-by: Nelson Chen <[email protected]>
I think i will create another PR to discuss |
yeah let's discuss dest dir in another pr... if we ever move to a different model, like one where another worker maybe written in a different language is first in charge of downloading and extracting the package, it may be weird for that worker to be setting the pythonpath. |
Signed-off-by: Nelson Chen <[email protected]>
@thomasjpfan @wild-endeavor @pingsutw |
I think it's possible to have For example, one can set |
Signed-off-by: Nelson Chen <[email protected]>
Got it. Thank you. i will create another PR to discuss dest_dir |
Signed-off-by: Nelson Chen <[email protected]>
Signed-off-by: Nelson Chen <[email protected]>
@@ -50,8 +50,5 @@ RUN SETUPTOOLS_SCM_PRETEND_VERSION_FOR_FLYTEKIT=$PSEUDO_VERSION \ | |||
&& chown flytekit: /home \ | |||
&& : | |||
|
|||
|
|||
ENV PYTHONPATH="/flytekit:/flytekit/plugins/flytekit-k8s-pod:/flytekit/plugins/flytekit-deck-standard:" |
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.
removing this broke flyteremote integration tests due to the way tasks+workflows are registered. The tests end up present in the image under the tests
module, which lives under the flytekit
directory and since we had /flytekit
as part of PYTHONPATH
the task was able to be run once pyflyte-execute
ran.
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.
fix in #2701.
Tracking issue
Why are the changes needed?
Sometimes User defined Dockfile is missing "ENV PYTHONPATH /root", it will cause execute errors.
What changes were proposed in this pull request?
This change will add pythonpath "." before loading modules
How was this patch tested?
build a docker image with Dockfile missing "ENV PYTHONPATH /root"
Setup process
Screenshots
Check all the applicable boxes
Related PRs
Docs link