-
-
Notifications
You must be signed in to change notification settings - Fork 698
fix: avoid stage1 bootstrap stdlib shadowing #3854
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
Open
gleyba
wants to merge
5
commits into
bazel-contrib:main
Choose a base branch
from
gleyba:fix-stage1-stdlib-shadowing
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+77
−5
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
1144d6b
fix: avoid stage1 bootstrap stdlib shadowing
gleyba f5ed6b5
fix: pin venv bat template line endings
gleyba 05dbf1b
fix: respect isolated bootstrap sys path
gleyba 6c2d4a8
Merge remote-tracking branch 'upstream/main' into fix-stage1-stdlib-s…
gleyba bcf5961
style: format bootstrap template
gleyba File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,13 +5,31 @@ from __future__ import absolute_import | |
| from __future__ import division | ||
| from __future__ import print_function | ||
|
|
||
| import sys | ||
|
|
||
| # By default, Python prepends the directory containing this script to | ||
| # sys.path. The stage 1 bootstrap only needs stdlib modules before it | ||
| # re-execs into the configured runtime, so avoid resolving imports from the | ||
| # target's output or runfiles package directory. This matters when that | ||
| # directory contains files with stdlib names, such as shutil.py or types.py. | ||
| # | ||
| # Python 3.11 introduced PYTHONSAFEPATH (-P), which disables the unsafe prepend. | ||
| # Isolated mode (-I) also disables it, including on older interpreters without | ||
| # safe_path. In either case, sys.path[0] is not the script directory and should | ||
| # be preserved. | ||
| if ( | ||
| not getattr(sys.flags, "safe_path", False) and | ||
| not getattr(sys.flags, "isolated", False) and | ||
| sys.path | ||
| ): | ||
| del sys.path[0] | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I remember the |
||
|
|
||
| # Generated file from @rules_python//python/private:python_bootstrap_template.txt | ||
|
|
||
| from os.path import abspath, dirname, join, basename, normpath | ||
| import os | ||
| import shutil | ||
| import subprocess | ||
| import sys | ||
|
|
||
| # NOTE: The sentinel strings are split (e.g., "%stage2" + "_bootstrap%") so that | ||
| # the substitution logic won't replace them. This allows runtime detection of | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| # Copyright 2026 The Bazel Authors. All rights reserved. | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
| """Verifies stage 1 bootstrap stdlib imports cannot be shadowed.""" | ||
|
|
||
|
|
||
| def test_bootstrap_reached_main(): | ||
| # If stage 1 imports target outputs such as shutil.py instead of stdlib | ||
| # modules, the process fails before this test module is executed. | ||
| pass |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Is this an intended change?