Skip to content

Commit c6ad9ac

Browse files
chore(toxgen): Check availability of pip and add detail to exceptions (#5076)
Exit `populate_tox.py` early if `pip` module is not available, and add a suggestion for running the script.
1 parent 3bc1d17 commit c6ad9ac

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-1
lines changed

scripts/populate_tox/README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,20 @@ sure we support everything we claim to.
77
This `populate_tox.py` script is responsible for picking reasonable versions to
88
test automatically and generating parts of `tox.ini` to capture this.
99

10+
## Running the script
11+
12+
You require a free-threaded interpreter with pip installed to run the script. With
13+
a recent version of `uv` you can directly run the script with the following
14+
command:
15+
16+
```
17+
uv run --python 3.14t \
18+
--with pip \
19+
--with-requirements scripts/populate_tox/requirements.txt \
20+
--with-editable . \
21+
python scripts/populate_tox/populate_tox.py
22+
```
23+
1024
## How it works
1125

1226
There is a template in this directory called `tox.jinja` which contains a

scripts/populate_tox/populate_tox.py

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -891,7 +891,31 @@ def _normalize_package_dependencies(package_dependencies: list[dict]) -> list[di
891891

892892
def _exit_if_not_free_threaded_interpreter():
893893
if "free-threading build" not in sys.version:
894-
raise Exception("Running with a free-threaded interpreter is required.")
894+
exc = Exception("Running with a free-threaded interpreter is required.")
895+
exc.add_note(
896+
"A dry run of pip is used to determine free-threading support of packages."
897+
)
898+
raise exc
899+
900+
901+
def _exit_if_pip_unavailable():
902+
pip_help_return_code = subprocess.run(
903+
[
904+
sys.executable,
905+
"-m",
906+
"pip",
907+
"--help",
908+
],
909+
stdout=subprocess.DEVNULL,
910+
stderr=subprocess.DEVNULL,
911+
).returncode
912+
913+
if pip_help_return_code != 0:
914+
exc = Exception("pip must be available.")
915+
exc.add_note(
916+
"A dry run of pip is used to determine free-threading support of packages."
917+
)
918+
raise exc
895919

896920

897921
def main() -> dict[str, list]:
@@ -901,6 +925,7 @@ def main() -> dict[str, list]:
901925
global MIN_PYTHON_VERSION, MAX_PYTHON_VERSION
902926

903927
_exit_if_not_free_threaded_interpreter()
928+
_exit_if_pip_unavailable()
904929

905930
meta = _fetch_sdk_metadata()
906931
sdk_python_versions = _parse_python_versions_from_classifiers(

0 commit comments

Comments
 (0)