Skip to content

Commit

Permalink
Move common utility functions to a common library (#12773)
Browse files Browse the repository at this point in the history
  • Loading branch information
srittau authored Oct 14, 2024
1 parent 407eeaa commit 1fa4986
Show file tree
Hide file tree
Showing 21 changed files with 31 additions and 31 deletions.
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,11 @@ __pycache__/
# Distribution / packaging
.Python
/env/
/build/
/lib/build/
/develop-eggs/
/dist/
/downloads/
/eggs/
/lib/
/lib64/
/parts/
/sdist/
Expand Down
1 change: 1 addition & 0 deletions lib/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Utilities for typeshed infrastructure scripts.
1 change: 1 addition & 0 deletions lib/ts_utils/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Utilities for typeshed infrastructure scripts."""
2 changes: 1 addition & 1 deletion tests/_metadata.py → lib/ts_utils/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from packaging.specifiers import Specifier
from packaging.version import Version

from _utils import cache
from .utils import cache

__all__ = [
"NoSuchStubError",
Expand Down
Empty file added lib/ts_utils/py.typed
Empty file.
File renamed without changes.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ extra-standard-library = [
"pyexpat",
"zoneinfo",
]
known-first-party = ["_metadata", "_utils"]
known-first-party = ["ts_utils", "_utils"]

[tool.typeshed]
oldest_supported_python = "3.8"
4 changes: 4 additions & 0 deletions pyrightconfig.scripts_and_tests.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@
"$schema": "https://raw.githubusercontent.com/microsoft/pyright/main/packages/vscode-pyright/schemas/pyrightconfig.schema.json",
"typeshedPath": ".",
"include": [
"lib",
"scripts",
"tests",
],
"extraPaths": [
"lib",
],
"typeCheckingMode": "strict",
// More of a lint. Unwanted for typeshed's own code.
"reportImplicitStringConcatenation": "none",
Expand Down
3 changes: 3 additions & 0 deletions requirements-tests.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,6 @@ tomli==2.0.2
tomlkit==0.13.2
typing_extensions>=4.12.0rc1
uv==0.4.18

# Utilities for typeshed infrastructure scripts.
ts_utils @ file:lib
2 changes: 1 addition & 1 deletion scripts/stubsabot.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ async def get_github_repo_info(session: aiohttp.ClientSession, stub_info: StubIn
Else, return None.
"""
if stub_info.upstream_repository:
# We have various sanity checks for the upstream_repository field in tests/_metadata.py,
# We have various sanity checks for the upstream_repository field in ts_utils.metadata,
# so no need to repeat all of them here
split_url = urllib.parse.urlsplit(stub_info.upstream_repository)
if split_url.netloc == "github.com":
Expand Down
4 changes: 2 additions & 2 deletions tests/check_typeshed_structure.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
import sys
from pathlib import Path

from _metadata import read_metadata
from _utils import (
from ts_utils.metadata import read_metadata
from ts_utils.utils import (
REQS_FILE,
STDLIB_PATH,
TEST_CASES_DIR,
Expand Down
2 changes: 1 addition & 1 deletion tests/get_external_stub_requirements.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

from packaging.requirements import Requirement

from _metadata import read_dependencies
from ts_utils.metadata import read_dependencies

distributions = sys.argv[1:]
if not distributions:
Expand Down
3 changes: 2 additions & 1 deletion tests/get_stubtest_system_requirements.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#!/usr/bin/env python3

import os
import sys

from _metadata import read_stubtest_settings
from ts_utils.metadata import read_stubtest_settings

platform = sys.platform
distributions = sys.argv[1:]
Expand Down
6 changes: 3 additions & 3 deletions tests/mypy_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
import tomli
from packaging.requirements import Requirement

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

# TODO: This could be added to _metadata.py, but is currently unused
# TODO: This could be added to ts_utils.metadata, but is currently unused
mypy_tests_conf: dict[str, dict[str, Any]] = data.get("mypy-tests", {})
if not mypy_tests_conf:
return
Expand Down
2 changes: 1 addition & 1 deletion tests/pyright_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import sys
from pathlib import Path

from _utils import parse_requirements, print_command
from ts_utils.utils import parse_requirements, print_command

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

Expand Down
4 changes: 2 additions & 2 deletions tests/pytype_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@
from pytype import config as pytype_config, load_pytd # type: ignore[import]
from pytype.imports import typeshed # type: ignore[import]

from _metadata import read_dependencies
from _utils import SupportedVersionsDict, parse_stdlib_versions_file, supported_versions_for_module
from ts_utils.metadata import read_dependencies
from ts_utils.utils import SupportedVersionsDict, parse_stdlib_versions_file, supported_versions_for_module

TYPESHED_SUBDIRS = ["stdlib", "stubs"]
TYPESHED_HOME = "TYPESHED_HOME"
Expand Down
4 changes: 2 additions & 2 deletions tests/regr_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
from pathlib import Path
from typing_extensions import TypeAlias

from _metadata import get_recursive_requirements, read_metadata
from _utils import (
from ts_utils.metadata import get_recursive_requirements, read_metadata
from ts_utils.utils import (
PYTHON_VERSION,
TEST_CASES_DIR,
DistributionTests,
Expand Down
11 changes: 1 addition & 10 deletions tests/runtests.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,8 @@
import sys
from importlib.util import find_spec
from pathlib import Path
from typing import Any

from _utils import TEST_CASES_DIR, test_cases_path

try:
from termcolor import colored # pyright: ignore[reportAssignmentType]
except ImportError:

def colored(text: str, color: str | None = None, **kwargs: Any) -> str: # type: ignore[misc]
return text

from ts_utils.utils import TEST_CASES_DIR, colored, test_cases_path

_STRICTER_CONFIG_FILE = "pyrightconfig.stricter.json"
_TESTCASES_CONFIG_FILE = "pyrightconfig.testcases.json"
Expand Down
2 changes: 1 addition & 1 deletion tests/stubtest_stdlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import sys
from pathlib import Path

from _utils import allowlist_stubtest_arguments, allowlists_path
from ts_utils.utils import allowlist_stubtest_arguments, allowlists_path


def run_stubtest(typeshed_dir: Path) -> int:
Expand Down
4 changes: 2 additions & 2 deletions tests/stubtest_third_party.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
from textwrap import dedent
from typing import NoReturn

from _metadata import NoSuchStubError, get_recursive_requirements, read_metadata
from _utils import (
from ts_utils.metadata import NoSuchStubError, get_recursive_requirements, read_metadata
from ts_utils.utils import (
PYTHON_VERSION,
allowlist_stubtest_arguments,
allowlists_path,
Expand Down
2 changes: 1 addition & 1 deletion tests/typecheck_typeshed.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from itertools import product
from typing_extensions import TypeAlias

from _utils import colored, print_error
from ts_utils.utils import colored, print_error

ReturnCode: TypeAlias = int

Expand Down

0 comments on commit 1fa4986

Please sign in to comment.