Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Don't override PIP_CONSTRAINT if set by the user #1675

Merged
merged 6 commits into from
Mar 9, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion cibuildwheel/macos.py
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,9 @@ def build(options: Options, tmp_path: Path) -> None:
config.version
)
)
build_env["PIP_CONSTRAINT"] = constraint_path.as_uri()
build_env["PIP_CONSTRAINT"] = (
constraint_path.as_uri() + " " + build_env.get("PIP_CONSTRAINT", "")
)
joerick marked this conversation as resolved.
Show resolved Hide resolved
joerick marked this conversation as resolved.
Show resolved Hide resolved
build_env["VIRTUALENV_PIP"] = get_pip_version(env)
call(
"python",
Expand Down
4 changes: 3 additions & 1 deletion cibuildwheel/windows.py
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,9 @@ def build(options: Options, tmp_path: Path) -> None:
tmp_file.write_bytes(constraints_path.read_bytes())
constraints_path = tmp_file

build_env["PIP_CONSTRAINT"] = str(constraints_path)
build_env["PIP_CONSTRAINT"] = (
str(constraints_path) + " " + build_env.get("PIP_CONSTRAINT", "")
)
joerick marked this conversation as resolved.
Show resolved Hide resolved
build_env["VIRTUALENV_PIP"] = get_pip_version(env)
call(
"python",
Expand Down
2 changes: 1 addition & 1 deletion docs/options.md
Original file line number Diff line number Diff line change
Expand Up @@ -674,7 +674,7 @@ Platform-specific environment variables are also available:<br/>
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).

!!! note
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.
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.

### `CIBW_ENVIRONMENT_PASS_LINUX` {: #environment-pass}
> Set environment variables on the host to pass-through to the container.
Expand Down
49 changes: 49 additions & 0 deletions test/test_environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,3 +93,52 @@ def test_overridden_path(tmp_path, capfd):
assert len(os.listdir(output_dir)) == 0
captured = capfd.readouterr()
assert "python available on PATH doesn't match our installed instance" in captured.err


@pytest.mark.parametrize("build_frontend", ["pip", "build"])
def test_overridden_pip_constraint(tmp_path, build_frontend):
"""
Verify that users can use PIP_CONSTRAINT to specify a specific version of
a build-system.requires dependency, by asserting the version of pytz in the
setup.py.
"""
project_dir = tmp_path / "project"

project = test_projects.new_c_project(
setup_py_add=textwrap.dedent(
"""
import pytz
assert pytz.__version__ == "2022.4"
"""
)
)
project.files["pyproject.toml"] = textwrap.dedent(
"""
[build-system]
requires = ["setuptools", "pytz"]
build-backend = "setuptools.build_meta"
"""
)
project.generate(project_dir)

if utils.platform == "linux":
# put the constraints file in the project directory, so it's available
# in the docker container
constraints_file = project_dir / "constraints.txt"
else:
constraints_file = tmp_path / "constraints.txt"

constraints_file.write_text("pytz==2022.4")

actual_wheels = utils.cibuildwheel_run(
project_dir,
add_env={
"CIBW_BUILD": "cp312-*",
"CIBW_BUILD_FRONTEND": build_frontend,
"PIP_CONSTRAINT": str(constraints_file),
"CIBW_ENVIRONMENT_LINUX": "PIP_CONSTRAINT=./constraints.txt",
},
)

expected_wheels = [w for w in utils.expected_wheels("spam", "0.1.0") if "cp312" in w]
assert set(actual_wheels) == set(expected_wheels)