From 53b8f8149c4b90f2a79f0dabd2bbfc0f65127c45 Mon Sep 17 00:00:00 2001 From: Henry Schreiner Date: Mon, 13 Dec 2021 09:39:41 -0500 Subject: [PATCH] fix: environment variable affect initial setup macOS/win (#956) --- cibuildwheel/macos.py | 31 ++++++++++++++----------- cibuildwheel/windows.py | 51 +++++++++++++++++++++-------------------- 2 files changed, 43 insertions(+), 39 deletions(-) diff --git a/cibuildwheel/macos.py b/cibuildwheel/macos.py index f2e377de0..f146348f7 100644 --- a/cibuildwheel/macos.py +++ b/cibuildwheel/macos.py @@ -192,24 +192,10 @@ def setup_python( # https://github.com/pypa/virtualenv/issues/620 # Also see https://github.com/python/cpython/pull/9516 env.pop("__PYVENV_LAUNCHER__", None) - env = environment.as_dictionary(prev_environment=env) # we version pip ourselves, so we don't care about pip version checking env["PIP_DISABLE_PIP_VERSION_CHECK"] = "1" - # check what version we're on - call(["which", "python"], env=env) - call(["python", "--version"], env=env) - which_python = subprocess.run( - ["which", "python"], env=env, universal_newlines=True, check=True, stdout=subprocess.PIPE - ).stdout.strip() - if which_python != "/tmp/cibw_bin/python": - print( - "cibuildwheel: python available on PATH doesn't match our installed instance. If you have modified PATH, ensure that you don't overwrite cibuildwheel's entry or insert python above it.", - file=sys.stderr, - ) - sys.exit(1) - # Install pip requires_reinstall = not (installation_bin_path / "pip").exists() @@ -233,6 +219,10 @@ def setup_python( cwd="/tmp", ) + # Apply our environment after pip is ready + env = environment.as_dictionary(prev_environment=env) + + # check what pip version we're on assert (installation_bin_path / "pip").exists() call(["which", "pip"], env=env) call(["pip", "--version"], env=env) @@ -246,6 +236,19 @@ def setup_python( ) sys.exit(1) + # check what Python version we're on + call(["which", "python"], env=env) + call(["python", "--version"], env=env) + which_python = subprocess.run( + ["which", "python"], env=env, universal_newlines=True, check=True, stdout=subprocess.PIPE + ).stdout.strip() + if which_python != "/tmp/cibw_bin/python": + print( + "cibuildwheel: python available on PATH doesn't match our installed instance. If you have modified PATH, ensure that you don't overwrite cibuildwheel's entry or insert python above it.", + file=sys.stderr, + ) + sys.exit(1) + # Set MACOSX_DEPLOYMENT_TARGET to 10.9, if the user didn't set it. # PyPy defaults to 10.7, causing inconsistencies if it's left unset. env.setdefault("MACOSX_DEPLOYMENT_TARGET", "10.9") diff --git a/cibuildwheel/windows.py b/cibuildwheel/windows.py index c67497907..0e1e9bd18 100644 --- a/cibuildwheel/windows.py +++ b/cibuildwheel/windows.py @@ -157,31 +157,6 @@ def setup_python( ) env["PIP_DISABLE_PIP_VERSION_CHECK"] = "1" - # update env with results from CIBW_ENVIRONMENT - env = environment.as_dictionary(prev_environment=env) - - # for the logs - check we're running the right version of python - call(["where", "python"], env=env) - call(["python", "--version"], env=env) - call(["python", "-c", "\"import struct; print(struct.calcsize('P') * 8)\""], env=env) - where_python = ( - subprocess.run( - ["where", "python"], - env=env, - universal_newlines=True, - check=True, - stdout=subprocess.PIPE, - ) - .stdout.splitlines()[0] - .strip() - ) - if where_python != str(installation_path / "python.exe"): - print( - "cibuildwheel: python available on PATH doesn't match our installed instance. If you have modified PATH, ensure that you don't overwrite cibuildwheel's entry or insert python above it.", - file=sys.stderr, - ) - sys.exit(1) - log.step("Installing build tools...") # Install pip @@ -230,6 +205,32 @@ def setup_python( cwd=CIBW_INSTALL_PATH, ) + # update env with results from CIBW_ENVIRONMENT + env = environment.as_dictionary(prev_environment=env) + + # check what Python version we're on + call(["where", "python"], env=env) + call(["python", "--version"], env=env) + call(["python", "-c", "\"import struct; print(struct.calcsize('P') * 8)\""], env=env) + where_python = ( + subprocess.run( + ["where", "python"], + env=env, + universal_newlines=True, + check=True, + stdout=subprocess.PIPE, + ) + .stdout.splitlines()[0] + .strip() + ) + if where_python != str(installation_path / "python.exe"): + print( + "cibuildwheel: python available on PATH doesn't match our installed instance. If you have modified PATH, ensure that you don't overwrite cibuildwheel's entry or insert python above it.", + file=sys.stderr, + ) + sys.exit(1) + + # check what pip version we're on assert (installation_path / "Scripts" / "pip.exe").exists() where_pip = ( subprocess.run(