Skip to content

Commit 8ca6a62

Browse files
authored
fix: mirror dependencies declared by wheels built from sdists (#5202)
1 parent a66aa23 commit 8ca6a62

2 files changed

Lines changed: 88 additions & 24 deletions

File tree

xinference/deploy/docker/pypiserver/download_packages.py

Lines changed: 71 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -411,31 +411,78 @@ def main() -> None:
411411
# 4. Build wheels for sdist-only downloads so the runtime never
412412
# compiles. Failures keep the sdist (the runtime image has a
413413
# toolchain) and are recorded in the report.
414+
#
415+
# A built wheel can declare dependencies that the sdist's static
416+
# metadata omitted (e.g. GPTQModel publishes an sdist whose
417+
# PKG-INFO lists no runtime requirements, while the wheel its
418+
# setup.py builds does). The locks above only saw the sdist
419+
# metadata, so fetch each built wheel's dependencies explicitly
420+
# and repeat until no new sdists arrive.
414421
# ------------------------------------------------------------------
415-
for sdist in sorted(dest.iterdir()):
416-
if sdist.suffix not in (".gz", ".zip", ".bz2") and not sdist.name.endswith(
417-
".tar.gz"
418-
):
419-
continue
420-
proc = run(
421-
[
422-
sys.executable,
423-
"-m",
424-
"pip",
425-
"wheel",
426-
"--quiet",
427-
"--no-deps",
428-
"--wheel-dir",
429-
str(dest),
430-
str(sdist),
431-
],
432-
env=package_build_env,
433-
)
434-
if proc.returncode == 0:
435-
sdist.unlink()
436-
else:
437-
print(f"WARN: keeping sdist {sdist.name}", flush=True)
438-
sdist_left.append(sdist.name)
422+
failed_sdists: Set[str] = set()
423+
while True:
424+
built_wheels: List[Path] = []
425+
for sdist in sorted(dest.iterdir()):
426+
if sdist.suffix not in (".gz", ".zip", ".bz2") and not sdist.name.endswith(
427+
".tar.gz"
428+
):
429+
continue
430+
if sdist.name in failed_sdists:
431+
continue
432+
wheels_before = {p.name for p in dest.glob("*.whl")}
433+
proc = run(
434+
[
435+
sys.executable,
436+
"-m",
437+
"pip",
438+
"wheel",
439+
"--quiet",
440+
"--no-deps",
441+
"--wheel-dir",
442+
str(dest),
443+
str(sdist),
444+
],
445+
env=package_build_env,
446+
)
447+
if proc.returncode == 0:
448+
sdist.unlink()
449+
built_wheels.extend(
450+
p for p in dest.glob("*.whl") if p.name not in wheels_before
451+
)
452+
else:
453+
print(f"WARN: keeping sdist {sdist.name}", flush=True)
454+
failed_sdists.add(sdist.name)
455+
if not built_wheels:
456+
break
457+
for wheel in built_wheels:
458+
proc = pip_download(
459+
[str(wheel)],
460+
dest,
461+
index_url=args.index_url,
462+
extra_index_urls=[args.pytorch_index],
463+
constraints=master_constraints,
464+
env=package_build_env,
465+
)
466+
if proc.returncode != 0:
467+
print(
468+
f"WARN: retrying dependencies of '{wheel.name}' "
469+
"without constraints",
470+
flush=True,
471+
)
472+
proc = pip_download(
473+
[str(wheel)],
474+
dest,
475+
index_url=args.index_url,
476+
extra_index_urls=[args.pytorch_index],
477+
env=package_build_env,
478+
)
479+
if proc.returncode != 0:
480+
sys.exit(
481+
f"FATAL: failed to fetch dependencies of built "
482+
f"wheel '{wheel.name}'"
483+
)
484+
unconstrained_fallbacks.append(wheel.name)
485+
sdist_left.extend(sorted(failed_sdists))
439486

440487
# ------------------------------------------------------------------
441488
# Report.

xinference/deploy/docker/pypiserver/tests/test_scripts.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,10 +417,18 @@ def fake_pip_download(args, target, **kwargs):
417417
download_calls.append((list(args), kwargs))
418418
if args == ["model-pin==1.0"]:
419419
(target / "source-1.0.tar.gz").write_text("sdist")
420+
# The wheel built from the sdist declares a dependency that the
421+
# sdist metadata omitted; it only exists as an sdist itself.
422+
if args == [str(dest / "source-1.0-py3-none-any.whl")]:
423+
(target / "hiddendep-1.0.tar.gz").write_text("sdist")
420424
return subprocess.CompletedProcess([], 0)
421425

422426
def fake_run(cmd, **kwargs):
423427
run_calls.append((list(cmd), kwargs))
428+
if "wheel" in cmd:
429+
sdist_name = Path(cmd[-1]).name
430+
wheel_name = sdist_name.replace(".tar.gz", "-py3-none-any.whl")
431+
(dest / wheel_name).write_text("wheel")
424432
return subprocess.CompletedProcess(cmd, 0)
425433

426434
monkeypatch.setattr(downloader, "uv_compile", fake_uv_compile)
@@ -458,6 +466,15 @@ def fake_run(cmd, **kwargs):
458466
assert all(call[1]["env"]["TORCH_VERSION"] == "2.12.3" for call in download_calls)
459467
assert all(call[1]["env"]["TORCH_VERSION"] == "2.12.3" for call in run_calls)
460468
assert not (dest / "source-1.0.tar.gz").exists()
469+
# Dependencies of wheels built from sdists are fetched from the built
470+
# wheel's own metadata, transitively until no new sdists arrive.
471+
assert [str(dest / "source-1.0-py3-none-any.whl")] in [
472+
call[0] for call in download_calls
473+
]
474+
assert [str(dest / "hiddendep-1.0-py3-none-any.whl")] in [
475+
call[0] for call in download_calls
476+
]
477+
assert not (dest / "hiddendep-1.0.tar.gz").exists()
461478
report = json.loads((manifest / "report.json").read_text())
462479
assert "transformers==5.13.1" in report["runtime_constraints"]
463480
assert report["unconstrained_fallbacks"] == []

0 commit comments

Comments
 (0)