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 typing import Any
19+
1420
15- def version_info_to_dict (obj ): # (object ) -> dict[str, Any]
21+ def version_info_to_dict (obj : sys . _version_info ) -> dict [str , Any ]:
1622 field_names = ('major' , 'minor' , 'micro' , 'releaselevel' , 'serial' )
1723 return {field : getattr (obj , field ) for field in field_names }
1824
1925
20- def get_dict_key (container , key ): # ( dict[str, Any], str) -> dict[str, Any]
26+ def get_dict_key (container : dict [str , Any ], key : str ) -> dict [str , Any ]:
2127 for part in key .split ('.' ):
2228 container = container [part ]
2329 return container
2430
2531
26- def generate_data (schema_version ) :
32+ def generate_data (schema_version : str ) -> collections . defaultdict [ str , Any ] :
2733 """Generate the build-details.json data (PEP 739).
2834
2935 :param schema_version: The schema version of the data we want to generate.
@@ -32,7 +38,9 @@ def generate_data(schema_version):
3238 if schema_version != '1.0' :
3339 raise ValueError (f'Unsupported schema_version: { schema_version } ' )
3440
35- data = collections .defaultdict (lambda : collections .defaultdict (dict ))
41+ data : collections .defaultdict [str , Any ] = collections .defaultdict (
42+ lambda : collections .defaultdict (dict ),
43+ )
3644
3745 data ['schema_version' ] = schema_version
3846
@@ -122,7 +130,7 @@ def generate_data(schema_version):
122130 return data
123131
124132
125- def make_paths_relative (data , config_path = None ): # ( dict[str, Any], str | None) -> None
133+ def make_paths_relative (data : dict [str , Any ], config_path : str | None = None ) -> None :
126134 # Make base_prefix relative to the config_path directory
127135 if config_path :
128136 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)
152160 container [child ] = new_path
153161
154162
155- def main (): # () -> None
163+ def main () -> None :
156164 parser = argparse .ArgumentParser (exit_on_error = False )
157165 parser .add_argument ('location' )
158166 parser .add_argument (
0 commit comments