Skip to content

Commit 6f78d73

Browse files
committed
fix: test_dependency_constraints_file when using build
1 parent a5ea7c4 commit 6f78d73

File tree

4 files changed

+36
-4
lines changed

4 files changed

+36
-4
lines changed

cibuildwheel/macos.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
NonPlatformWheelError,
2020
download,
2121
get_build_verbosity_extra_flags,
22+
get_pip_version,
2223
install_certifi_script,
2324
prepare_command,
2425
read_python_configs,
@@ -319,7 +320,7 @@ def setup_python(
319320
"install",
320321
"--upgrade",
321322
"delocate",
322-
"build",
323+
"build[virtualenv]",
323324
*dependency_constraint_flags,
324325
],
325326
env=env,
@@ -396,6 +397,12 @@ def build(options: BuildOptions) -> None:
396397

397398
if options.pypa_build:
398399
config_setting = " ".join(verbosity_flags)
400+
build_env = dict(env)
401+
if options.dependency_constraints:
402+
build_env["PIP_CONSTRAINT"] = str(
403+
options.dependency_constraints.get_for_python_version(config.version)
404+
)
405+
build_env["VIRTUALENV_PIP"] = get_pip_version(env)
399406
call(
400407
[
401408
"python",
@@ -406,7 +413,7 @@ def build(options: BuildOptions) -> None:
406413
f"--outdir={built_wheel_dir}",
407414
f"--config-setting={config_setting}",
408415
],
409-
env=env,
416+
env=build_env,
410417
)
411418
else:
412419
# Path.resolve() is needed. Without it pip wheel may try to fetch package from pypi.org

cibuildwheel/util.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
import os
55
import re
66
import ssl
7+
import subprocess
8+
import sys
79
import textwrap
810
import time
911
import urllib.request
@@ -275,3 +277,18 @@ def print_new_wheels(msg: str, output_dir: Path) -> Iterator[None]:
275277
s = time.time() - start_time
276278
m = s / 60
277279
print(msg.format(n=n, s=s, m=m), *sorted(f" {f.name}" for f in new_contents), sep="\n")
280+
281+
282+
def get_pip_version(env: Dict[str, str]) -> str:
283+
# we use shell=True here for windows, even though we don't need a shell due to a bug
284+
# https://bugs.python.org/issue8557
285+
shell = sys.platform.startswith("win")
286+
versions_output_text = subprocess.check_output(
287+
["python", "-m", "pip", "freeze", "--all"], universal_newlines=True, shell=shell, env=env
288+
)
289+
(pip_version,) = [
290+
version[5:]
291+
for version in versions_output_text.strip().splitlines()
292+
if version.startswith("pip==")
293+
]
294+
return pip_version

cibuildwheel/windows.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
NonPlatformWheelError,
1818
download,
1919
get_build_verbosity_extra_flags,
20+
get_pip_version,
2021
prepare_command,
2122
read_python_configs,
2223
)
@@ -291,6 +292,12 @@ def build(options: BuildOptions) -> None:
291292

292293
if options.pypa_build:
293294
config_setting = " ".join(verbosity_flags)
295+
build_env = dict(env)
296+
if options.dependency_constraints:
297+
build_env["PIP_CONSTRAINT"] = str(
298+
options.dependency_constraints.get_for_python_version(config.version)
299+
)
300+
build_env["VIRTUALENV_PIP"] = get_pip_version(env)
294301
call(
295302
[
296303
"python",
@@ -301,7 +308,7 @@ def build(options: BuildOptions) -> None:
301308
f"--outdir={built_wheel_dir}",
302309
f"--config-setting={config_setting}",
303310
],
304-
env=env,
311+
env=build_env,
305312
)
306313
else:
307314
# Path.resolve() is needed. Without it pip wheel may try to fetch package from pypi.org

test/test_dependency_versions.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ def test_dependency_constraints_file(tmp_path):
118118
"pip": "20.0.2",
119119
"setuptools": "53.0.0",
120120
"wheel": "0.34.2",
121-
"virtualenv": "20.0.10",
121+
"virtualenv": "20.0.35",
122122
}
123123

124124
constraints_file = tmp_path / "constraints.txt"
@@ -129,6 +129,7 @@ def test_dependency_constraints_file(tmp_path):
129129
setuptools=={setuptools}
130130
wheel=={wheel}
131131
virtualenv=={virtualenv}
132+
importlib-metadata<3,>=0.12; python_version < "3.8"
132133
""".format(
133134
**tool_versions
134135
)

0 commit comments

Comments
 (0)