8000 Support `requires_python` in `runtests.py` by Avasam · Pull Request #14051 · python/typeshed · GitHub
[go: up one dir, main page]

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter 8000

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
4 changes: 2 additions & 2 deletions lib/ts_utils/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def _is_nested_dict(obj: object) -> TypeGuard[dict[str, dict[str, Any]]]:


@functools.cache
def _get_oldest_supported_python() -> str:
def get_oldest_supported_python() -> str:
with PYPROJECT_PATH.open("rb") as config:
val = tomli.load(config)["tool"]["typeshed"]["oldest_supported_python"]
assert type(val) is str
Expand Down Expand Up @@ -276,7 +276,7 @@ def read_metadata(distribution: str) -> StubMetadata:
partial_stub: object = data.get("partial_stub", True)
assert type(partial_stub) is bool
requires_python_str: object = data.get("requires_python" 8000 ;)
oldest_supported_python = _get_oldest_supported_python()
oldest_supported_python = get_oldest_supported_python()
oldest_supported_python_specifier = Specifier(f">={oldest_supported_python}")
if requires_python_str is None:
requires_python = oldest_supported_python_specifier
Expand Down
19 changes: 13 additions & 6 deletions tests/runtests.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from importlib.util import find_spec
from pathlib import Path

from ts_utils.metadata import get_oldest_supported_python, read_metadata
from ts_utils.paths import TEST_CASES_DIR, test_cases_path
from ts_utils.utils import colored

Expand All @@ -19,9 +20,6 @@
_SUCCESS = colored("Success", "green")
_SKIPPED = colored("Skipped", "yellow")
_FAILED = colored("Failed", "red")
# We're using the oldest fully supported version because it's the most likely to produce errors
# due to unsupported syntax, feature, or bug in a tool.
_PYTHON_VERSION = "3.9"


def _parse_jsonc(json_text: str) -> str:
Expand Down Expand Up @@ -52,15 +50,16 @@ def main() -> None:
)
parser.add_argument(
"--python-version",
default=_PYTHON_VERSION,
default=None,
choices=("3.9", "3.10", "3.11", "3.12", "3.13", "3.14"),
help="Target Python version for the test (default: %(default)s).",
# We're using the oldest fully supported version because it's the most likely to produce errors
# due to unsupported syntax, feature, or bug in a tool.
help="Target Python version for the test (defaults to oldest supported Python version).",
)
parser.add_argument("path", help="Path of the stub to test in format <folder>/<stub>, from the root of the project.")
args = parser.parse_args()
path = Path(args.path)
run_stubtest: bool = args.run_stubtest
python_version: str = args.python_version

if len(path.parts) != 2:
parser.error("'path' argument should be in format <folder>/<stub>.")
Expand All @@ -69,6 +68,14 @@ def main() -> None:
parser.error("Only the 'stdlib' and 'stubs' folders are supported.")
if not path.exists():
parser.error(f"{path=} does not exist.")

if args.python_version:
python_version: str = args.python_version
elif folder in "stubs":
python_version = read_metadata(stub).requires_python.version
else:
python_version = get_oldest_supported_python()

stubtest_result: subprocess.CompletedProcess[bytes] | None = None
pytype_result: subprocess.CompletedProcess[bytes] | None = None

Expand Down
0