Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit bdf036d

Browse files
authored
check_consistent.py: Add check ensuring packages are not installed for unspecified platforms (#9265)
1 parent 59f35b5 commit bdf036d

3 files changed

Lines changed: 23 additions & 6 deletions

File tree

tests/check_consistent.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,14 @@
1515
from packaging.requirements import Requirement
1616
from packaging.specifiers import SpecifierSet
1717
from packaging.version import Version
18-
from utils import VERSIONS_RE, get_all_testcase_directories, get_gitignore_spec, spec_matches_path, strip_comments
18+
from utils import (
19+
METADATA_MAPPING,
20+
VERSIONS_RE,
21+
get_all_testcase_directories,
22+
get_gitignore_spec,
23+
spec_matches_path,
24+
strip_comments,
25+
)
1926

2027
metadata_keys = {
2128
"version",
@@ -182,11 +189,19 @@ def check_metadata() -> None:
182189
for key in data.get("tool", {}).get(tool, {}):
183190
assert key in tk, f"Unrecognised {tool} key {key} for {distribution}"
184191

185-
specified_stubtest_platforms = set(data.get("tool", {}).get("stubtest", {}).get("platforms", []))
192+
tool_stubtest = data.get("tool", {}).get("stubtest", {})
193+
specified_stubtest_platforms = set(tool_stubtest.get("platforms", []))
186194
assert (
187195
specified_stubtest_platforms <= supported_stubtest_platforms
188196
), f"Unrecognised platforms specified: {supported_stubtest_platforms - specified_stubtest_platforms}"
189197

198+
# Check that only specified platforms install packages:
199+
for supported_plat in supported_stubtest_platforms:
200+
if supported_plat not in specified_stubtest_platforms:
201+
assert (
202+
METADATA_MAPPING[supported_plat] not in tool_stubtest
203+
), f"Installing system deps for unspecified platform {supported_plat} for {distribution}"
204+
190205

191206
def get_txt_requirements() -> dict[str, SpecifierSet]:
192207
with open("requirements-tests.txt", encoding="UTF-8") as requirements_file:

tests/get_packages.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,15 @@
33
import sys
44

55
import tomli
6+
from utils import METADATA_MAPPING
67

78
platform = sys.platform
89
distributions = sys.argv[1:]
910
if not distributions:
1011
distributions = os.listdir("stubs")
1112

12-
metadata_mapping = {"linux": "apt_dependencies", "darwin": "brew_dependencies", "win32": "choco_dependencies"}
13-
14-
if platform in metadata_mapping:
13+
if platform in METADATA_MAPPING:
1514
for distribution in distributions:
1615
with open(f"stubs/{distribution}/METADATA.toml", "rb") as file:
17-
for package in tomli.load(file).get("tool", {}).get("stubtest", {}).get(metadata_mapping[platform], []):
16+
for package in tomli.load(file).get("tool", {}).get("stubtest", {}).get(METADATA_MAPPING[platform], []):
1817
print(package)

tests/utils.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
import pathspec # type: ignore[import]
1313
import tomli
1414

15+
# Used to install system-wide packages for different OS types:
16+
METADATA_MAPPING = {"linux": "apt_dependencies", "darwin": "brew_dependencies", "win32": "choco_dependencies"}
17+
1518

1619
def strip_comments(text: str) -> str:
1720
return text.split("#")[0].strip()

0 commit comments

Comments
 (0)