Skip to content

Commit 1fa4986

Browse files
authored
Move common utility functions to a common library (#12773)
1 parent 407eeaa commit 1fa4986

21 files changed

+31
-31
lines changed

.gitignore

+1-2
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,11 @@ __pycache__/
88
# Distribution / packaging
99
.Python
1010
/env/
11-
/build/
11+
/lib/build/
1212
/develop-eggs/
1313
/dist/
1414
/downloads/
1515
/eggs/
16-
/lib/
1716
/lib64/
1817
/parts/
1918
/sdist/

lib/pyproject.toml

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Utilities for typeshed infrastructure scripts.

lib/ts_utils/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"""Utilities for typeshed infrastructure scripts."""

tests/_metadata.py renamed to lib/ts_utils/metadata.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
from packaging.specifiers import Specifier
2020
from packaging.version import Version
2121

22-
from _utils import cache
22+
from .utils import cache
2323

2424
__all__ = [
2525
"NoSuchStubError",

lib/ts_utils/py.typed

Whitespace-only changes.
File renamed without changes.

pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ extra-standard-library = [
162162
"pyexpat",
163163
"zoneinfo",
164164
]
165-
known-first-party = ["_metadata", "_utils"]
165+
known-first-party = ["ts_utils", "_utils"]
166166

167167
[tool.typeshed]
168168
oldest_supported_python = "3.8"

pyrightconfig.scripts_and_tests.json

+4
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,13 @@
22
"$schema": "https://raw.githubusercontent.com/microsoft/pyright/main/packages/vscode-pyright/schemas/pyrightconfig.schema.json",
33
"typeshedPath": ".",
44
"include": [
5+
"lib",
56
"scripts",
67
"tests",
78
],
9+
"extraPaths": [
10+
"lib",
11+
],
812
"typeCheckingMode": "strict",
913
// More of a lint. Unwanted for typeshed's own code.
1014
"reportImplicitStringConcatenation": "none",

requirements-tests.txt

+3
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,6 @@ tomli==2.0.2
2222
tomlkit==0.13.2
2323
typing_extensions>=4.12.0rc1
2424
uv==0.4.18
25+
26+
# Utilities for typeshed infrastructure scripts.
27+
ts_utils @ file:lib

scripts/stubsabot.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ async def get_github_repo_info(session: aiohttp.ClientSession, stub_info: StubIn
312312
Else, return None.
313313
"""
314314
if stub_info.upstream_repository:
315-
# We have various sanity checks for the upstream_repository field in tests/_metadata.py,
315+
# We have various sanity checks for the upstream_repository field in ts_utils.metadata,
316316
# so no need to repeat all of them here
317317
split_url = urllib.parse.urlsplit(stub_info.upstream_repository)
318318
if split_url.netloc == "github.com":

tests/check_typeshed_structure.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
import sys
1313
from pathlib import Path
1414

15-
from _metadata import read_metadata
16-
from _utils import (
15+
from ts_utils.metadata import read_metadata
16+
from ts_utils.utils import (
1717
REQS_FILE,
1818
STDLIB_PATH,
1919
TEST_CASES_DIR,

tests/get_external_stub_requirements.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
from packaging.requirements import Requirement
1313

14-
from _metadata import read_dependencies
14+
from ts_utils.metadata import read_dependencies
1515

1616
distributions = sys.argv[1:]
1717
if not distributions:

tests/get_stubtest_system_requirements.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
#!/usr/bin/env python3
2+
23
import os
34
import sys
45

5-
from _metadata import read_stubtest_settings
6+
from ts_utils.metadata import read_stubtest_settings
67

78
platform = sys.platform
89
distributions = sys.argv[1:]

tests/mypy_test.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222
import tomli
2323
from packaging.requirements import Requirement
2424

25-
from _metadata import PackageDependencies, get_recursive_requirements, read_metadata
26-
from _utils import (
25+
from ts_utils.metadata import PackageDependencies, get_recursive_requirements, read_metadata
26+
from ts_utils.utils import (
2727
PYTHON_VERSION,
2828
STDLIB_PATH,
2929
TESTS_DIR,
@@ -173,7 +173,7 @@ def add_configuration(configurations: list[MypyDistConf], distribution: str) ->
173173
with Path("stubs", distribution, "METADATA.toml").open("rb") as f:
174174
data = tomli.load(f)
175175

176-
# TODO: This could be added to _metadata.py, but is currently unused
176+
# TODO: This could be added to ts_utils.metadata, but is currently unused
177177
mypy_tests_conf: dict[str, dict[str, Any]] = data.get("mypy-tests", {})
178178
if not mypy_tests_conf:
179179
return

tests/pyright_test.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import sys
77
from pathlib import Path
88

9-
from _utils import parse_requirements, print_command
9+
from ts_utils.utils import parse_requirements, print_command
1010

1111
_WELL_KNOWN_FILE = Path("tests", "pyright_test.py")
1212

tests/pytype_test.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@
3535
from pytype import config as pytype_config, load_pytd # type: ignore[import]
3636
from pytype.imports import typeshed # type: ignore[import]
3737

38-
from _metadata import read_dependencies
39-
from _utils import SupportedVersionsDict, parse_stdlib_versions_file, supported_versions_for_module
38+
from ts_utils.metadata import read_dependencies
39+
from ts_utils.utils import SupportedVersionsDict, parse_stdlib_versions_file, supported_versions_for_module
4040

4141
TYPESHED_SUBDIRS = ["stdlib", "stubs"]
4242
TYPESHED_HOME = "TYPESHED_HOME"

tests/regr_test.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
from pathlib import Path
2222
from typing_extensions import TypeAlias
2323

24-
from _metadata import get_recursive_requirements, read_metadata
25-
from _utils import (
24+
from ts_utils.metadata import get_recursive_requirements, read_metadata
25+
from ts_utils.utils import (
2626
PYTHON_VERSION,
2727
TEST_CASES_DIR,
2828
DistributionTests,

tests/runtests.py

+1-10
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,8 @@
99
import sys
1010
from importlib.util import find_spec
1111
from pathlib import Path
12-
from typing import Any
13-
14-
from _utils import TEST_CASES_DIR, test_cases_path
15-
16-
try:
17-
from termcolor import colored # pyright: ignore[reportAssignmentType]
18-
except ImportError:
19-
20-
def colored(text: str, color: str | None = None, **kwargs: Any) -> str: # type: ignore[misc]
21-
return text
2212

13+
from ts_utils.utils import TEST_CASES_DIR, colored, test_cases_path
2314

2415
_STRICTER_CONFIG_FILE = "pyrightconfig.stricter.json"
2516
_TESTCASES_CONFIG_FILE = "pyrightconfig.testcases.json"

tests/stubtest_stdlib.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import sys
1414
from pathlib import Path
1515

16-
from _utils import allowlist_stubtest_arguments, allowlists_path
16+
from ts_utils.utils import allowlist_stubtest_arguments, allowlists_path
1717

1818

1919
def run_stubtest(typeshed_dir: Path) -> int:

tests/stubtest_third_party.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
from textwrap import dedent
1414
from typing import NoReturn
1515

16-
from _metadata import NoSuchStubError, get_recursive_requirements, read_metadata
17-
from _utils import (
16+
from ts_utils.metadata import NoSuchStubError, get_recursive_requirements, read_metadata
17+
from ts_utils.utils import (
1818
PYTHON_VERSION,
1919
allowlist_stubtest_arguments,
2020
allowlists_path,

tests/typecheck_typeshed.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from itertools import product
1010
from typing_extensions import TypeAlias
1111

12-
from _utils import colored, print_error
12+
from ts_utils.utils import colored, print_error
1313

1414
ReturnCode: TypeAlias = int
1515

0 commit comments

Comments
 (0)