summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDuy Truong <duytruong@google.com>2023-10-27 11:35:34 -0700
committerLUCI <gerrit-scoped@luci-project-accounts.iam.gserviceaccount.com>2023-11-29 11:50:53 +0000
commit9f0ef5d926b29cabf8509be1b777c24c192c5e21 (patch)
tree353b9087b08273a18f0dc73ffc860bc33e29cde8
parentc287428b37c485edeaefbbfb1b99ceb20cc303f6 (diff)
downloadgit-repo-9f0ef5d926b29cabf8509be1b777c24c192c5e21.tar.gz
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>
-rwxr-xr-xrepo8
1 files changed, 8 insertions, 0 deletions
diff --git a/repo b/repo
index 704bb2eb..2dd9dd90 100755
--- a/repo
+++ b/repo
@@ -1494,6 +1494,14 @@ def main(orig_args):
1494 if reqs: 1494 if reqs:
1495 reqs.assert_all() 1495 reqs.assert_all()
1496 1496
1497 # Python 3.11 introduces PYTHONSAFEPATH and the -P flag which, if enabled,
1498 # does not prepend the script's directory to sys.path by default.
1499 # repo relies on this import path, so add directory of REPO_MAIN to
1500 # PYTHONPATH so that this continues to work when PYTHONSAFEPATH is enabled.
1501 python_paths = os.environ.get("PYTHONPATH", "").split(os.pathsep)
1502 new_python_paths = [os.path.join(rel_repo_dir, S_repo)] + python_paths
1503 os.environ["PYTHONPATH"] = os.pathsep.join(new_python_paths)
1504
1497 ver_str = ".".join(map(str, VERSION)) 1505 ver_str = ".".join(map(str, VERSION))
1498 me = [ 1506 me = [
1499 sys.executable, 1507 sys.executable,