Bug 1755530: Remove python_executable_version() r=glandium

* The python2/python3 lookup logic is obsolete, we can always depend on
  `sys.executable` since Mach starts with a Python version check
* `MozbuildObject`'s `python3` property was unused, which means that all
  of this removed code was dead anyways.

Differential Revision: https://phabricator.services.mozilla.com/D138824
This commit is contained in:
Mitchell Hentges 2022-02-18 14:18:26 +00:00
parent 1f97f6e796
commit 6b25424737
2 changed files with 0 additions and 101 deletions

View File

@ -38,7 +38,6 @@ from .mozconfig import (
MozconfigLoadException,
MozconfigLoader,
)
from .pythonutil import find_python3_executable
from .util import (
memoize,
memoized_property,
@ -547,25 +546,6 @@ class MozbuildObject(ProcessExecutionMixin):
return BuildReader(config, finder=finder)
@memoized_property
def python3(self):
"""Obtain info about a Python 3 executable.
Returns a tuple of an executable path and its version (as a tuple).
Either both entries will have a value or both will be None.
"""
# Search configured build info first. Then fall back to system.
try:
subst = self.substs
if "PYTHON3" in subst:
version = tuple(map(int, subst["PYTHON3_VERSION"].split(".")))
return subst["PYTHON3"], version
except BuildEnvironmentNotFoundException:
pass
return find_python3_executable()
def is_clobber_needed(self):
if not os.path.exists(self.topobjdir):
return False

View File

@ -5,12 +5,8 @@
from __future__ import absolute_import, print_function, unicode_literals
import os
import six
import subprocess
import sys
from distutils.version import StrictVersion
def iter_modules_in_path(*paths):
paths = [os.path.abspath(os.path.normcase(p)) + os.sep for p in paths]
@ -27,80 +23,3 @@ def iter_modules_in_path(*paths):
if any(path.startswith(p) for p in paths):
yield path
def python_executable_version(exe):
"""Determine the version of a Python executable by invoking it.
May raise ``subprocess.CalledProcessError`` or ``ValueError`` on failure.
"""
program = "import sys; print('.'.join(map(str, sys.version_info[0:3])))"
out = six.ensure_text(
subprocess.check_output([exe, "-c", program], universal_newlines=True)
).rstrip()
return StrictVersion(out)
def _find_python_executable(major):
if major not in (2, 3):
raise ValueError("Expected a Python major version of 2 or 3")
min_versions = {2: "2.7.0", 3: "3.6.0"}
def ret(min_version=min_versions[major]):
from mozfile import which
prefix = min_version[0] + "."
if not min_version.startswith(prefix):
raise ValueError(
"min_version expected a %sx string, got %s" % (prefix, min_version)
)
min_version = StrictVersion(min_version)
major = min_version.version[0]
if sys.version_info.major == major:
our_version = StrictVersion("%s.%s.%s" % (sys.version_info[0:3]))
if our_version >= min_version:
# This will potentially return a virtualenv Python. It's probably
# OK for now...
return sys.executable, our_version.version
# Else fall back to finding another binary.
# https://www.python.org/dev/peps/pep-0394/ defines how the Python binary
# should be named. `python3` should refer to some Python 3, and
# `python2` to some Python 2. `python` may refer to a Python 2 or 3.
# `pythonX.Y` may exist.
#
# Since `python` is ambiguous and `pythonX` should always exist, we
# ignore `python` here. We instead look for the preferred `pythonX` first
# and fall back to `pythonX.Y` if it isn't found or doesn't meet our
# version requirements.
names = ["python%d" % major]
# Look for `pythonX.Y` down to our minimum version.
for minor in range(9, min_version.version[1] - 1, -1):
names.append("python%d.%d" % (major, minor))
for name in names:
exe = which(name)
if not exe:
continue
# We always verify we can invoke the executable and its version is
# sane.
try:
version = python_executable_version(exe)
except (subprocess.CalledProcessError, ValueError):
continue
if version >= min_version:
return exe, version.version
return None, None
return ret
find_python3_executable = _find_python_executable(3)