Switch to uv for all of our Python scripts (#7242)

This removes the need to install any specific version of Python or
figure out how to configure it by instead asking users to install `uv`
and letting it manage Python. Among other advantages, `uv` is designed
to be fast enough to embed directly into our scripts.

We were already using this in `bench_runner.py` so that the script could
import non standard library dependencies. Moving to it for the rest of
our Python unifies the approach and will also enable dependencies
whenever needed.

I've left `github_tools` alone as it has special handling with its own
Bazel setup.

I've updated the contributing tools to explain the approach here.
This commit is contained in:
Chandler Carruth
2026-05-28 18:03:52 +00:00
committed by GitHub
parent 6aee1280e9
commit b79ce84f33
32 changed files with 193 additions and 75 deletions
+14 -14
View File
@@ -1,14 +1,24 @@
#!/usr/bin/env python3
#!/usr/bin/env -S uv run --script
# /// script
# requires-python = ">=3.10"
# dependencies = [
# "gql==2.0.0",
# "requests",
# "types-requests",
# ]
# ///
"""Check if a PR depends on other open PRs based on shared commits.
Usage examples:
# Check a specific PR in dry-run mode:
GITHUB_ACCESS_TOKEN=$(gh auth token) \
python3 github_tools/check_dependent_pr.py --pr-number <PR_NUMBER> --dry-run
./github_tools/check_dependent_pr.py --pr-number <PR_NUMBER> --dry-run
# Scan all dependent PRs in dry-run mode:
GITHUB_ACCESS_TOKEN=$(gh auth token) \
python3 github_tools/check_dependent_pr.py --scan --dry-run
./github_tools/check_dependent_pr.py --scan --dry-run
"""
__copyright__ = """
@@ -19,26 +29,16 @@ SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
import argparse
import datetime
import importlib.util
import json
import re
import os
import sys
import requests
from typing import Any, Optional
# Do some extra work to support direct runs.
try:
from github_tools import github_helpers
except ImportError:
github_helpers_spec = importlib.util.spec_from_file_location(
"github_helpers",
os.path.join(os.path.dirname(__file__), "github_helpers.py"),
)
assert github_helpers_spec is not None
github_helpers = importlib.util.module_from_spec(github_helpers_spec)
github_helpers_spec.loader.exec_module(github_helpers) # type: ignore
import github_helpers # type: ignore
# Queries
_QUERY_OPEN_PRS = """