3
3
# Script initially imported from:
4
4
# https://github.com/FFY00/python-instrospection/blob/main/python_introspection/scripts/generate-build-details.py
5
5
6
+ from __future__ import annotations
7
+
6
8
import argparse
7
9
import collections
8
10
import importlib .machinery
11
13
import sys
12
14
import sysconfig
13
15
16
+ TYPE_CHECKING = False
17
+ if TYPE_CHECKING :
18
+ from sys import _version_info
19
+ from typing import Any
20
+
14
21
15
- def version_info_to_dict (obj ): # (object ) -> dict[str, Any]
22
+ def version_info_to_dict (obj : _version_info ) -> dict [str , Any ]:
16
23
field_names = ('major' , 'minor' , 'micro' , 'releaselevel' , 'serial' )
17
24
return {field : getattr (obj , field ) for field in field_names }
18
25
19
26
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 ]:
21
28
for part in key .split ('.' ):
22
29
container = container [part ]
23
30
return container
24
31
25
32
26
- def generate_data (schema_version ) :
33
+ def generate_data (schema_version : str ) -> collections . defaultdict [ str , Any ] :
27
34
"""Generate the build-details.json data (PEP 739).
28
35
29
36
:param schema_version: The schema version of the data we want to generate.
@@ -32,7 +39,9 @@ def generate_data(schema_version):
32
39
if schema_version != '1.0' :
33
40
raise ValueError (f'Unsupported schema_version: { schema_version } ' )
34
41
35
- data = collections .defaultdict (lambda : collections .defaultdict (dict ))
42
+ data : collections .defaultdict [str , Any ] = collections .defaultdict (
43
+ lambda : collections .defaultdict (dict ),
44
+ )
36
45
37
46
data ['schema_version' ] = schema_version
38
47
@@ -122,7 +131,7 @@ def generate_data(schema_version):
122
131
return data
123
132
124
133
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 :
126
135
# Make base_prefix relative to the config_path directory
127
136
if config_path :
128
137
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)
152
161
container [child ] = new_path
153
162
154
163
155
- def main (): # () -> None
164
+ def main () -> None :
156
165
parser = argparse .ArgumentParser (exit_on_error = False )
157
166
parser .add_argument ('location' )
158
167
parser .add_argument (
0 commit comments