From d450af15a4b2ede935baa6bc4b1937427c0393bd Mon Sep 17 00:00:00 2001 From: Henry Schreiner Date: Thu, 9 Dec 2021 11:25:52 -0500 Subject: [PATCH 1/2] fix: environment variable affect initial setup macOS/win --- cibuildwheel/macos.py | 4 +++- cibuildwheel/windows.py | 6 +++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/cibuildwheel/macos.py b/cibuildwheel/macos.py index f2e377de0..5a8a8f028 100644 --- a/cibuildwheel/macos.py +++ b/cibuildwheel/macos.py @@ -192,7 +192,6 @@ 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" @@ -246,6 +245,9 @@ def setup_python( ) sys.exit(1) + # Apply our environment after pip is ready + env = environment.as_dictionary(prev_environment=env) + # 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 77c41cd62..ba99dd20a 100644 --- a/cibuildwheel/windows.py +++ b/cibuildwheel/windows.py @@ -157,9 +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) @@ -247,6 +244,9 @@ def setup_python( call(["pip", "--version"], env=env) + # update env with results from CIBW_ENVIRONMENT + env = environment.as_dictionary(prev_environment=env) + if build_frontend == "pip": call( [ From 95fa1c0fdb4195049ee9a16bea182fc0dfc68e46 Mon Sep 17 00:00:00 2001 From: Henry Schreiner Date: Fri, 10 Dec 2021 22:30:39 -0500 Subject: [PATCH 2/2] fix: move Python check too --- cibuildwheel/macos.py | 31 +++++++++++++------------ cibuildwheel/windows.py | 51 +++++++++++++++++++++-------------------- 2 files changed, 42 insertions(+), 40 deletions(-) diff --git a/cibuildwheel/macos.py b/cibuildwheel/macos.py index 5a8a8f028..f146348f7 100644 --- a/cibuildwheel/macos.py +++ b/cibuildwheel/macos.py @@ -196,19 +196,6 @@ def setup_python( # 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() @@ -232,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) @@ -245,8 +236,18 @@ def setup_python( ) sys.exit(1) - # Apply our environment after pip is ready - env = environment.as_dictionary(prev_environment=env) + # 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. diff --git a/cibuildwheel/windows.py b/cibuildwheel/windows.py index ba99dd20a..d401a3a8c 100644 --- a/cibuildwheel/windows.py +++ b/cibuildwheel/windows.py @@ -157,28 +157,6 @@ def setup_python( ) env["PIP_DISABLE_PIP_VERSION_CHECK"] = "1" - # 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 @@ -227,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( @@ -244,9 +248,6 @@ def setup_python( call(["pip", "--version"], env=env) - # update env with results from CIBW_ENVIRONMENT - env = environment.as_dictionary(prev_environment=env) - if build_frontend == "pip": call( [