fix: respect constraints when building with pip (#1818)
When building a project that has a `pyproject.toml`, constraints are not respected when building with the `pip` frontend. This commit fixes this by using the same tricks as for the `build` frontend.
This commit is contained in:
+13
-14
@@ -381,6 +381,18 @@ def build(options: Options, tmp_path: Path) -> None:
|
|||||||
)
|
)
|
||||||
extra_flags += build_frontend.args
|
extra_flags += build_frontend.args
|
||||||
|
|
||||||
|
build_env = env.copy()
|
||||||
|
build_env["VIRTUALENV_PIP"] = get_pip_version(env)
|
||||||
|
if build_options.dependency_constraints:
|
||||||
|
constraint_path = build_options.dependency_constraints.get_for_python_version(
|
||||||
|
config.version
|
||||||
|
)
|
||||||
|
user_constraints = build_env.get("PIP_CONSTRAINT")
|
||||||
|
our_constraints = constraint_path.as_uri()
|
||||||
|
build_env["PIP_CONSTRAINT"] = " ".join(
|
||||||
|
c for c in [user_constraints, our_constraints] if c
|
||||||
|
)
|
||||||
|
|
||||||
if build_frontend.name == "pip":
|
if build_frontend.name == "pip":
|
||||||
extra_flags += get_build_verbosity_extra_flags(build_options.build_verbosity)
|
extra_flags += get_build_verbosity_extra_flags(build_options.build_verbosity)
|
||||||
# Path.resolve() is needed. Without it pip wheel may try to fetch package from pypi.org
|
# 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:
|
|||||||
f"--wheel-dir={built_wheel_dir}",
|
f"--wheel-dir={built_wheel_dir}",
|
||||||
"--no-deps",
|
"--no-deps",
|
||||||
*extra_flags,
|
*extra_flags,
|
||||||
env=env,
|
env=build_env,
|
||||||
)
|
)
|
||||||
elif build_frontend.name == "build":
|
elif build_frontend.name == "build":
|
||||||
if not 0 <= build_options.build_verbosity < 2:
|
if not 0 <= build_options.build_verbosity < 2:
|
||||||
msg = f"build_verbosity {build_options.build_verbosity} is not supported for build frontend. Ignoring."
|
msg = f"build_verbosity {build_options.build_verbosity} is not supported for build frontend. Ignoring."
|
||||||
log.warning(msg)
|
log.warning(msg)
|
||||||
build_env = env.copy()
|
|
||||||
if build_options.dependency_constraints:
|
|
||||||
constraint_path = (
|
|
||||||
build_options.dependency_constraints.get_for_python_version(
|
|
||||||
config.version
|
|
||||||
)
|
|
||||||
)
|
|
||||||
user_constraints = build_env.get("PIP_CONSTRAINT")
|
|
||||||
our_constraints = constraint_path.as_uri()
|
|
||||||
build_env["PIP_CONSTRAINT"] = " ".join(
|
|
||||||
c for c in [user_constraints, our_constraints] if c
|
|
||||||
)
|
|
||||||
build_env["VIRTUALENV_PIP"] = get_pip_version(env)
|
|
||||||
call(
|
call(
|
||||||
"python",
|
"python",
|
||||||
"-m",
|
"-m",
|
||||||
|
|||||||
+21
-23
@@ -407,32 +407,12 @@ def build(options: Options, tmp_path: Path) -> None:
|
|||||||
)
|
)
|
||||||
extra_flags += build_frontend.args
|
extra_flags += build_frontend.args
|
||||||
|
|
||||||
if build_frontend.name == "pip":
|
|
||||||
extra_flags += get_build_verbosity_extra_flags(build_options.build_verbosity)
|
|
||||||
# Path.resolve() is needed. Without it pip wheel may try to fetch package from pypi.org
|
|
||||||
# see https://github.com/pypa/cibuildwheel/pull/369
|
|
||||||
call(
|
|
||||||
"python",
|
|
||||||
"-m",
|
|
||||||
"pip",
|
|
||||||
"wheel",
|
|
||||||
options.globals.package_dir.resolve(),
|
|
||||||
f"--wheel-dir={built_wheel_dir}",
|
|
||||||
"--no-deps",
|
|
||||||
*extra_flags,
|
|
||||||
env=env,
|
|
||||||
)
|
|
||||||
elif build_frontend.name == "build":
|
|
||||||
if not 0 <= build_options.build_verbosity < 2:
|
|
||||||
msg = f"build_verbosity {build_options.build_verbosity} is not supported for build frontend. Ignoring."
|
|
||||||
log.warning(msg)
|
|
||||||
build_env = env.copy()
|
build_env = env.copy()
|
||||||
|
build_env["VIRTUALENV_PIP"] = get_pip_version(env)
|
||||||
if build_options.dependency_constraints:
|
if build_options.dependency_constraints:
|
||||||
constraints_path = (
|
constraints_path = build_options.dependency_constraints.get_for_python_version(
|
||||||
build_options.dependency_constraints.get_for_python_version(
|
|
||||||
config.version
|
config.version
|
||||||
)
|
)
|
||||||
)
|
|
||||||
# Bug in pip <= 21.1.3 - we can't have a space in the
|
# Bug in pip <= 21.1.3 - we can't have a space in the
|
||||||
# constraints file, and pip doesn't support drive letters
|
# constraints file, and pip doesn't support drive letters
|
||||||
# in uhi. After probably pip 21.2, we can use uri. For
|
# in uhi. After probably pip 21.2, we can use uri. For
|
||||||
@@ -449,7 +429,25 @@ def build(options: Options, tmp_path: Path) -> None:
|
|||||||
c for c in [our_constraints, user_constraints] if c
|
c for c in [our_constraints, user_constraints] if c
|
||||||
)
|
)
|
||||||
|
|
||||||
build_env["VIRTUALENV_PIP"] = get_pip_version(env)
|
if build_frontend.name == "pip":
|
||||||
|
extra_flags += get_build_verbosity_extra_flags(build_options.build_verbosity)
|
||||||
|
# Path.resolve() is needed. Without it pip wheel may try to fetch package from pypi.org
|
||||||
|
# see https://github.com/pypa/cibuildwheel/pull/369
|
||||||
|
call(
|
||||||
|
"python",
|
||||||
|
"-m",
|
||||||
|
"pip",
|
||||||
|
"wheel",
|
||||||
|
options.globals.package_dir.resolve(),
|
||||||
|
f"--wheel-dir={built_wheel_dir}",
|
||||||
|
"--no-deps",
|
||||||
|
*extra_flags,
|
||||||
|
env=build_env,
|
||||||
|
)
|
||||||
|
elif build_frontend.name == "build":
|
||||||
|
if not 0 <= build_options.build_verbosity < 2:
|
||||||
|
msg = f"build_verbosity {build_options.build_verbosity} is not supported for build frontend. Ignoring."
|
||||||
|
log.warning(msg)
|
||||||
call(
|
call(
|
||||||
"python",
|
"python",
|
||||||
"-m",
|
"-m",
|
||||||
|
|||||||
@@ -15,9 +15,10 @@ project_with_expected_version_checks = test_projects.new_c_project(
|
|||||||
r"""
|
r"""
|
||||||
import subprocess
|
import subprocess
|
||||||
import os
|
import os
|
||||||
|
import sys
|
||||||
|
|
||||||
versions_output_text = subprocess.check_output(
|
versions_output_text = subprocess.check_output(
|
||||||
['pip', 'freeze', '--all', '-qq'],
|
[sys.executable, '-m', 'pip', 'freeze', '--all', '-qq'],
|
||||||
universal_newlines=True,
|
universal_newlines=True,
|
||||||
)
|
)
|
||||||
versions = versions_output_text.strip().splitlines()
|
versions = versions_output_text.strip().splitlines()
|
||||||
@@ -36,6 +37,11 @@ project_with_expected_version_checks = test_projects.new_c_project(
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
project_with_expected_version_checks.files["pyproject.toml"] = r"""
|
||||||
|
[build-system]
|
||||||
|
requires = ["setuptools", "pip"]
|
||||||
|
build-backend = "setuptools.build_meta"
|
||||||
|
"""
|
||||||
|
|
||||||
VERSION_REGEX = r"([\w-]+)==([^\s]+)"
|
VERSION_REGEX = r"([\w-]+)==([^\s]+)"
|
||||||
|
|
||||||
@@ -50,27 +56,16 @@ def get_versions_from_constraint_file(constraint_file):
|
|||||||
def test_pinned_versions(tmp_path, python_version, build_frontend_env):
|
def test_pinned_versions(tmp_path, python_version, build_frontend_env):
|
||||||
if utils.platform == "linux":
|
if utils.platform == "linux":
|
||||||
pytest.skip("linux doesn't pin individual tool versions, it pins manylinux images instead")
|
pytest.skip("linux doesn't pin individual tool versions, it pins manylinux images instead")
|
||||||
|
if python_version == "3.6" and utils.platform == "macos" and platform.machine() == "arm64":
|
||||||
|
pytest.skip("macOS arm64 does not support Python 3.6")
|
||||||
|
|
||||||
project_dir = tmp_path / "project"
|
project_dir = tmp_path / "project"
|
||||||
project_with_expected_version_checks.generate(project_dir)
|
project_with_expected_version_checks.generate(project_dir)
|
||||||
|
|
||||||
|
version_no_dot = python_version.replace(".", "")
|
||||||
build_environment = {}
|
build_environment = {}
|
||||||
|
build_pattern = f"[cp]p{version_no_dot}-*"
|
||||||
if python_version == "3.6":
|
constraint_filename = f"constraints-python{version_no_dot}.txt"
|
||||||
if utils.platform == "macos" and platform.machine() == "arm64":
|
|
||||||
pytest.skip("macOS arm64 does not support Python 3.6")
|
|
||||||
constraint_filename = "constraints-python36.txt"
|
|
||||||
build_pattern = "[cp]p36-*"
|
|
||||||
elif python_version == "3.7":
|
|
||||||
constraint_filename = "constraints-python37.txt"
|
|
||||||
build_pattern = "[cp]p37-*"
|
|
||||||
elif python_version == "3.8":
|
|
||||||
constraint_filename = "constraints-python38.txt"
|
|
||||||
build_pattern = "[cp]p38-*"
|
|
||||||
else:
|
|
||||||
constraint_filename = "constraints-python310.txt"
|
|
||||||
build_pattern = "[cp]p310-*"
|
|
||||||
|
|
||||||
constraint_file = cibuildwheel.util.resources_dir / constraint_filename
|
constraint_file = cibuildwheel.util.resources_dir / constraint_filename
|
||||||
constraint_versions = get_versions_from_constraint_file(constraint_file)
|
constraint_versions = get_versions_from_constraint_file(constraint_file)
|
||||||
|
|
||||||
@@ -89,21 +84,11 @@ def test_pinned_versions(tmp_path, python_version, build_frontend_env):
|
|||||||
)
|
)
|
||||||
|
|
||||||
# also check that we got the right wheels
|
# also check that we got the right wheels
|
||||||
if python_version == "3.6":
|
|
||||||
expected_wheels = [
|
expected_wheels = [
|
||||||
w for w in utils.expected_wheels("spam", "0.1.0") if "-cp36" in w or "-pp36" in w
|
w
|
||||||
|
for w in utils.expected_wheels("spam", "0.1.0")
|
||||||
|
if f"-cp{version_no_dot}" in w or f"-pp{version_no_dot}" in w
|
||||||
]
|
]
|
||||||
elif python_version == "3.8":
|
|
||||||
expected_wheels = [
|
|
||||||
w for w in utils.expected_wheels("spam", "0.1.0") if "-cp38" in w or "-pp38" in w
|
|
||||||
]
|
|
||||||
elif python_version == "3.10":
|
|
||||||
expected_wheels = [
|
|
||||||
w for w in utils.expected_wheels("spam", "0.1.0") if "-cp310" in w or "-pp310" in w
|
|
||||||
]
|
|
||||||
else:
|
|
||||||
msg = "unhandled python version"
|
|
||||||
raise ValueError(msg)
|
|
||||||
|
|
||||||
assert set(actual_wheels) == set(expected_wheels)
|
assert set(actual_wheels) == set(expected_wheels)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user