Skip to content

feat(pylock): allow select() to prefer source distributions#1334

Open
r266-tech wants to merge 2 commits into
pypa:mainfrom
r266-tech:feat/pylock-prefer-sdist
Open

feat(pylock): allow select() to prefer source distributions#1334
r266-tech wants to merge 2 commits into
pypa:mainfrom
r266-tech:feat/pylock-prefer-sdist

Conversation

@r266-tech

Copy link
Copy Markdown
Contributor

Summary

Add the maintainer-proposed prefer_sdist_predicate argument to Pylock.select() so installers can apply per-package source-build policy.

  • Select an available sdist before compatible wheels when the predicate returns True.
  • Preserve compatible-wheel selection, sdist fallback, and the existing error when no usable source exists.
  • Document the 26.3 API addition and cover the full wheel/sdist selection matrix.

Closes #1333.

Verification

  • python -m pytest -q (62118 passed, 1 skipped, 417 deselected)
  • python -m pytest tests/test_pylock_select.py -q (25 passed)
  • ruff check src/packaging/pylock.py tests/test_pylock_select.py
  • ruff format --check src/packaging/pylock.py tests/test_pylock_select.py
  • uvx nox -s docs (392 doctests passed; HTML and LaTeX builds clean)
  • Targeted strict mypy check for both changed files

@sbidoul

sbidoul commented Jul 15, 2026

Copy link
Copy Markdown
Member

For ease of verification, this should not change existing tests.

@r266-tech

Copy link
Copy Markdown
Contributor Author

Thanks — updated in ad866d0.

  • Restored test_sdist_fallback and test_missing_sdist_fallback unchanged.
  • Moved the new behavior into a separate test_prefer_sdist_predicate parameterized test.
  • Avoided calling the predicate when no sdist exists, and added the incompatible-wheel case to make the issue's source-preference contract explicit.

Verified with pytest tests/test_pylock_select.py -q (24 passed), Ruff check/format, and git diff --check.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow Pylock.select to prefer source distributions

2 participants