mirror of
https://gerrit.googlesource.com/git-repo
synced 2024-12-21 07:16:21 +00:00
repo: add repo main script's directory to PYTHONPATH.
Python 3.11 introduces PYTHONSAFEPATH and the -P flag which, if enabled, does not prepend the script's directory to sys.path by default. This breaks repo because main.py expects its own directory to be part of Python's import path. This causes problems with tools that add PYTHONSAFEPATH to python programs, most notably Bazel. We will simply prepend main.py's path to PYTHONPATH instead. Bug: 307767740 Change-Id: I94f3fda50213e450df0d1e2df6a0b8b597416973 Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/391236 Tested-by: Duy Truong <duytruong@google.com> Commit-Queue: Mike Frysinger <vapier@google.com> Reviewed-by: Mike Frysinger <vapier@google.com>
This commit is contained in:
parent
c287428b37
commit
9f0ef5d926
8
repo
8
repo
@ -1494,6 +1494,14 @@ def main(orig_args):
|
|||||||
if reqs:
|
if reqs:
|
||||||
reqs.assert_all()
|
reqs.assert_all()
|
||||||
|
|
||||||
|
# Python 3.11 introduces PYTHONSAFEPATH and the -P flag which, if enabled,
|
||||||
|
# does not prepend the script's directory to sys.path by default.
|
||||||
|
# repo relies on this import path, so add directory of REPO_MAIN to
|
||||||
|
# PYTHONPATH so that this continues to work when PYTHONSAFEPATH is enabled.
|
||||||
|
python_paths = os.environ.get("PYTHONPATH", "").split(os.pathsep)
|
||||||
|
new_python_paths = [os.path.join(rel_repo_dir, S_repo)] + python_paths
|
||||||
|
os.environ["PYTHONPATH"] = os.pathsep.join(new_python_paths)
|
||||||
|
|
||||||
ver_str = ".".join(map(str, VERSION))
|
ver_str = ".".join(map(str, VERSION))
|
||||||
me = [
|
me = [
|
||||||
sys.executable,
|
sys.executable,
|
||||||
|
Loading…
Reference in New Issue
Block a user