Skip to content

Commit f7de18e

Browse files
authored
Merge pull request #1675 from pypa/pip-constraints-fix
fix: Don't override PIP_CONSTRAINT if set by the user
2 parents 80095ac + 6940c77 commit f7de18e

File tree

4 files changed

+61
-3
lines changed

4 files changed

+61
-3
lines changed

cibuildwheel/macos.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,11 @@ def build(options: Options, tmp_path: Path) -> None:
407407
config.version
408408
)
409409
)
410-
build_env["PIP_CONSTRAINT"] = constraint_path.as_uri()
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+
)
411415
build_env["VIRTUALENV_PIP"] = get_pip_version(env)
412416
call(
413417
"python",

cibuildwheel/windows.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,12 @@ def build(options: Options, tmp_path: Path) -> None:
443443
tmp_file.write_bytes(constraints_path.read_bytes())
444444
constraints_path = tmp_file
445445

446-
build_env["PIP_CONSTRAINT"] = str(constraints_path)
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+
447452
build_env["VIRTUALENV_PIP"] = get_pip_version(env)
448453
call(
449454
"python",

docs/options.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -743,7 +743,7 @@ Platform-specific environment variables are also available:<br/>
743743
cibuildwheel always defines the environment variable `CIBUILDWHEEL=1`. This can be useful for [building wheels with optional extensions](faq.md#building-packages-with-optional-c-extensions).
744744

745745
!!! note
746-
To do its work, cibuildwheel internally sets the options `PIP_CONSTRAINT`, `VIRTUALENV_PIP`, `DIST_EXTRA_CONFIG`, `SETUPTOOLS_EXT_SUFFIX`, `PIP_DISABLE_PIP_VERSION_CHECK`, `PIP_ROOT_USER_ACTION`. Your assignments to these options might be overridden.
746+
To do its work, cibuildwheel sets the variables `VIRTUALENV_PIP`, `DIST_EXTRA_CONFIG`, `SETUPTOOLS_EXT_SUFFIX`, `PIP_DISABLE_PIP_VERSION_CHECK`, `PIP_ROOT_USER_ACTION`, and it extends the variables `PATH` and `PIP_CONSTRAINT`. Your assignments to these options might be replaced or extended.
747747

748748
### `CIBW_ENVIRONMENT_PASS_LINUX` {: #environment-pass}
749749
> Set environment variables on the host to pass-through to the container.

test/test_environment.py

+49
Original file line numberDiff line numberDiff line change
@@ -93,3 +93,52 @@ def test_overridden_path(tmp_path, capfd):
9393
assert len(os.listdir(output_dir)) == 0
9494
captured = capfd.readouterr()
9595
assert "python available on PATH doesn't match our installed instance" in captured.err
96+
97+
98+
@pytest.mark.parametrize("build_frontend", ["pip", "build"])
99+
def test_overridden_pip_constraint(tmp_path, build_frontend):
100+
"""
101+
Verify that users can use PIP_CONSTRAINT to specify a specific version of
102+
a build-system.requires dependency, by asserting the version of pytz in the
103+
setup.py.
104+
"""
105+
project_dir = tmp_path / "project"
106+
107+
project = test_projects.new_c_project(
108+
setup_py_add=textwrap.dedent(
109+
"""
110+
import pytz
111+
assert pytz.__version__ == "2022.4"
112+
"""
113+
)
114+
)
115+
project.files["pyproject.toml"] = textwrap.dedent(
116+
"""
117+
[build-system]
118+
requires = ["setuptools", "pytz"]
119+
build-backend = "setuptools.build_meta"
120+
"""
121+
)
122+
project.generate(project_dir)
123+
124+
if utils.platform == "linux":
125+
# put the constraints file in the project directory, so it's available
126+
# in the docker container
127+
constraints_file = project_dir / "constraints.txt"
128+
else:
129+
constraints_file = tmp_path / "constraints.txt"
130+
131+
constraints_file.write_text("pytz==2022.4")
132+
133+
actual_wheels = utils.cibuildwheel_run(
134+
project_dir,
135+
add_env={
136+
"CIBW_BUILD": "cp312-*",
137+
"CIBW_BUILD_FRONTEND": build_frontend,
138+
"PIP_CONSTRAINT": str(constraints_file),
139+
"CIBW_ENVIRONMENT_LINUX": "PIP_CONSTRAINT=./constraints.txt",
140+
},
141+
)
142+
143+
expected_wheels = [w for w in utils.expected_wheels("spam", "0.1.0") if "cp312" in w]
144+
assert set(actual_wheels) == set(expected_wheels)

0 commit comments

Comments
 (0)