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

Skip to content

Commit 451e0ef

Browse files
authored
Improve documentation of the check_consistent script (#11757)
1 parent 6bd4556 commit 451e0ef

1 file changed

Lines changed: 16 additions & 8 deletions

File tree

tests/check_consistent.py

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
#!/usr/bin/env python3
22

3-
# For security (and simplicity) reasons, only a limited kind of files can be
4-
# present in /stdlib and /stubs directories, see README for detail. Here we
5-
# verify these constraints.
3+
"""
4+
Check that the typeshed repository contains the correct files in the
5+
correct places, and that various configuration files are correct.
6+
"""
7+
68
from __future__ import annotations
79

810
import os
@@ -53,10 +55,12 @@ def assert_consistent_filetypes(
5355

5456

5557
def check_stdlib() -> None:
58+
"""Check that the stdlib directory contains only the correct files."""
5659
assert_consistent_filetypes(Path("stdlib"), kind=".pyi", allowed={"_typeshed/README.md", "VERSIONS"})
5760

5861

5962
def check_stubs() -> None:
63+
"""Check that the stubs directory contains only the correct files."""
6064
gitignore_spec = get_gitignore_spec()
6165
for dist in Path("stubs").iterdir():
6266
if spec_matches_path(gitignore_spec, dist):
@@ -80,6 +84,7 @@ def check_stubs() -> None:
8084

8185

8286
def check_test_cases() -> None:
87+
"""Check that the test_cases directory contains only the correct files."""
8388
for _, testcase_dir in get_all_testcase_directories():
8489
assert_consistent_filetypes(testcase_dir, kind=".py", allowed={"README.md"}, allow_nonidentifier_filenames=True)
8590
bad_test_case_filename = 'Files in a `test_cases` directory must have names starting with "check_"; got "{}"'
@@ -88,6 +93,7 @@ def check_test_cases() -> None:
8893

8994

9095
def check_no_symlinks() -> None:
96+
"""Check that there are no symlinks in the typeshed repository."""
9197
files = [os.path.join(root, file) for root, _, files in os.walk(".") for file in files]
9298
no_symlink = "You cannot use symlinks in typeshed, please copy {} to its link."
9399
for file in files:
@@ -96,7 +102,8 @@ def check_no_symlinks() -> None:
96102
raise ValueError(no_symlink.format(file))
97103

98104

99-
def check_versions() -> None:
105+
def check_versions_file() -> None:
106+
"""Check that the stdlib/VERSIONS file has the correct format."""
100107
versions = set[str]()
101108
with open("stdlib/VERSIONS", encoding="UTF-8") as f:
102109
data = f.read().splitlines()
@@ -132,6 +139,7 @@ def _find_stdlib_modules() -> set[str]:
132139

133140

134141
def check_metadata() -> None:
142+
"""Check that all METADATA.toml files are valid."""
135143
for distribution in os.listdir("stubs"):
136144
# This function does various sanity checks for METADATA.toml files
137145
read_metadata(distribution)
@@ -150,10 +158,10 @@ def check_requirement_pins() -> None:
150158

151159
if __name__ == "__main__":
152160
assert sys.version_info >= (3, 9), "Python 3.9+ is required to run this test"
153-
check_stdlib()
154-
check_versions()
155-
check_stubs()
161+
check_versions_file()
156162
check_metadata()
163+
check_requirement_pins()
157164
check_no_symlinks()
165+
check_stdlib()
166+
check_stubs()
158167
check_test_cases()
159-
check_requirement_pins()

0 commit comments

Comments
 (0)