mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
[3.14] gh-133403: Check Tools/build/generate-build-details.py
with mypy (GH-133735) (#133764)
gh-133403: Check `Tools/build/generate-build-details.py` with mypy (GH-133735)
(cherry picked from commit cd2f234ad2
)
Co-authored-by: sobolevn <mail@sobolevn.me>
This commit is contained in:
parent
5dddedf327
commit
bd6aad0ec4
3 changed files with 16 additions and 6 deletions
1
.github/workflows/mypy.yml
vendored
1
.github/workflows/mypy.yml
vendored
|
@ -15,6 +15,7 @@ on:
|
|||
- "Misc/mypy/**"
|
||||
- "Tools/build/compute-changes.py"
|
||||
- "Tools/build/generate_sbom.py"
|
||||
- "Tools/build/generate-build-details.py"
|
||||
- "Tools/build/verify_ensurepip_wheels.py"
|
||||
- "Tools/build/update_file.py"
|
||||
- "Tools/cases_generator/**"
|
||||
|
|
|
@ -3,6 +3,8 @@
|
|||
# Script initially imported from:
|
||||
# https://github.com/FFY00/python-instrospection/blob/main/python_introspection/scripts/generate-build-details.py
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
import collections
|
||||
import importlib.machinery
|
||||
|
@ -11,19 +13,23 @@ import os
|
|||
import sys
|
||||
import sysconfig
|
||||
|
||||
TYPE_CHECKING = False
|
||||
if TYPE_CHECKING:
|
||||
from typing import Any
|
||||
|
||||
def version_info_to_dict(obj): # (object) -> dict[str, Any]
|
||||
|
||||
def version_info_to_dict(obj: sys._version_info) -> dict[str, Any]:
|
||||
field_names = ('major', 'minor', 'micro', 'releaselevel', 'serial')
|
||||
return {field: getattr(obj, field) for field in field_names}
|
||||
|
||||
|
||||
def get_dict_key(container, key): # (dict[str, Any], str) -> dict[str, Any]
|
||||
def get_dict_key(container: dict[str, Any], key: str) -> dict[str, Any]:
|
||||
for part in key.split('.'):
|
||||
container = container[part]
|
||||
return container
|
||||
|
||||
|
||||
def generate_data(schema_version):
|
||||
def generate_data(schema_version: str) -> collections.defaultdict[str, Any]:
|
||||
"""Generate the build-details.json data (PEP 739).
|
||||
|
||||
:param schema_version: The schema version of the data we want to generate.
|
||||
|
@ -32,7 +38,9 @@ def generate_data(schema_version):
|
|||
if schema_version != '1.0':
|
||||
raise ValueError(f'Unsupported schema_version: {schema_version}')
|
||||
|
||||
data = collections.defaultdict(lambda: collections.defaultdict(dict))
|
||||
data: collections.defaultdict[str, Any] = collections.defaultdict(
|
||||
lambda: collections.defaultdict(dict),
|
||||
)
|
||||
|
||||
data['schema_version'] = schema_version
|
||||
|
||||
|
@ -122,7 +130,7 @@ def generate_data(schema_version):
|
|||
return data
|
||||
|
||||
|
||||
def make_paths_relative(data, config_path=None): # (dict[str, Any], str | None) -> None
|
||||
def make_paths_relative(data: dict[str, Any], config_path: str | None = None) -> None:
|
||||
# Make base_prefix relative to the config_path directory
|
||||
if config_path:
|
||||
data['base_prefix'] = os.path.relpath(data['base_prefix'], os.path.dirname(config_path))
|
||||
|
@ -152,7 +160,7 @@ def make_paths_relative(data, config_path=None): # (dict[str, Any], str | None)
|
|||
container[child] = new_path
|
||||
|
||||
|
||||
def main(): # () -> None
|
||||
def main() -> None:
|
||||
parser = argparse.ArgumentParser(exit_on_error=False)
|
||||
parser.add_argument('location')
|
||||
parser.add_argument(
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
# .github/workflows/mypy.yml
|
||||
files =
|
||||
Tools/build/compute-changes.py,
|
||||
Tools/build/generate-build-details.py,
|
||||
Tools/build/generate_sbom.py,
|
||||
Tools/build/verify_ensurepip_wheels.py,
|
||||
Tools/build/update_file.py
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue