4
4
from __future__ import annotations
5
5
6
6
import os
7
- import typing as t
8
7
from contextlib import contextmanager , nullcontext , suppress
9
8
from functools import partial
10
9
from pathlib import Path
11
10
from shutil import copytree
12
11
from sys import implementation as _system_implementation
13
12
from sys import stderr as _standard_error_stream
14
13
from tempfile import TemporaryDirectory
14
+ from typing import Dict , Iterator , List , Union
15
15
from warnings import warn as _warn_that
16
16
17
17
from setuptools .build_meta import build_sdist as _setuptools_build_sdist
55
55
'get_requires_for_build_wheel' ,
56
56
'prepare_metadata_for_build_wheel' ,
57
57
* (
58
- () if _setuptools_build_editable is None
58
+ () if _setuptools_build_editable is None # type: ignore[redundant-expr]
59
59
else (
60
60
'build_editable' ,
61
61
'get_requires_for_build_editable' ,
64
64
),
65
65
)
66
66
67
- _ConfigDict = t . Dict [str , t . Union [str , t . List [str ], None ]]
67
+ _ConfigDict = Dict [str , Union [str , List [str ], None ]]
68
68
69
69
70
70
CYTHON_TRACING_CONFIG_SETTING = 'with-cython-tracing'
86
86
"""A fallback for ``pure-python`` is not set."""
87
87
88
88
89
- def _is_truthy_setting_value (setting_value ) -> bool :
89
+ def _is_truthy_setting_value (setting_value : str ) -> bool :
90
90
truthy_values = {'' , None , 'true' , '1' , 'on' }
91
91
return setting_value .lower () in truthy_values
92
92
@@ -107,7 +107,7 @@ def _get_setting_value(
107
107
continue
108
108
109
109
with suppress (lookup_errors ): # type: ignore[arg-type]
110
- return _is_truthy_setting_value (src_mapping [src_key ]) # type: ignore[index]
110
+ return _is_truthy_setting_value (src_mapping [src_key ]) # type: ignore[arg-type, index]
111
111
112
112
return default
113
113
@@ -124,7 +124,7 @@ def _make_pure_python(config_settings: _ConfigDict | None = None) -> bool:
124
124
def _include_cython_line_tracing (
125
125
config_settings : _ConfigDict | None = None ,
126
126
* ,
127
- default = False ,
127
+ default : bool = False ,
128
128
) -> bool :
129
129
return _get_setting_value (
130
130
config_settings ,
@@ -135,60 +135,61 @@ def _include_cython_line_tracing(
135
135
136
136
137
137
@contextmanager
138
- def patched_distutils_cmd_install ():
138
+ def patched_distutils_cmd_install () -> Iterator [ None ] :
139
139
"""Make `install_lib` of `install` cmd always use `platlib`.
140
140
141
141
:yields: None
142
142
"""
143
143
# Without this, build_lib puts stuff under `*.data/purelib/` folder
144
144
orig_finalize = _distutils_install_cmd .finalize_options
145
145
146
- def new_finalize_options (self ) : # noqa: WPS430
146
+ def new_finalize_options (self : _distutils_install_cmd ) -> None : # noqa: WPS430
147
147
self .install_lib = self .install_platlib
148
148
orig_finalize (self )
149
149
150
- _distutils_install_cmd .finalize_options = new_finalize_options
150
+ _distutils_install_cmd .finalize_options = new_finalize_options # type: ignore[method-assign]
151
151
try :
152
152
yield
153
153
finally :
154
- _distutils_install_cmd .finalize_options = orig_finalize
154
+ _distutils_install_cmd .finalize_options = orig_finalize # type: ignore[method-assign]
155
155
156
156
157
157
@contextmanager
158
- def patched_dist_has_ext_modules ():
158
+ def patched_dist_has_ext_modules () -> Iterator [ None ] :
159
159
"""Make `has_ext_modules` of `Distribution` always return `True`.
160
160
161
161
:yields: None
162
162
"""
163
163
# Without this, build_lib puts stuff under `*.data/platlib/` folder
164
164
orig_func = _DistutilsDistribution .has_ext_modules
165
165
166
- _DistutilsDistribution .has_ext_modules = lambda * args , ** kwargs : True
166
+ _DistutilsDistribution .has_ext_modules = lambda * args , ** kwargs : True # type: ignore[method-assign]
167
167
try :
168
168
yield
169
169
finally :
170
- _DistutilsDistribution .has_ext_modules = orig_func
170
+ _DistutilsDistribution .has_ext_modules = orig_func # type: ignore[method-assign]
171
171
172
172
173
173
@contextmanager
174
- def patched_dist_get_long_description ():
174
+ def patched_dist_get_long_description () -> Iterator [ None ] :
175
175
"""Make `has_ext_modules` of `Distribution` always return `True`.
176
176
177
177
:yields: None
178
178
"""
179
179
# Without this, build_lib puts stuff under `*.data/platlib/` folder
180
180
_orig_func = _DistutilsDistributionMetadata .get_long_description
181
181
182
- def _get_sanitized_long_description (self ):
182
+ def _get_sanitized_long_description (self : _DistutilsDistributionMetadata ) -> str :
183
+ assert self .long_description is not None
183
184
return sanitize_rst_roles (self .long_description )
184
185
185
- _DistutilsDistributionMetadata .get_long_description = (
186
+ _DistutilsDistributionMetadata .get_long_description = ( # type: ignore[method-assign]
186
187
_get_sanitized_long_description
187
188
)
188
189
try :
189
190
yield
190
191
finally :
191
- _DistutilsDistributionMetadata .get_long_description = _orig_func
192
+ _DistutilsDistributionMetadata .get_long_description = _orig_func # type: ignore[method-assign]
192
193
193
194
194
195
def _exclude_dir_path (
@@ -215,7 +216,7 @@ def _exclude_dir_path(
215
216
216
217
217
218
@contextmanager
218
- def _in_temporary_directory (src_dir : Path ) -> t . Iterator [None ]:
219
+ def _in_temporary_directory (src_dir : Path ) -> Iterator [None ]:
219
220
with TemporaryDirectory (prefix = '.tmp-frozenlist-pep517-' ) as tmp_dir :
220
221
tmp_dir_path = Path (tmp_dir )
221
222
root_tmp_dir_path = tmp_dir_path .parent
@@ -238,7 +239,7 @@ def maybe_prebuild_c_extensions(
238
239
line_trace_cython_when_unset : bool = False ,
239
240
build_inplace : bool = False ,
240
241
config_settings : _ConfigDict | None = None ,
241
- ) -> t . Generator [None , t . Any , t . Any ]:
242
+ ) -> Iterator [None ]:
242
243
"""Pre-build C-extensions in a temporary directory, when needed.
243
244
244
245
This context manager also patches metadata, setuptools and distutils.
0 commit comments