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 typing import Any
19
+
14
20
15
- def version_info_to_dict (obj ): # (object ) -> dict[str, Any]
21
+ def version_info_to_dict (obj : sys . _version_info )-> dict [str ,Any ]:
16
22
field_names = ('major' ,'minor' ,'micro' ,'releaselevel' ,'serial' )
17
23
return {field :getattr (obj ,field )for field in field_names }
18
24
19
25
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 ]:
21
27
for part in key .split ('.' ):
22
28
container = container [part ]
23
29
return container
24
30
25
31
26
- def generate_data (schema_version ) :
32
+ def generate_data (schema_version : str ) -> collections . defaultdict [ str , Any ] :
27
33
"""Generate the build-details.json data (PEP 739).
28
34
29
35
:param schema_version: The schema version of the data we want to generate.
@@ -32,7 +38,9 @@ def generate_data(schema_version):
32
38
if schema_version != '1.0' :
33
39
raise ValueError (f'Unsupported schema_version:{ schema_version } ' )
34
40
35
- data = collections .defaultdict (lambda :collections .defaultdict (dict ))
41
+ data :collections .defaultdict [str ,Any ]= collections .defaultdict (
42
+ lambda :collections .defaultdict (dict ),
43
+ )
36
44
37
45
data ['schema_version' ]= schema_version
38
46
@@ -122,7 +130,7 @@ def generate_data(schema_version):
122
130
return data
123
131
124
132
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 :
126
134
# Make base_prefix relative to the config_path directory
127
135
if config_path :
128
136
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)
152
160
container [child ]= new_path
153
161
154
162
155
- def main (): # () -> None
163
+ def main ()-> None :
156
164
parser = argparse .ArgumentParser (exit_on_error = False )
157
165
parser .add_argument ('location' )
158
166
parser .add_argument (