33# Script initially imported from:
44# https://github.com/FFY00/python-instrospection/blob/main/python_introspection/scripts/generate-build-details.py
55
6+ from __future__ import annotations
7+
68import argparse
79import collections
810import importlib .machinery
1113import sys
1214import sysconfig
1315
16+ TYPE_CHECKING = False
17+ if TYPE_CHECKING :
18+ from sys import _version_info
19+ from typing import Any
20+
1421
15- def version_info_to_dict (obj ): # (object ) -> dict[str, Any]
22+ def version_info_to_dict (obj : _version_info ) -> dict [str , Any ]:
1623 field_names = ('major' , 'minor' , 'micro' , 'releaselevel' , 'serial' )
1724 return {field : getattr (obj , field ) for field in field_names }
1825
1926
20- def get_dict_key (container , key ): # ( dict[str, Any], str) -> dict[str, Any]
27+ def get_dict_key (container : dict [str , Any ], key : str ) -> dict [str , Any ]:
2128 for part in key .split ('.' ):
2229 container = container [part ]
2330 return container
2431
2532
26- def generate_data (schema_version ) :
33+ def generate_data (schema_version : str ) -> collections . defaultdict [ str , Any ] :
2734 """Generate the build-details.json data (PEP 739).
2835
2936 :param schema_version: The schema version of the data we want to generate.
@@ -32,7 +39,9 @@ def generate_data(schema_version):
3239 if schema_version != '1.0' :
3340 raise ValueError (f'Unsupported schema_version: { schema_version } ' )
3441
35- data = collections .defaultdict (lambda : collections .defaultdict (dict ))
42+ data : collections .defaultdict [str , Any ] = collections .defaultdict (
43+ lambda : collections .defaultdict (dict ),
44+ )
3645
3746 data ['schema_version' ] = schema_version
3847
@@ -122,7 +131,7 @@ def generate_data(schema_version):
122131 return data
123132
124133
125- def make_paths_relative (data , config_path = None ): # ( dict[str, Any], str | None) -> None
134+ def make_paths_relative (data : dict [str , Any ], config_path : str | None = None ) -> None :
126135 # Make base_prefix relative to the config_path directory
127136 if config_path :
128137 data ['base_prefix' ] = os .path .relpath (data ['base_prefix' ], os .path .dirname (config_path ))
@@ -152,7 +161,7 @@ def make_paths_relative(data, config_path=None): # (dict[str, Any], str | None)
152161 container [child ] = new_path
153162
154163
155- def main (): # () -> None
164+ def main () -> None :
156165 parser = argparse .ArgumentParser (exit_on_error = False )
157166 parser .add_argument ('location' )
158167 parser .add_argument (
0 commit comments