mirror of
https://github.com/davidhalter/typeshed.git
synced 2026-01-28 13:52:12 +08:00
Integrate requirements-stubtest.txt into METADATA.toml (#9778)
This commit is contained in:
@@ -162,7 +162,7 @@ directly, with
|
||||
|
||||
For each distribution, stubtest ignores definitions listed in a `@tests/stubtest_allowlist.txt` file,
|
||||
relative to the distribution. Additional packages that are needed to run stubtest for a
|
||||
distribution can be added to `@tests/requirements-stubtest.txt`.
|
||||
distribution can be added to `tool.stubtest.stubtest_requirements` in `METADATA.toml`.
|
||||
|
||||
### Using stubtest to find objects missing from the stubs
|
||||
|
||||
|
||||
@@ -48,6 +48,7 @@ class StubtestSettings:
|
||||
extras: list[str]
|
||||
ignore_missing_stub: bool
|
||||
platforms: list[str]
|
||||
stubtest_requirements: list[str]
|
||||
|
||||
def system_requirements_for_platform(self, platform: str) -> list[str]:
|
||||
assert platform in _STUBTEST_PLATFORM_MAPPING, f"Unrecognised platform {platform!r}"
|
||||
@@ -69,6 +70,7 @@ def read_stubtest_settings(distribution: str) -> StubtestSettings:
|
||||
extras = data.get("extras", [])
|
||||
ignore_missing_stub = data.get("ignore_missing_stub", False)
|
||||
specified_platforms = data.get("platforms", ["linux"])
|
||||
stubtest_requirements = data.get("stubtest_requirements", [])
|
||||
|
||||
assert type(skipped) is bool
|
||||
assert type(ignore_missing_stub) is bool
|
||||
@@ -79,6 +81,7 @@ def read_stubtest_settings(distribution: str) -> StubtestSettings:
|
||||
assert _is_list_of_strings(brew_dependencies)
|
||||
assert _is_list_of_strings(choco_dependencies)
|
||||
assert _is_list_of_strings(extras)
|
||||
assert _is_list_of_strings(stubtest_requirements)
|
||||
|
||||
unrecognised_platforms = set(specified_platforms) - _STUBTEST_PLATFORM_MAPPING.keys()
|
||||
assert not unrecognised_platforms, f"Unrecognised platforms specified for {distribution!r}: {unrecognised_platforms}"
|
||||
@@ -98,6 +101,7 @@ def read_stubtest_settings(distribution: str) -> StubtestSettings:
|
||||
extras=extras,
|
||||
ignore_missing_stub=ignore_missing_stub,
|
||||
platforms=specified_platforms,
|
||||
stubtest_requirements=stubtest_requirements,
|
||||
)
|
||||
|
||||
|
||||
@@ -131,6 +135,7 @@ _KNOWN_METADATA_TOOL_FIELDS: Final = {
|
||||
"extras",
|
||||
"ignore_missing_stub",
|
||||
"platforms",
|
||||
"stubtest_requirements",
|
||||
}
|
||||
}
|
||||
_DIST_NAME_RE: Final = re.compile(r"^[a-z0-9]([a-z0-9._-]*[a-z0-9])?$", re.IGNORECASE)
|
||||
|
||||
@@ -41,10 +41,9 @@ def run_stubtest(dist: Path, *, verbose: bool = False, specified_stubs_only: boo
|
||||
dist_extras = ", ".join(stubtest_settings.extras)
|
||||
dist_req = f"{dist_name}[{dist_extras}]=={metadata.version}"
|
||||
|
||||
# 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)]
|
||||
# If tool.stubtest.stubtest_requirements exists, run "pip install" on it.
|
||||
if stubtest_settings.stubtest_requirements:
|
||||
pip_cmd = [pip_exe, "install"] + stubtest_settings.stubtest_requirements
|
||||
try:
|
||||
subprocess.run(pip_cmd, check=True, capture_output=True)
|
||||
except subprocess.CalledProcessError as e:
|
||||
|
||||
Reference in New Issue
Block a user