Skip to content

Commit fd840c0

Browse files
committed
fix: pull out windows workaround
Signed-off-by: Henry Schreiner <[email protected]>
1 parent f1a6af4 commit fd840c0

File tree

4 files changed

+36
-22
lines changed

4 files changed

+36
-22
lines changed

cibuildwheel/macos.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
BuildSelector,
3232
NonPlatformWheelError,
3333
call,
34+
combine_constraints,
3435
detect_ci_provider,
3536
download,
3637
find_compatible_wheel,
@@ -432,11 +433,8 @@ def build(options: Options, tmp_path: Path) -> None:
432433
constraint_path = build_options.dependency_constraints.get_for_python_version(
433434
config.version
434435
)
435-
pip_constraint = "UV_CONSTRAINT" if use_uv else "PIP_CONSTRAINT"
436-
user_constraints = build_env.get(pip_constraint)
437-
our_constraints = str(constraint_path) if use_uv else constraint_path.as_uri()
438-
build_env[pip_constraint] = " ".join(
439-
c for c in [user_constraints, our_constraints] if c
436+
combine_constraints(
437+
build_env, constraint_path, identifier_tmp_dir if use_uv else None
440438
)
441439

442440
if build_frontend.name == "pip":

cibuildwheel/util.py

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
import typing
1717
import urllib.request
1818
from collections import defaultdict
19-
from collections.abc import Generator, Iterable, Mapping, Sequence
19+
from collections.abc import Generator, Iterable, Mapping, MutableMapping, Sequence
2020
from dataclasses import dataclass
2121
from enum import Enum
2222
from functools import cached_property, lru_cache
@@ -44,6 +44,7 @@
4444
"cached_property",
4545
"call",
4646
"chdir",
47+
"combine_constraints",
4748
"find_compatible_wheel",
4849
"find_uv",
4950
"format_safe",
@@ -866,9 +867,37 @@ def parse_key_value_string(
866867
def find_uv() -> Path | None:
867868
# Prefer uv in our environment
868869
with contextlib.suppress(ImportError, FileNotFoundError):
870+
# pylint: disable-next=import-outside-toplevel
869871
from uv import find_uv_bin
870872

871873
return Path(find_uv_bin())
872874

873875
uv_on_path = shutil.which("uv")
874876
return Path(uv_on_path) if uv_on_path else None
877+
878+
879+
def combine_constraints(
880+
env: MutableMapping[str, str], /, constraints_path: Path, tmp_dir: Path | None
881+
) -> None:
882+
"""
883+
This will workaround a bug in pip<=21.1.1 or uv<=0.2.0 if a tmp_dir is given.
884+
If set to None, this will use the modern URI method.
885+
"""
886+
887+
if tmp_dir:
888+
if " " in str(constraints_path):
889+
assert " " not in str(tmp_dir)
890+
tmp_file = tmp_dir / "constraints.txt"
891+
tmp_file.write_bytes(constraints_path.read_bytes())
892+
constraints_path = tmp_file
893+
our_constraints = str(constraints_path)
894+
else:
895+
our_constraints = (
896+
constraints_path.as_uri() if " " in str(constraints_path) else str(constraints_path)
897+
)
898+
899+
user_constraints = env.get("PIP_CONSTRAINT")
900+
901+
env["UV_CONSTRAINT"] = env["PIP_CONSTRAINT"] = " ".join(
902+
c for c in [our_constraints, user_constraints] if c
903+
)

cibuildwheel/windows.py

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
BuildSelector,
3030
NonPlatformWheelError,
3131
call,
32+
combine_constraints,
3233
download,
3334
extract_zip,
3435
find_compatible_wheel,
@@ -425,22 +426,7 @@ def build(options: Options, tmp_path: Path) -> None:
425426
constraints_path = build_options.dependency_constraints.get_for_python_version(
426427
config.version
427428
)
428-
# Bug in pip <= 21.1.3 - we can't have a space in the
429-
# constraints file, and pip doesn't support drive letters
430-
# in uhi. After probably pip 21.2, we can use uri. For
431-
# now, use a temporary file.
432-
if " " in str(constraints_path):
433-
assert " " not in str(identifier_tmp_dir)
434-
tmp_file = identifier_tmp_dir / "constraints.txt"
435-
tmp_file.write_bytes(constraints_path.read_bytes())
436-
constraints_path = tmp_file
437-
438-
our_constraints = str(constraints_path)
439-
user_constraints = build_env.get("PIP_CONSTRAINT")
440-
build_env["PIP_CONSTRAINT"] = " ".join(
441-
c for c in [our_constraints, user_constraints] if c
442-
)
443-
build_env["UV_CONSTRAINT"] = build_env["PIP_CONSTRAINT"]
429+
combine_constraints(build_env, constraints_path, identifier_tmp_dir)
444430

445431
if build_frontend.name == "pip":
446432
extra_flags += get_build_verbosity_extra_flags(build_options.build_verbosity)

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ messages_control.disable = [
177177
"wrong-import-position",
178178
"unused-argument", # Handled by Ruff
179179
"broad-exception-raised", # Could be improved eventually
180+
"consider-using-in", # MyPy can't narrow "in"
180181
]
181182

182183
[tool.ruff]

0 commit comments

Comments
 (0)