5
5
import sysconfig
6
6
import warnings
7
7
import platform
8
+ import rebuildpython
8
9
9
10
import __np__
10
11
21
22
del sys .path [0 ]
22
23
sys .modules ["pip" ] = _pip
23
24
24
- try :
25
- import pip ._internal .pyproject
26
-
27
- def load_pyproject_toml (use_pep517 , pyproject_toml , setup_py , req_name ):
28
- return None
29
-
30
- pip ._internal .pyproject .load_pyproject_toml = load_pyproject_toml
31
- except :
32
- pass
33
-
34
- import pip ._internal .req .req_install
35
-
36
25
37
26
def urlretrieve (url , output_filename ):
38
27
local_filename = __np__ .download_file (url , os .path .dirname (output_filename ))
@@ -261,127 +250,99 @@ def install_dependency(name):
261
250
f .write (package_index ["version" ])
262
251
263
252
264
- _InstallRequirement = pip ._internal .req .req_install .InstallRequirement
265
-
253
+ from pip ._internal .req .req_install import InstallRequirement
254
+ from typing import Iterable , List , Optional , Tuple
255
+ import pip ._internal .wheel_builder
256
+ _orig_build_one_inside_env = pip ._internal .wheel_builder ._build_one_inside_env
257
+
258
+ def _build_one_inside_env (
259
+ req : InstallRequirement ,
260
+ output_dir : str ,
261
+ build_options : List [str ],
262
+ global_options : List [str ],
263
+ editable : bool ,
264
+ ) -> Optional [str ]:
265
+ fallback = False
266
+ if req .name == "setuptools" :
267
+ raise NotImplementedError ("setuptools not yet supported" )
268
+ try :
269
+ package_index = getPackageJson ("packages" , req .name )
270
+ except __np__ .NoSuchURL :
271
+ fallback = True
272
+ except :
273
+ if req .name == "certifi" :
274
+ fallback = True
275
+ else :
276
+ throw
266
277
267
- class InstallRequirement (_InstallRequirement ):
268
- def install (
269
- self ,
270
- install_options ,
271
- global_options = None ,
272
- root = None ,
273
- home = None ,
274
- prefix = None ,
275
- warn_script_location = True ,
276
- use_user_site = False ,
277
- pycompile = True ,
278
- ):
279
- fallback = False
278
+ if fallback or not req .source_dir :
279
+ __np__ .my_print ("FALLBACK to standard install for %s" % req .name )
280
280
281
- try :
282
- package_index = getPackageJson ("packages" , self .name )
283
- except __np__ .NoSuchURL :
284
- fallback = True
285
- except :
286
- if self .name == "certifi" :
287
- fallback = True
288
- else :
289
- throw
290
-
291
- if fallback or not self .source_dir :
292
- __np__ .my_print ("FALLBACK to standard install for %s" % self .name )
293
-
294
- return _InstallRequirement .install (
295
- self ,
296
- install_options ,
297
- global_options ,
298
- root ,
299
- home ,
300
- prefix ,
301
- warn_script_location ,
302
- use_user_site ,
303
- pycompile ,
304
- )
281
+ return _orig_build_one_inside_env (req , output_dir , build_options , global_options , editable )
305
282
306
- matched_source = None
307
- for source in package_index ["scripts" ]:
308
- for key , value_glob in source ["metadata" ].items ():
309
- if not fnmatch .fnmatch (self .metadata [key ], value_glob ):
310
- matched_metadata = False
311
- break
312
- else :
313
- matched_metadata = True
314
-
315
- if matched_metadata :
316
- matched_source = source
283
+ matched_source = None
284
+ for source in package_index ["scripts" ]:
285
+ for key , value_glob in source ["metadata" ].items ():
286
+ if not fnmatch .fnmatch (req .metadata [key ], value_glob ):
287
+ matched_metadata = False
317
288
break
289
+ else :
290
+ matched_metadata = True
318
291
319
- install_temp_dir = os .path .dirname (self .source_dir )
292
+ if matched_metadata :
293
+ matched_source = source
294
+ break
320
295
321
- if "build_tools" in matched_source :
322
- for dep in matched_source ["build_tools" ]:
323
- install_build_tool (dep )
296
+ install_temp_dir = os .path .dirname (req .source_dir )
324
297
325
- if "dependencies " in matched_source :
326
- for dep in matched_source ["dependencies " ]:
327
- install_dependency (dep )
298
+ if "build_tools " in matched_source :
299
+ for dep in matched_source ["build_tools " ]:
300
+ install_build_tool (dep )
328
301
329
- for file in matched_source ["files" ]:
330
- package_dir_url = getPackageUrl ("packages" , self .name )
331
- urlretrieve (
332
- "{package_dir_url}/{file}" .format (** locals ()),
333
- os .path .join (install_temp_dir , file ),
334
- )
335
-
336
- build_script_module_name = getBuildScriptName (install_temp_dir , self .name )
302
+ if "dependencies" in matched_source :
303
+ for dep in matched_source ["dependencies" ]:
304
+ install_dependency (dep )
337
305
338
- initcwd = os . getcwd ()
339
- initenviron = dict ( os . environ )
340
- build_script_module = importFileAsModule (
341
- build_script_module_name ,
342
- os .path .join (install_temp_dir , matched_source [ "build_script" ] ),
306
+ for file in matched_source [ "files" ]:
307
+ package_dir_url = getPackageUrl ( "packages" , req . name )
308
+ urlretrieve (
309
+ "{package_dir_url}/{file}" . format ( ** locals ()) ,
310
+ os .path .join (install_temp_dir , file ),
343
311
)
344
312
345
- static_pattern = matched_source .get ("static_pattern" )
346
- if static_pattern is None and os .name == "nt" :
347
- static_pattern = "*"
313
+ build_script_module_name = getBuildScriptName (install_temp_dir , req .name )
348
314
349
- # Put to empty, to avoid need to remove it and for easier manual usage.
350
- os .environ ["NUITKA_PYTHON_STATIC_PATTERN" ] = static_pattern or ""
315
+ initcwd = os .getcwd ()
316
+ initenviron = dict (os .environ )
317
+ build_script_module = importFileAsModule (
318
+ build_script_module_name ,
319
+ os .path .join (install_temp_dir , matched_source ["build_script" ]),
320
+ )
351
321
352
- try :
353
- result = build_script_module .run (install_temp_dir , self .source_dir )
354
- finally :
355
- if build_script_module_name in sys .modules :
356
- del sys .modules [build_script_module_name ]
357
- try :
358
- del build_script_module
359
- except NameError :
360
- pass
361
- os .chdir (initcwd )
362
- os .environ .clear ()
363
- os .environ .update (initenviron )
322
+ static_pattern = matched_source .get ("static_pattern" )
323
+ if static_pattern is None and os .name == "nt" :
324
+ static_pattern = "*"
364
325
365
- if result :
366
- _InstallRequirement .install (
367
- self ,
368
- install_options ,
369
- global_options ,
370
- root ,
371
- home ,
372
- prefix ,
373
- warn_script_location ,
374
- use_user_site ,
375
- pycompile ,
376
- )
326
+ # Put to empty, to avoid need to remove it and for easier manual usage.
327
+ os .environ ["NUITKA_PYTHON_STATIC_PATTERN" ] = static_pattern or ""
377
328
378
- if not int (os .environ .get ("NUITKA_PYTHON_MANUAL_REBUILD" , "0" )):
379
- import rebuildpython
329
+ try :
330
+ result = build_script_module .run (install_temp_dir , req .source_dir )
331
+ finally :
332
+ if build_script_module_name in sys .modules :
333
+ del sys .modules [build_script_module_name ]
334
+ try :
335
+ del build_script_module
336
+ except NameError :
337
+ pass
338
+ os .chdir (initcwd )
339
+ os .environ .clear ()
340
+ os .environ .update (initenviron )
380
341
381
- rebuildpython . run_rebuild ()
342
+ return result
382
343
383
344
384
- pip ._internal .req . req_install . InstallRequirement = InstallRequirement
345
+ pip ._internal .wheel_builder . _build_one_inside_env = _build_one_inside_env
385
346
386
347
387
348
import pip ._internal .index .package_finder
@@ -391,7 +352,7 @@ def install(
391
352
392
353
_PackageFinder = pip ._internal .index .package_finder .PackageFinder
393
354
394
-
355
+ """
395
356
def build_stub(
396
357
requirements, # type: Iterable[InstallRequirement]
397
358
wheel_cache, # type: WheelCache
@@ -403,8 +364,8 @@ def build_stub(
403
364
r.use_pep517 = False
404
365
return [], requirements
405
366
406
-
407
367
wheel_builder.build = build_stub
368
+ """
408
369
409
370
410
371
class PackageFinder (_PackageFinder ):
@@ -430,6 +391,34 @@ def find_all_candidates(self, project_name):
430
391
431
392
pip ._internal .index .package_finder .PackageFinder = PackageFinder
432
393
394
+ my_path = os .path .abspath (__file__ )
395
+
396
+ def get_runnable_pip () -> str :
397
+ return my_path
398
+
399
+ import pip ._internal .build_env
400
+ pip ._internal .build_env .get_runnable_pip = get_runnable_pip
401
+
402
+
403
+ import pip ._internal .req .req_install
404
+ orig_install = pip ._internal .req .req_install .InstallRequirement .install
405
+
406
+ def install (
407
+ self ,
408
+ global_options = None ,
409
+ root = None ,
410
+ home = None ,
411
+ prefix = None ,
412
+ warn_script_location = True ,
413
+ use_user_site = False ,
414
+ pycompile = True ,
415
+ ):
416
+ orig_install (self , global_options , root , home , prefix , warn_script_location , use_user_site , pycompile )
417
+
418
+ rebuildpython .run_rebuild ()
419
+
420
+ pip ._internal .req .req_install .InstallRequirement .install = install
421
+
433
422
434
423
def main ():
435
424
# Work around the error reported in #9540, pending a proper fix.
0 commit comments