check_consistent.py: Add check ensuring packages are not installed for unspecified platforms (#9265)

This commit is contained in:
Nikita Sobolev
2022-11-25 13:11:59 +03:00
committed by GitHub
parent 59f35b51b2
commit bdf036d516
3 changed files with 23 additions and 6 deletions

View File

@@ -15,7 +15,14 @@ import yaml
from packaging.requirements import Requirement
from packaging.specifiers import SpecifierSet
from packaging.version import Version
from utils import VERSIONS_RE, get_all_testcase_directories, get_gitignore_spec, spec_matches_path, strip_comments
from utils import (
METADATA_MAPPING,
VERSIONS_RE,
get_all_testcase_directories,
get_gitignore_spec,
spec_matches_path,
strip_comments,
)
metadata_keys = {
"version",
@@ -182,11 +189,19 @@ def check_metadata() -> None:
for key in data.get("tool", {}).get(tool, {}):
assert key in tk, f"Unrecognised {tool} key {key} for {distribution}"
specified_stubtest_platforms = set(data.get("tool", {}).get("stubtest", {}).get("platforms", []))
tool_stubtest = data.get("tool", {}).get("stubtest", {})
specified_stubtest_platforms = set(tool_stubtest.get("platforms", []))
assert (
specified_stubtest_platforms <= supported_stubtest_platforms
), f"Unrecognised platforms specified: {supported_stubtest_platforms - specified_stubtest_platforms}"
# Check that only specified platforms install packages:
for supported_plat in supported_stubtest_platforms:
if supported_plat not in specified_stubtest_platforms:
assert (
METADATA_MAPPING[supported_plat] not in tool_stubtest
), f"Installing system deps for unspecified platform {supported_plat} for {distribution}"
def get_txt_requirements() -> dict[str, SpecifierSet]:
with open("requirements-tests.txt", encoding="UTF-8") as requirements_file:

View File

@@ -3,16 +3,15 @@ import os
import sys
import tomli
from utils import METADATA_MAPPING
platform = sys.platform
distributions = sys.argv[1:]
if not distributions:
distributions = os.listdir("stubs")
metadata_mapping = {"linux": "apt_dependencies", "darwin": "brew_dependencies", "win32": "choco_dependencies"}
if platform in metadata_mapping:
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], []):
for package in tomli.load(file).get("tool", {}).get("stubtest", {}).get(METADATA_MAPPING[platform], []):
print(package)

View File

@@ -12,6 +12,9 @@ from typing import NamedTuple
import pathspec # type: ignore[import]
import tomli
# Used to install system-wide packages for different OS types:
METADATA_MAPPING = {"linux": "apt_dependencies", "darwin": "brew_dependencies", "win32": "choco_dependencies"}
def strip_comments(text: str) -> str:
return text.split("#")[0].strip()