diff options
author | Peter Kjellerstedt <pkj@axis.com> | 2023-11-03 17:22:40 +0100 |
---|---|---|
committer | LUCI <gerrit-scoped@luci-project-accounts.iam.gserviceaccount.com> | 2023-12-15 06:49:27 +0000 |
commit | 172c58398b340f30bad1902aebba9d198b5786f4 (patch) | |
tree | a190d060bf04736e12e0c8a30710d78241e02928 | |
parent | aa506db8a76e224fadbeabb5b83661805c791bb2 (diff) | |
download | git-repo-172c58398b340f30bad1902aebba9d198b5786f4.tar.gz |
repo: Drop reexec of python3 from check_python_version()
This simplifies check_python_version() since there is no point in trying
to fall back to python3, as we are already running using some Python 3
interpreter.
Change-Id: I9dfdd002b4ef5567e064d3d6ca98ee1f3410fd48
Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/397759
Reviewed-by: Mike Frysinger <vapier@google.com>
Tested-by: Peter Kjellerstedt <peter.kjellerstedt@axis.com>
Commit-Queue: Peter Kjellerstedt <peter.kjellerstedt@axis.com>
-rwxr-xr-x | repo | 30 |
1 files changed, 2 insertions, 28 deletions
@@ -79,7 +79,7 @@ def check_python_version(): | |||
79 | major = ver.major | 79 | major = ver.major |
80 | minor = ver.minor | 80 | minor = ver.minor |
81 | 81 | ||
82 | # Try to re-exec the version specific Python 3 if needed. | 82 | # Try to re-exec the version specific Python if needed. |
83 | if (major, minor) < MIN_PYTHON_VERSION_SOFT: | 83 | if (major, minor) < MIN_PYTHON_VERSION_SOFT: |
84 | # Python makes releases ~once a year, so try our min version +10 to help | 84 | # Python makes releases ~once a year, so try our min version +10 to help |
85 | # bridge the gap. This is the fallback anyways so perf isn't critical. | 85 | # bridge the gap. This is the fallback anyways so perf isn't critical. |
@@ -96,36 +96,10 @@ def check_python_version(): | |||
96 | break | 96 | break |
97 | reexec(f"python{min_major}.{min_minor - inc}") | 97 | reexec(f"python{min_major}.{min_minor - inc}") |
98 | 98 | ||
99 | # Try the generic Python 3 wrapper, but only if it's new enough. If it | ||
100 | # isn't, we want to just give up below and make the user resolve things. | ||
101 | try: | ||
102 | proc = subprocess.Popen( | ||
103 | [ | ||
104 | "python3", | ||
105 | "-c", | ||
106 | "import sys; " | ||
107 | "print(sys.version_info.major, sys.version_info.minor)", | ||
108 | ], | ||
109 | stdout=subprocess.PIPE, | ||
110 | stderr=subprocess.PIPE, | ||
111 | ) | ||
112 | (output, _) = proc.communicate() | ||
113 | python3_ver = tuple(int(x) for x in output.decode("utf-8").split()) | ||
114 | except (OSError, subprocess.CalledProcessError): | ||
115 | python3_ver = None | ||
116 | |||
117 | # If the python3 version looks like it's new enough, give it a try. | ||
118 | if ( | ||
119 | python3_ver | ||
120 | and python3_ver >= MIN_PYTHON_VERSION_HARD | ||
121 | and python3_ver != (major, minor) | ||
122 | ): | ||
123 | reexec("python3") | ||
124 | |||
125 | # We're still here, so diagnose things for the user. | 99 | # We're still here, so diagnose things for the user. |
126 | if (major, minor) < MIN_PYTHON_VERSION_HARD: | 100 | if (major, minor) < MIN_PYTHON_VERSION_HARD: |
127 | print( | 101 | print( |
128 | "repo: error: Python 3 version is too old; " | 102 | "repo: error: Python version is too old; " |
129 | "Please use Python {}.{} or newer.".format( | 103 | "Please use Python {}.{} or newer.".format( |
130 | *MIN_PYTHON_VERSION_HARD | 104 | *MIN_PYTHON_VERSION_HARD |
131 | ), | 105 | ), |