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

refactor: pull out dependency_constraint #2347

Merged
merged 3 commits into from
Apr 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ pr:
jobs:
- job: linux_311
timeoutInMinutes: 120
pool: {vmImage: 'Ubuntu-20.04'}
pool: {vmImage: 'Ubuntu-22.04'}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

20.04 is in brownout.

steps:
- task: UsePythonVersion@0
inputs:
Expand All @@ -27,7 +27,7 @@ jobs:
- bash: |
python -m pip install dependency-groups
python -m dependency_groups test | xargs python -m pip install -e.
python ./bin/run_tests.py --num-processes 2
python ./bin/run_tests.py
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This speeds up the macOS tests quite a bit. The docs say they have 3 cores, but 4 are reported. Either way, it's faster not to limit it. Also in #1538.


- job: windows_311
pool: {vmImage: 'windows-2019'}
Expand Down
6 changes: 5 additions & 1 deletion bin/run_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@
from pathlib import Path

if __name__ == "__main__":
default_cpu_count = os.cpu_count() or 2
if sys.version_info < (3, 13):
default_cpu_count = os.cpu_count() or 2
else:
default_cpu_count = os.process_cpu_count() or 2

parser = argparse.ArgumentParser()
parser.add_argument(
"--run-podman", action="store_true", default=False, help="run podman tests (linux only)"
Expand Down
24 changes: 10 additions & 14 deletions cibuildwheel/platforms/ios.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
from ..logger import log
from ..options import Options
from ..selector import BuildSelector
from ..typing import PathOrStr
from ..util import resources
from ..util.cmd import call, shell
from ..util.file import (
Expand All @@ -39,7 +38,7 @@
find_compatible_wheel,
get_pip_version,
)
from ..venv import virtualenv
from ..venv import constraint_flags, virtualenv
from .macos import install_cpython as install_build_cpython


Expand Down Expand Up @@ -151,7 +150,7 @@ def cross_virtualenv(
multiarch: str,
build_python: Path,
venv_path: Path,
dependency_constraint_flags: Sequence[PathOrStr],
dependency_constraint: Path | None,
xbuild_tools: Sequence[str] | None,
) -> dict[str, str]:
"""Create a cross-compilation virtual environment.
Expand All @@ -178,8 +177,8 @@ def cross_virtualenv(
:param build_python: The path to the python binary for the build platform
:param venv_path: The path where the cross virtual environment should be
created.
:param dependency_constraint_flags: Any flags that should be used when
constraining dependencies in the environment.
:param dependency_constraint: A path to a constraint file that should be
used when constraining dependencies in the environment.
:param xbuild_tools: A list of executable names (without paths) that are
on the path, but must be preserved in the cross environment.
"""
Expand All @@ -188,7 +187,7 @@ def cross_virtualenv(
py_version,
build_python,
venv_path,
dependency_constraint_flags,
dependency_constraint,
use_uv=False,
)

Expand Down Expand Up @@ -279,7 +278,7 @@ def setup_python(
tmp: Path,
*,
python_configuration: PythonConfiguration,
dependency_constraint_flags: Sequence[PathOrStr],
dependency_constraint: Path | None,
environment: ParsedEnvironment,
build_frontend: BuildFrontendName,
xbuild_tools: Sequence[str] | None,
Expand Down Expand Up @@ -334,7 +333,7 @@ def setup_python(
multiarch=python_configuration.multiarch,
build_python=build_python,
venv_path=venv_path,
dependency_constraint_flags=dependency_constraint_flags,
dependency_constraint=dependency_constraint,
xbuild_tools=xbuild_tools,
)
venv_bin_path = venv_path / "bin"
Expand All @@ -351,7 +350,7 @@ def setup_python(
"install",
"--upgrade",
"pip",
*dependency_constraint_flags,
*constraint_flags(dependency_constraint),
env=env,
cwd=venv_path,
)
Expand Down Expand Up @@ -397,7 +396,7 @@ def setup_python(
"install",
"--upgrade",
"build[virtualenv]",
*dependency_constraint_flags,
*constraint_flags(dependency_constraint),
env=env,
)
else:
Expand Down Expand Up @@ -453,14 +452,11 @@ def build(options: Options, tmp_path: Path) -> None:
constraints_path = build_options.dependency_constraints.get_for_python_version(
version=config.version, tmp_dir=identifier_tmp_dir
)
dependency_constraint_flags: Sequence[PathOrStr] = (
["-c", constraints_path] if constraints_path else []
)

target_install_path, env = setup_python(
identifier_tmp_dir / "build",
python_configuration=config,
dependency_constraint_flags=dependency_constraint_flags,
dependency_constraint=constraints_path,
environment=build_options.environment,
build_frontend=build_frontend.name,
xbuild_tools=build_options.xbuild_tools,
Expand Down
30 changes: 16 additions & 14 deletions cibuildwheel/platforms/macos.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import subprocess
import sys
import typing
from collections.abc import Sequence, Set
from collections.abc import Set
from dataclasses import dataclass
from pathlib import Path
from typing import Literal, assert_never
Expand All @@ -23,7 +23,6 @@
from ..logger import log
from ..options import Options
from ..selector import BuildSelector
from ..typing import PathOrStr
from ..util import resources
from ..util.cmd import call, shell
from ..util.file import (
Expand All @@ -34,7 +33,7 @@
)
from ..util.helpers import prepare_command, unwrap
from ..util.packaging import combine_constraints, find_compatible_wheel, get_pip_version
from ..venv import find_uv, virtualenv
from ..venv import constraint_flags, find_uv, virtualenv


@functools.cache
Expand Down Expand Up @@ -195,7 +194,7 @@ def install_pypy(tmp: Path, url: str) -> Path:
def setup_python(
tmp: Path,
python_configuration: PythonConfiguration,
dependency_constraint_flags: Sequence[PathOrStr],
dependency_constraint: Path | None,
environment: ParsedEnvironment,
build_frontend: BuildFrontendName,
) -> tuple[Path, dict[str, str]]:
Expand Down Expand Up @@ -226,7 +225,7 @@ def setup_python(
python_configuration.version,
base_python,
venv_path,
dependency_constraint_flags,
dependency_constraint,
use_uv=use_uv,
)
venv_bin_path = venv_path / "bin"
Expand Down Expand Up @@ -256,7 +255,7 @@ def setup_python(
"install",
"--upgrade",
"pip",
*dependency_constraint_flags,
*constraint_flags(dependency_constraint),
env=env,
cwd=venv_path,
)
Expand Down Expand Up @@ -351,7 +350,7 @@ def setup_python(
"install",
"--upgrade",
"delocate",
*dependency_constraint_flags,
*constraint_flags(dependency_constraint),
env=env,
)
elif build_frontend == "build":
Expand All @@ -361,7 +360,7 @@ def setup_python(
"--upgrade",
"delocate",
"build[virtualenv]",
*dependency_constraint_flags,
*constraint_flags(dependency_constraint),
env=env,
)
elif build_frontend == "build[uv]":
Expand All @@ -373,7 +372,7 @@ def setup_python(
"--upgrade",
"delocate",
"build[virtualenv, uv]",
*dependency_constraint_flags,
*constraint_flags(dependency_constraint),
env=env,
)
else:
Expand Down Expand Up @@ -427,14 +426,11 @@ def build(options: Options, tmp_path: Path) -> None:
constraints_path = build_options.dependency_constraints.get_for_python_version(
version=config.version, tmp_dir=identifier_tmp_dir
)
dependency_constraint_flags: Sequence[PathOrStr] = (
["-c", constraints_path] if constraints_path else []
)

base_python, env = setup_python(
identifier_tmp_dir / "build",
config,
dependency_constraint_flags,
constraints_path,
build_options.environment,
build_frontend.name,
)
Expand Down Expand Up @@ -621,7 +617,13 @@ def build(options: Options, tmp_path: Path) -> None:
# set up a virtual environment to install and test from, to make sure
# there are no dependencies that were pulled in at build time.
if not use_uv:
call("pip", "install", "virtualenv", *dependency_constraint_flags, env=env)
call(
"pip",
"install",
"virtualenv",
*constraint_flags(constraints_path),
env=env,
)

venv_dir = identifier_tmp_dir / f"venv-test-{testing_arch}"

Expand Down
18 changes: 7 additions & 11 deletions cibuildwheel/platforms/pyodide.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import shutil
import sys
import tomllib
from collections.abc import Sequence, Set
from collections.abc import Set
from dataclasses import dataclass
from pathlib import Path
from tempfile import TemporaryDirectory
Expand All @@ -18,7 +18,6 @@
from ..logger import log
from ..options import Options
from ..selector import BuildSelector
from ..typing import PathOrStr
from ..util import resources
from ..util.cmd import call, shell
from ..util.file import (
Expand All @@ -31,7 +30,7 @@
)
from ..util.helpers import prepare_command
from ..util.packaging import combine_constraints, find_compatible_wheel, get_pip_version
from ..venv import virtualenv
from ..venv import constraint_flags, virtualenv

IS_WIN: Final[bool] = sys.platform.startswith("win")

Expand Down Expand Up @@ -145,14 +144,14 @@ def get_base_python(identifier: str) -> Path:
def setup_python(
tmp: Path,
python_configuration: PythonConfiguration,
dependency_constraint_flags: Sequence[PathOrStr],
constraints_path: Path | None,
environment: ParsedEnvironment,
) -> dict[str, str]:
base_python = get_base_python(python_configuration.identifier)

log.step("Setting up build environment...")
venv_path = tmp / "venv"
env = virtualenv(python_configuration.version, base_python, venv_path, [], use_uv=False)
env = virtualenv(python_configuration.version, base_python, venv_path, None, use_uv=False)
venv_bin_path = venv_path / "bin"
assert venv_bin_path.exists()
env["PIP_DISABLE_PIP_VERSION_CHECK"] = "1"
Expand All @@ -166,7 +165,7 @@ def setup_python(
"install",
"--upgrade",
"pip",
*dependency_constraint_flags,
*constraint_flags(constraints_path),
env=env,
cwd=venv_path,
)
Expand Down Expand Up @@ -198,7 +197,7 @@ def setup_python(
"auditwheel-emscripten",
"build[virtualenv]",
"pyodide-build",
*dependency_constraint_flags,
*constraint_flags(constraints_path),
env=env,
)

Expand Down Expand Up @@ -269,14 +268,11 @@ def build(options: Options, tmp_path: Path) -> None:
constraints_path = build_options.dependency_constraints.get_for_python_version(
version=config.version, variant="pyodide", tmp_dir=identifier_tmp_dir
)
dependency_constraint_flags: Sequence[PathOrStr] = (
["-c", constraints_path] if constraints_path else []
)

env = setup_python(
identifier_tmp_dir / "build",
config,
dependency_constraint_flags,
constraints_path,
build_options.environment,
)
pip_version = get_pip_version(env)
Expand Down
Loading
Loading