9
9
10
10
from installer import install as _install
11
11
from installer ._core import _process_WHEEL_file
12
- from installer .destinations import SchemeDictionaryDestination
12
+ from installer .destinations import SchemeDictionaryDestination , WheelDestination
13
13
from installer .exceptions import InvalidWheelSource
14
14
from installer .records import RecordEntry
15
15
from installer .sources import WheelContentElement , WheelSource
@@ -97,12 +97,14 @@ def __init__(
97
97
self ,
98
98
* args : Any ,
99
99
link_method : LinkMethod = "copy" ,
100
+ rename_pth : bool = False ,
100
101
** kwargs : Any ,
101
102
) -> None :
102
103
super ().__init__ (* args , ** kwargs )
103
104
self .link_method = link_method
105
+ self .rename_pth = rename_pth
104
106
105
- def write_to_fs (self , scheme : Scheme , path : str | Path , stream : BinaryIO , is_executable : bool ) -> RecordEntry :
107
+ def write_to_fs (self , scheme : Scheme , path : str , stream : BinaryIO , is_executable : bool ) -> RecordEntry :
106
108
from installer .records import Hash
107
109
from installer .utils import copyfileobj_with_hashing , make_file_executable
108
110
@@ -112,6 +114,10 @@ def write_to_fs(self, scheme: Scheme, path: str | Path, stream: BinaryIO, is_exe
112
114
113
115
os .makedirs (os .path .dirname (target_path ), exist_ok = True )
114
116
117
+ if self .rename_pth and target_path .endswith (".pth" ) and "/" not in path :
118
+ # Postpone the creation of pth files since it may cause race condition
119
+ # when multiple packages are installed at the same time.
120
+ target_path += ".pdmtmp"
115
121
if self .link_method == "copy" or not hasattr (stream , "name" ):
116
122
with open (target_path , "wb" ) as f :
117
123
hash_ , size = copyfileobj_with_hashing (stream , f , self .hash_algorithm )
@@ -147,6 +153,7 @@ def install_package(
147
153
environment : BaseEnvironment ,
148
154
direct_url : dict [str , Any ] | None = None ,
149
155
install_links : bool = True ,
156
+ rename_pth : bool = False ,
150
157
) -> str :
151
158
"""Only create .pth files referring to the cached package.
152
159
If the cache doesn't exist, create one.
@@ -175,6 +182,7 @@ def install_package(
175
182
interpreter = interpreter ,
176
183
script_kind = script_kind ,
177
184
link_method = link_method ,
185
+ rename_pth = rename_pth ,
178
186
)
179
187
source = PackageWheelSource (package )
180
188
dist_info_dir = install (source , destination = destination , additional_metadata = additional_metadata )
@@ -184,7 +192,7 @@ def install_package(
184
192
185
193
186
194
def install (
187
- source : WheelSource , destination : InstallDestination , additional_metadata : dict [str , bytes ] | None = None
195
+ source : WheelSource , destination : WheelDestination , additional_metadata : dict [str , bytes ] | None = None
188
196
) -> str :
189
197
"""A lower level installation method that is copied from installer
190
198
but is controlled by extra parameters.
@@ -198,7 +206,7 @@ def install(
198
206
199
207
def install_wheel (wheel : str , environment : BaseEnvironment , direct_url : dict [str , Any ] | None = None ) -> str :
200
208
"""Install a wheel into the environment, return the .dist-info path"""
201
- destination = InstallDestination (
209
+ destination = SchemeDictionaryDestination (
202
210
scheme_dict = environment .get_paths (_get_dist_name (wheel )),
203
211
interpreter = str (environment .interpreter .executable ),
204
212
script_kind = environment .script_kind ,
0 commit comments