mirror of
https://github.com/davidhalter/typeshed.git
synced 2026-02-10 03:31:27 +08:00
Add the ability to run third-party stubtest on Windows or MacOS when needed (#8923)
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com> Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
This commit is contained in:
@@ -18,7 +18,7 @@ from packaging.version import Version
|
||||
from utils import VERSIONS_RE, get_all_testcase_directories, get_gitignore_spec, spec_matches_path, strip_comments
|
||||
|
||||
metadata_keys = {"version", "requires", "extra_description", "obsolete_since", "no_longer_updated", "tool"}
|
||||
tool_keys = {"stubtest": {"skip", "apt_dependencies", "extras", "ignore_missing_stub"}}
|
||||
tool_keys = {"stubtest": {"skip", "apt_dependencies", "extras", "ignore_missing_stub", "platforms"}}
|
||||
extension_descriptions = {".pyi": "stub", ".py": ".py"}
|
||||
|
||||
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
#!/usr/bin/env python3
|
||||
import os
|
||||
import sys
|
||||
|
||||
import tomli
|
||||
|
||||
distributions = sys.argv[1:]
|
||||
if not distributions:
|
||||
distributions = os.listdir("stubs")
|
||||
|
||||
for distribution in distributions:
|
||||
with open(f"stubs/{distribution}/METADATA.toml", "rb") as file:
|
||||
for apt_package in tomli.load(file).get("tool", {}).get("stubtest", {}).get("apt_dependencies", []):
|
||||
print(apt_package)
|
||||
23
tests/get_packages.py
Executable file
23
tests/get_packages.py
Executable file
@@ -0,0 +1,23 @@
|
||||
#!/usr/bin/env python3
|
||||
import os
|
||||
import sys
|
||||
|
||||
import tomli
|
||||
|
||||
platform = sys.platform
|
||||
distributions = sys.argv[1:]
|
||||
if not distributions:
|
||||
distributions = os.listdir("stubs")
|
||||
|
||||
metadata_mapping = {
|
||||
"linux": "apt_dependencies",
|
||||
# We could add others here if we run into stubs that need it:
|
||||
# "darwin": "brew_dependencies",
|
||||
# "win32": "choco_dependencies",
|
||||
}
|
||||
|
||||
if platform in metadata_mapping:
|
||||
for distribution in distributions:
|
||||
with open(f"stubs/{distribution}/METADATA.toml", "rb") as file:
|
||||
for package in tomli.load(file).get("tool", {}).get("stubtest", {}).get(metadata_mapping[platform], []):
|
||||
print(package)
|
||||
@@ -34,6 +34,11 @@ def run_stubtest(dist: Path, *, verbose: bool = False) -> bool:
|
||||
print(colored("skipping", "yellow"))
|
||||
return True
|
||||
|
||||
platforms_to_test = stubtest_meta.get("platforms", ["linux"])
|
||||
if sys.platform not in platforms_to_test:
|
||||
print(colored(f"skipping, unsupported platform: {sys.platform}, supported: {platforms_to_test}", "yellow"))
|
||||
return True
|
||||
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
venv_dir = Path(tmp)
|
||||
venv.create(venv_dir, with_pip=True, clear=True)
|
||||
@@ -57,8 +62,8 @@ def run_stubtest(dist: Path, *, verbose: bool = False) -> bool:
|
||||
# If @tests/requirements-stubtest.txt exists, run "pip install" on it.
|
||||
req_path = dist / "@tests" / "requirements-stubtest.txt"
|
||||
if req_path.exists():
|
||||
pip_cmd = [pip_exe, "install", "-r", str(req_path)]
|
||||
try:
|
||||
pip_cmd = [pip_exe, "install", "-r", str(req_path)]
|
||||
subprocess.run(pip_cmd, check=True, capture_output=True)
|
||||
except subprocess.CalledProcessError as e:
|
||||
print_command_failure("Failed to install requirements", e)
|
||||
@@ -102,6 +107,9 @@ def run_stubtest(dist: Path, *, verbose: bool = False) -> bool:
|
||||
allowlist_path = dist / "@tests/stubtest_allowlist.txt"
|
||||
if allowlist_path.exists():
|
||||
stubtest_cmd.extend(["--allowlist", str(allowlist_path)])
|
||||
platform_allowlist = dist / f"@tests/stubtest_allowlist_{sys.platform}.txt"
|
||||
if platform_allowlist.exists():
|
||||
stubtest_cmd.extend(["--allowlist", str(platform_allowlist)])
|
||||
|
||||
try:
|
||||
subprocess.run(stubtest_cmd, env=stubtest_env, check=True, capture_output=True)
|
||||
|
||||
Reference in New Issue
Block a user