Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update pip install calls in scripts to use uv or reference current executable #13597

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ This has the following keys:
Only add extra OSes to the test
if there are platform-specific branches in a stubs package.

`*_dependencies` are usually packages needed to `pip install` the implementation
`*_dependencies` are usually system packages needed to install the python implementation
distribution.

The format of all `METADATA.toml` files can be checked by running
Expand Down Expand Up @@ -300,9 +300,8 @@ Typeshed includes `scripts/create_baseline_stubs.py`.
It generates stubs automatically using a tool called
[stubgen](https://mypy.readthedocs.io/en/latest/stubgen.html) that comes with mypy.

To get started, fork typeshed, clone your fork, and then
[create a virtualenv](#-or-create-a-local-development-environment).
You can then install the library with `pip` into the virtualenv and run the script below,
To get started, fork typeshed, clone your fork, and then [prepare your environment](#preparing-the-environment).
You can then install the library with `uv pip` into the virtualenv and run the script below,
replacing `$INSERT_LIBRARY_NAME_HERE` with the name of the library:

```bash
Expand Down
6 changes: 4 additions & 2 deletions scripts/create_baseline_stubs.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ def get_installed_package_info(project: str) -> tuple[str, str] | None:

Return (normalized project name, installed version) if successful.
"""
r = subprocess.run(["pip", "freeze"], capture_output=True, text=True, check=True)
# Not using "uv pip freeze" because if this is run from a global Python,
# it'll mistakenly list the .venv's packages.
r = subprocess.run(("pip", "freeze"), capture_output=True, text=True, check=True)
return search_pip_freeze_output(project, r.stdout)


Expand Down Expand Up @@ -220,7 +222,7 @@ def main() -> None:
if info is None:
print(f'Error: "{project}" is not installed', file=sys.stderr)
print(file=sys.stderr)
print(f'Suggestion: Run "python3 -m pip install {project}" and try again', file=sys.stderr)
print(f"Suggestion: Run `{sys.executable} -m pip install {project}` and try again", file=sys.stderr)
sys.exit(1)
project, version = info

Expand Down
11 changes: 9 additions & 2 deletions scripts/install_all_third_party_dependencies.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
import subprocess
import sys

from ts_utils.requirements import get_external_stub_requirements

requirements = get_external_stub_requirements()
subprocess.check_call(("pip", "install", *[str(requirement) for requirement in requirements]))

def main() -> None:
requirements = get_external_stub_requirements()
subprocess.check_call(("uv", "pip", "install", *sys.argv[1:], *[str(requirement) for requirement in requirements]))
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By forwarding arguments, we naturally allow non-venv (system installs) by letting the script's user follow uv's own helpful hint:
image



if __name__ == "__main__":
main()
2 changes: 1 addition & 1 deletion tests/mypy_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,7 @@ def setup_virtual_environments(distributions: dict[str, PackageDependencies], ar
print(colored(f"took {venv_elapsed_time:.2f} seconds", "blue"))

# STAGE 3: For each {virtual_environment: requirements_set} pairing,
# `pip install` the requirements set into the virtual environment
# `uv pip install` the requirements set into the virtual environment
pip_start_time = time.perf_counter()

# Limit workers to 10 at a time, since this makes network requests
Expand Down
7 changes: 6 additions & 1 deletion tests/runtests.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,12 @@ def main() -> None:
print("\nRunning pytype...")
pytype_result = subprocess.run([sys.executable, "tests/pytype_test.py", path])
else:
print(colored("\nSkipping pytype on Windows. You need to install it first: `pip install pytype`.", "yellow"))
print(
colored(
f"\nSkipping pytype on Windows. You need to install it first: `{sys.executable} -m pip install pytype` .",
"yellow",
)
)

cases_path = test_cases_path(stub if folder == "stubs" else "stdlib")
if not cases_path.exists():
Expand Down
Loading