-
Notifications
You must be signed in to change notification settings - Fork 543
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
fix: only delete first sys.path entry in the stage-2 bootstrap if PYTHONSAFEPATH is unset or unsupported #2418
base: main
Are you sure you want to change the base?
Conversation
|
||
# < Python 3.11 behaviour | ||
if (major, minor) < (3, 11): | ||
# Because of https://github.com/bazelbuild/rules_python/blob/0.39.0/python/private/stage2_bootstrap_template.py#L415-L436 |
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.
Whilst adding tests for this change, I discovered what might be another bug?
This snippet always executes on Python 3.10 and below, because safe_path
hasn't been implemented yet.
But it will never execute on Python 3.11, because PYTHONSAFEPATH
is unconditionally set in stage 1.
Not sure if this is expected behaviour.
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.
Hmm, I wish I could remember what this was about, exactly. Maybe if I went and dug through the change history...
This might be about how PYTHONSAFEPATH being set by the outer environment is respected (by the bootstrap impl). While stage1 bootstrap will set it by default, it first checks to see if the outer environment has set it. If so, it'll respect that.
Thanks for the PR. This mostly LGTM. Just need to use a non-integration test for this instead. See comment. |
75c5ea9
to
4319193
Compare
Hrm. I think "intended behavior" here is all murky. I'm pretty sure the intent of At the least, we can confidently say: for 3.11 and later, there shouldn't be any |
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.
LGTM, I agree with the reasoning in @rickeylev's message above.
Ok, I think I know what this logic is about. It's fixing up the path0 entry to point to the proper directory (runfiles instead of the filepath on the command line). At startup, path0 looks like e.g. But, that directory doesn't have much in it, plus it means things outside the runfiles become importable. So the later Hence, if safe path is disabled, we have to go manipulating sys.path. If safe path is enabled, then there is nothing to manipulate. I did come across an edge case while looking into this: I happen to have PYTHONPATH set in my env. on python 3.11, because of that |
This PR should address that problem, shouldn't it? The burning question I have is - should Removing it will have all Python versions behave identically, and in line with historical behaviour. Is there something undesirable about having the script's directory (where it doesn't follow symlinks) in |
59dfcee
to
b788eb2
Compare
Pretty sure the build failures with It's because |
I think that PYTHONSAFEPATH was being set in the python template in the bazel repo since quite a while ago, so the historic behaviour might be to have PYTHONSPAFEPATH to be used if it is possible. However I can't find a link to the old source quickly, so my memory may be failing me. |
2f5b78b
to
6f816cd
Compare
…THONSAFEPATH is unset or unsupported
6f816cd
to
c2ebbc4
Compare
Unnconditionally deleting the first
sys.path
entry on the stage-2 bootstrap incorrecly removes a valid search path on Python 3.11 and above, sincePYTHONSAFEPATH
is already unconditionally set in stage-1.It should be deleted only if it is unset or unsupported.
Fixes #2318