Skip to content

Commit adec6c3

Browse files
committed
fix: respect constraints when building with pip
1 parent 744d37e commit adec6c3

File tree

3 files changed

+53
-53
lines changed

3 files changed

+53
-53
lines changed

cibuildwheel/macos.py

+13-14
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,18 @@ def build(options: Options, tmp_path: Path) -> None:
381381
)
382382
extra_flags += build_frontend.args
383383

384+
build_env = env.copy()
385+
build_env["VIRTUALENV_PIP"] = get_pip_version(env)
386+
if build_options.dependency_constraints:
387+
constraint_path = build_options.dependency_constraints.get_for_python_version(
388+
config.version
389+
)
390+
user_constraints = build_env.get("PIP_CONSTRAINT")
391+
our_constraints = constraint_path.as_uri()
392+
build_env["PIP_CONSTRAINT"] = " ".join(
393+
c for c in [user_constraints, our_constraints] if c
394+
)
395+
384396
if build_frontend.name == "pip":
385397
extra_flags += get_build_verbosity_extra_flags(build_options.build_verbosity)
386398
# Path.resolve() is needed. Without it pip wheel may try to fetch package from pypi.org
@@ -394,25 +406,12 @@ def build(options: Options, tmp_path: Path) -> None:
394406
f"--wheel-dir={built_wheel_dir}",
395407
"--no-deps",
396408
*extra_flags,
397-
env=env,
409+
env=build_env,
398410
)
399411
elif build_frontend.name == "build":
400412
if not 0 <= build_options.build_verbosity < 2:
401413
msg = f"build_verbosity {build_options.build_verbosity} is not supported for build frontend. Ignoring."
402414
log.warning(msg)
403-
build_env = env.copy()
404-
if build_options.dependency_constraints:
405-
constraint_path = (
406-
build_options.dependency_constraints.get_for_python_version(
407-
config.version
408-
)
409-
)
410-
user_constraints = build_env.get("PIP_CONSTRAINT")
411-
our_constraints = constraint_path.as_uri()
412-
build_env["PIP_CONSTRAINT"] = " ".join(
413-
c for c in [user_constraints, our_constraints] if c
414-
)
415-
build_env["VIRTUALENV_PIP"] = get_pip_version(env)
416415
call(
417416
"python",
418417
"-m",

cibuildwheel/windows.py

+33-35
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,28 @@ def build(options: Options, tmp_path: Path) -> None:
407407
)
408408
extra_flags += build_frontend.args
409409

410+
build_env = env.copy()
411+
build_env["VIRTUALENV_PIP"] = get_pip_version(env)
412+
if build_options.dependency_constraints:
413+
constraints_path = build_options.dependency_constraints.get_for_python_version(
414+
config.version
415+
)
416+
# Bug in pip <= 21.1.3 - we can't have a space in the
417+
# constraints file, and pip doesn't support drive letters
418+
# in uhi. After probably pip 21.2, we can use uri. For
419+
# now, use a temporary file.
420+
if " " in str(constraints_path):
421+
assert " " not in str(identifier_tmp_dir)
422+
tmp_file = identifier_tmp_dir / "constraints.txt"
423+
tmp_file.write_bytes(constraints_path.read_bytes())
424+
constraints_path = tmp_file
425+
426+
our_constraints = str(constraints_path)
427+
user_constraints = build_env.get("PIP_CONSTRAINT")
428+
build_env["PIP_CONSTRAINT"] = " ".join(
429+
c for c in [our_constraints, user_constraints] if c
430+
)
431+
410432
if build_frontend.name == "pip":
411433
extra_flags += get_build_verbosity_extra_flags(build_options.build_verbosity)
412434
# Path.resolve() is needed. Without it pip wheel may try to fetch package from pypi.org
@@ -420,46 +442,22 @@ def build(options: Options, tmp_path: Path) -> None:
420442
f"--wheel-dir={built_wheel_dir}",
421443
"--no-deps",
422444
*extra_flags,
423-
env=env,
445+
env=build_env,
424446
)
425447
elif build_frontend.name == "build":
426448
if not 0 <= build_options.build_verbosity < 2:
427449
msg = f"build_verbosity {build_options.build_verbosity} is not supported for build frontend. Ignoring."
428450
log.warning(msg)
429-
build_env = env.copy()
430-
if build_options.dependency_constraints:
431-
constraints_path = (
432-
build_options.dependency_constraints.get_for_python_version(
433-
config.version
434-
)
435-
)
436-
# Bug in pip <= 21.1.3 - we can't have a space in the
437-
# constraints file, and pip doesn't support drive letters
438-
# in uhi. After probably pip 21.2, we can use uri. For
439-
# now, use a temporary file.
440-
if " " in str(constraints_path):
441-
assert " " not in str(identifier_tmp_dir)
442-
tmp_file = identifier_tmp_dir / "constraints.txt"
443-
tmp_file.write_bytes(constraints_path.read_bytes())
444-
constraints_path = tmp_file
445-
446-
our_constraints = str(constraints_path)
447-
user_constraints = build_env.get("PIP_CONSTRAINT")
448-
build_env["PIP_CONSTRAINT"] = " ".join(
449-
c for c in [our_constraints, user_constraints] if c
450-
)
451-
452-
build_env["VIRTUALENV_PIP"] = get_pip_version(env)
453-
call(
454-
"python",
455-
"-m",
456-
"build",
457-
build_options.package_dir,
458-
"--wheel",
459-
f"--outdir={built_wheel_dir}",
460-
*extra_flags,
461-
env=build_env,
462-
)
451+
call(
452+
"python",
453+
"-m",
454+
"build",
455+
build_options.package_dir,
456+
"--wheel",
457+
f"--outdir={built_wheel_dir}",
458+
*extra_flags,
459+
env=build_env,
460+
)
463461
else:
464462
assert_never(build_frontend)
465463

test/test_dependency_versions.py

+7-4
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,10 @@
1515
r"""
1616
import subprocess
1717
import os
18+
import sys
1819
1920
versions_output_text = subprocess.check_output(
20-
['pip', 'freeze', '--all', '-qq'],
21+
[sys.executable, '-m', 'pip', 'freeze', '--all', '-qq'],
2122
universal_newlines=True,
2223
)
2324
versions = versions_output_text.strip().splitlines()
@@ -36,6 +37,11 @@
3637
)
3738
)
3839

40+
project_with_expected_version_checks.files["pyproject.toml"] = r"""
41+
[build-system]
42+
requires = ["setuptools", "pip"]
43+
build-backend = "setuptools.build_meta"
44+
"""
3945

4046
VERSION_REGEX = r"([\w-]+)==([^\s]+)"
4147

@@ -61,9 +67,6 @@ def test_pinned_versions(tmp_path, python_version, build_frontend_env):
6167
pytest.skip("macOS arm64 does not support Python 3.6")
6268
constraint_filename = "constraints-python36.txt"
6369
build_pattern = "[cp]p36-*"
64-
elif python_version == "3.7":
65-
constraint_filename = "constraints-python37.txt"
66-
build_pattern = "[cp]p37-*"
6770
elif python_version == "3.8":
6871
constraint_filename = "constraints-python38.txt"
6972
build_pattern = "[cp]p38-*"

0 commit comments

Comments
 (0)