From 86752e9a55281200715749d75a88cf57bf2e7b01 Mon Sep 17 00:00:00 2001 From: Josip Sokcevic Date: Wed, 3 Jan 2024 21:16:10 +0000 Subject: [PATCH] Update repo_launcher to 2.40 Bug: 1515383 Change-Id: Iaae10a7482e09943ea8b84bb97d97ebbf2dff642 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/5166208 Commit-Queue: Mike Frysinger Auto-Submit: Josip Sokcevic Reviewed-by: Mike Frysinger --- repo_launcher | 47 ++++++++++++----------------------------------- 1 file changed, 12 insertions(+), 35 deletions(-) diff --git a/repo_launcher b/repo_launcher index 2738142112..2dd9dd909b 100755 --- a/repo_launcher +++ b/repo_launcher @@ -79,17 +79,6 @@ def check_python_version(): major = ver.major minor = ver.minor - # Abort on very old Python 2 versions. - if (major, minor) < (2, 7): - print( - "repo: error: Your Python version is too old. " - "Please use Python {}.{} or newer instead.".format( - *MIN_PYTHON_VERSION_SOFT - ), - file=sys.stderr, - ) - sys.exit(1) - # Try to re-exec the version specific Python 3 if needed. if (major, minor) < MIN_PYTHON_VERSION_SOFT: # Python makes releases ~once a year, so try our min version +10 to help @@ -134,16 +123,7 @@ def check_python_version(): reexec("python3") # We're still here, so diagnose things for the user. - if major < 3: - print( - "repo: error: Python 2 is no longer supported; " - "Please upgrade to Python {}.{}+.".format( - *MIN_PYTHON_VERSION_HARD - ), - file=sys.stderr, - ) - sys.exit(1) - elif (major, minor) < MIN_PYTHON_VERSION_HARD: + if (major, minor) < MIN_PYTHON_VERSION_HARD: print( "repo: error: Python 3 version is too old; " "Please use Python {}.{} or newer.".format( @@ -170,7 +150,7 @@ if not REPO_REV: BUG_URL = "https://issues.gerritcodereview.com/issues/new?component=1370071" # increment this whenever we make important changes to this script -VERSION = (2, 39) +VERSION = (2, 40) # increment this if the MAINTAINER_KEYS block is modified KEYRING_VERSION = (2, 3) @@ -274,19 +254,8 @@ import optparse import re import shutil import stat - - -if sys.version_info[0] == 3: - import urllib.error - import urllib.request -else: - import imp - - import urllib2 - - urllib = imp.new_module("urllib") - urllib.request = urllib2 - urllib.error = urllib2 +import urllib.error +import urllib.request repo_config_dir = os.getenv("REPO_CONFIG_DIR", os.path.expanduser("~")) @@ -1525,6 +1494,14 @@ def main(orig_args): if reqs: 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)) me = [ sys.executable,