♻️ refactor(discovery): extract py_discovery as self-contained package#3070
Merged
gaborbernat merged 6 commits intopypa:mainfrom Feb 25, 2026
Merged
♻️ refactor(discovery): extract py_discovery as self-contained package#3070gaborbernat merged 6 commits intopypa:mainfrom
gaborbernat merged 6 commits intopypa:mainfrom
Conversation
ad61c9e to
08709c4
Compare
Move discovery logic into src/virtualenv/py_discovery/ with underscore-prefixed private modules and minimal public API. Remove creators() monkey-patch in favor of direct CreatorSelector.for_interpreter() calls. Auto-detect zipapp via pkgutil.get_data instead of exposing set_resolve_script. Thin wrappers in discovery/ provide CLI/argparse integration.
08709c4 to
739c7f2
Compare
for more information, see https://pre-commit.ci
b1369d3 to
e860fc1
Compare
Sync specifier frozen dataclasses, Final annotations, verbose regexes, and from_string factory methods from the py-discovery standalone repo. Signed-off-by: Bernát Gábor <bgabor8@bloomberg.net>
e860fc1 to
f5e323b
Compare
Replace internal py_discovery copy with python-discovery>=1. Add backward-compatibility re-export shims for py_info, py_spec, and cached_py_info to avoid breaking tox and other downstream consumers. Fix system_executable None handling in creator.py and restore fixture/mock parameter names that were incorrectly renamed with _ prefix.
Assert system_executable is not None to satisfy ty type checker. Normalize distribution names in zipapp build and lookup to handle packages with hyphens like python-discovery. Add Python 3.14 to zipapp versions.
This was referenced Feb 26, 2026
1 task
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
virtualenv's discovery module is tightly coupled to the rest of the codebase through imports of
AppData, subprocess wrappers, andvirtualenv.infoutilities. This makes it impossible for other tools — tox, pipx, nox — to reuse Python discovery without pulling in all of virtualenv. Today these tools either reimplement discovery poorly (no caching, no shim resolution) or reach into virtualenv internals directly with fragile imports likefrom virtualenv.discovery.cached_py_info import from_exe.This PR introduces
src/virtualenv/py_discovery/as a self-contained package with zero imports from the rest of virtualenv. ♻️ It ships its own Protocol-based cache layer (DiskCache/NoOpCache), platform compat utilities, and specifier parsing — all inlined from their original locations. The cache interface uses structural typing so virtualenv's existingAppDatapasses through without adapters. Aresolve_scriptparameter replaces the zipappensure_extractedcoupling, keeping that concern in virtualenv's wrapper layer where it belongs.The existing
src/virtualenv/discovery/becomes thin re-export wrappers that delegate topy_discovery. All external consumers (tox'sfrom virtualenv.discovery import cached_py_info, creator modules importingPythonInfo, etc.) continue working unchanged. Thecreators()method, which depends on virtualenv's plugin system, is monkey-patched back ontoPythonInfoin the wrapper layer rather than living in the extracted package. 🔌 Tools that want to use discovery directly can import fromvirtualenv.py_discoverywith justfilelockandplatformdirsas dependencies.Ref: #2074