1
1
"""Build Environment used for isolation during sdist building"""
2
2
3
+ from __future__ import annotations
4
+
3
5
import logging
4
6
import os
5
7
import pathlib
6
8
import site
7
9
import sys
8
10
import textwrap
9
11
from collections import OrderedDict
12
+ from collections .abc import Iterable
10
13
from types import TracebackType
11
- from typing import TYPE_CHECKING , Iterable , List , Optional , Set , Tuple , Type , Union
14
+ from typing import TYPE_CHECKING
12
15
13
16
from pip ._vendor .packaging .version import Version
14
17
27
30
logger = logging .getLogger (__name__ )
28
31
29
32
30
- def _dedup (a : str , b : str ) -> Union [ Tuple [ str ], Tuple [str , str ] ]:
33
+ def _dedup (a : str , b : str ) -> tuple [ str ] | tuple [str , str ]:
31
34
return (a , b ) if a != b else (a ,)
32
35
33
36
@@ -56,7 +59,7 @@ def get_runnable_pip() -> str:
56
59
return os .fsdecode (source / "__pip-runner__.py" )
57
60
58
61
59
- def _get_system_sitepackages () -> Set [str ]:
62
+ def _get_system_sitepackages () -> set [str ]:
60
63
"""Get system site packages
61
64
62
65
Usually from site.getsitepackages,
@@ -87,8 +90,8 @@ def __init__(self) -> None:
87
90
for name in ("normal" , "overlay" )
88
91
)
89
92
90
- self ._bin_dirs : List [str ] = []
91
- self ._lib_dirs : List [str ] = []
93
+ self ._bin_dirs : list [str ] = []
94
+ self ._lib_dirs : list [str ] = []
92
95
for prefix in reversed (list (self ._prefixes .values ())):
93
96
self ._bin_dirs .append (prefix .bin_dir )
94
97
self ._lib_dirs .extend (prefix .lib_dirs )
@@ -156,9 +159,9 @@ def __enter__(self) -> None:
156
159
157
160
def __exit__ (
158
161
self ,
159
- exc_type : Optional [ Type [ BaseException ]] ,
160
- exc_val : Optional [ BaseException ] ,
161
- exc_tb : Optional [ TracebackType ] ,
162
+ exc_type : type [ BaseException ] | None ,
163
+ exc_val : BaseException | None ,
164
+ exc_tb : TracebackType | None ,
162
165
) -> None :
163
166
for varname , old_value in self ._save_env .items ():
164
167
if old_value is None :
@@ -168,7 +171,7 @@ def __exit__(
168
171
169
172
def check_requirements (
170
173
self , reqs : Iterable [str ]
171
- ) -> Tuple [ Set [ Tuple [str , str ]], Set [str ]]:
174
+ ) -> tuple [ set [ tuple [str , str ]], set [str ]]:
172
175
"""Return 2 sets:
173
176
- conflicting requirements: set of (installed, wanted) reqs tuples
174
177
- missing requirements: set of reqs
@@ -202,7 +205,7 @@ def check_requirements(
202
205
203
206
def install_requirements (
204
207
self ,
205
- finder : " PackageFinder" ,
208
+ finder : PackageFinder ,
206
209
requirements : Iterable [str ],
207
210
prefix_as_string : str ,
208
211
* ,
@@ -224,13 +227,13 @@ def install_requirements(
224
227
@staticmethod
225
228
def _install_requirements (
226
229
pip_runnable : str ,
227
- finder : " PackageFinder" ,
230
+ finder : PackageFinder ,
228
231
requirements : Iterable [str ],
229
232
prefix : _Prefix ,
230
233
* ,
231
234
kind : str ,
232
235
) -> None :
233
- args : List [str ] = [
236
+ args : list [str ] = [
234
237
sys .executable ,
235
238
pip_runnable ,
236
239
"install" ,
@@ -305,9 +308,9 @@ def __enter__(self) -> None:
305
308
306
309
def __exit__ (
307
310
self ,
308
- exc_type : Optional [ Type [ BaseException ]] ,
309
- exc_val : Optional [ BaseException ] ,
310
- exc_tb : Optional [ TracebackType ] ,
311
+ exc_type : type [ BaseException ] | None ,
312
+ exc_val : BaseException | None ,
313
+ exc_tb : TracebackType | None ,
311
314
) -> None :
312
315
pass
313
316
@@ -316,7 +319,7 @@ def cleanup(self) -> None:
316
319
317
320
def install_requirements (
318
321
self ,
319
- finder : " PackageFinder" ,
322
+ finder : PackageFinder ,
320
323
requirements : Iterable [str ],
321
324
prefix_as_string : str ,
322
325
* ,
0 commit comments