9
9
from pip .exceptions import (InstallationError , BestVersionAlreadyInstalled ,
10
10
DistributionNotFound , PreviousBuildDirError )
11
11
from pip .index import Link
12
- from pip .locations import (
13
- PIP_DELETE_MARKER_FILENAME , write_delete_marker_file , build_prefix ,
14
- )
12
+ from pip .locations import (PIP_DELETE_MARKER_FILENAME , build_prefix ,
13
+ write_delete_marker_file )
15
14
from pip .log import logger
16
15
from pip .req .req_install import InstallRequirement
17
16
from pip .util import (display_path , rmtree , dist_in_usersite , call_subprocess ,
18
17
_make_build_dir )
19
18
from pip .vcs import vcs
19
+ from pip .wheel import wheel_ext
20
20
21
21
22
22
class Requirements (object ):
@@ -53,10 +53,12 @@ def __init__(self, build_dir, src_dir, download_dir, download_cache=None,
53
53
upgrade = False , ignore_installed = False , as_egg = False ,
54
54
target_dir = None , ignore_dependencies = False ,
55
55
force_reinstall = False , use_user_site = False , session = None ,
56
- pycompile = True ):
56
+ pycompile = True , wheel_download_dir = None ):
57
57
self .build_dir = build_dir
58
58
self .src_dir = src_dir
59
59
self .download_dir = download_dir
60
+ if download_cache :
61
+ download_cache = os .path .expanduser (download_cache )
60
62
self .download_cache = download_cache
61
63
self .upgrade = upgrade
62
64
self .ignore_installed = ignore_installed
@@ -74,6 +76,7 @@ def __init__(self, build_dir, src_dir, download_dir, download_cache=None,
74
76
self .target_dir = target_dir # set from --target option
75
77
self .session = session or PipSession ()
76
78
self .pycompile = pycompile
79
+ self .wheel_download_dir = wheel_download_dir
77
80
78
81
def __str__ (self ):
79
82
reqs = [req for req in self .requirements .values ()
@@ -209,6 +212,11 @@ def prepare_files(self, finder, force_root_egg_info=False, bundle=False):
209
212
install = True
210
213
best_installed = False
211
214
not_found = None
215
+
216
+ ###############################################
217
+ ## Search for archive to fulfill requirement ##
218
+ ###############################################
219
+
212
220
if not self .ignore_installed and not req_to_install .editable :
213
221
req_to_install .check_if_exists ()
214
222
if req_to_install .satisfied_by :
@@ -258,6 +266,11 @@ def prepare_files(self, finder, force_root_egg_info=False, bundle=False):
258
266
else :
259
267
logger .notify ('Downloading/unpacking %s' % req_to_install )
260
268
logger .indent += 2
269
+
270
+ ##################################
271
+ ## vcs update or unpack archive ##
272
+ ##################################
273
+
261
274
try :
262
275
is_bundle = False
263
276
is_wheel = False
@@ -323,9 +336,21 @@ def prepare_files(self, finder, force_root_egg_info=False, bundle=False):
323
336
assert url
324
337
if url :
325
338
try :
339
+
340
+ if (
341
+ url .filename .endswith (wheel_ext )
342
+ and self .wheel_download_dir
343
+ ):
344
+ # when doing 'pip wheel`
345
+ download_dir = self .wheel_download_dir
346
+ do_download = True
347
+ else :
348
+ download_dir = self .download_dir
349
+ do_download = self .is_download
326
350
self .unpack_url (
327
- url , location , self .is_download ,
328
- )
351
+ url , location , download_dir ,
352
+ do_download ,
353
+ )
329
354
except HTTPError as exc :
330
355
logger .fatal (
331
356
'Could not install requirement %s because '
@@ -340,7 +365,7 @@ def prepare_files(self, finder, force_root_egg_info=False, bundle=False):
340
365
unpack = False
341
366
if unpack :
342
367
is_bundle = req_to_install .is_bundle
343
- is_wheel = url and url .filename .endswith ('.whl' )
368
+ is_wheel = url and url .filename .endswith (wheel_ext )
344
369
if is_bundle :
345
370
req_to_install .move_bundle_files (
346
371
self .build_dir ,
@@ -356,6 +381,11 @@ def prepare_files(self, finder, force_root_egg_info=False, bundle=False):
356
381
req_to_install .run_egg_info ()
357
382
if url and url .scheme in vcs .all_schemes :
358
383
req_to_install .archive (self .download_dir )
384
+
385
+ ##############################
386
+ ## parse wheel dependencies ##
387
+ ##############################
388
+
359
389
elif is_wheel :
360
390
req_to_install .source_dir = location
361
391
req_to_install .url = url .url
@@ -413,6 +443,11 @@ def prepare_files(self, finder, force_root_egg_info=False, bundle=False):
413
443
req_to_install
414
444
)
415
445
install = False
446
+
447
+ ##############################
448
+ ## parse sdist dependencies ##
449
+ ##############################
450
+
416
451
if not (is_bundle or is_wheel ):
417
452
## FIXME: shouldn't be globally added:
418
453
finder .add_dependency_links (
@@ -503,29 +538,36 @@ def copy_to_build_dir(self, req_to_install):
503
538
call_subprocess (["python" , "%s/setup.py" % dest , "clean" ], cwd = dest ,
504
539
command_desc = 'python setup.py clean' )
505
540
506
- def unpack_url (self , link , location , only_download = False ):
507
- if only_download :
508
- loc = self .download_dir
509
- else :
510
- loc = location
541
+ def unpack_url (self , link , location , download_dir = None ,
542
+ only_download = False ):
543
+ if download_dir is None :
544
+ download_dir = self .download_dir
545
+
546
+ # non-editable vcs urls
511
547
if is_vcs_url (link ):
512
- return unpack_vcs_link (link , loc , only_download )
513
- # a local file:// index could have links with hashes
514
- elif not link .hash and is_file_url (link ):
515
- return unpack_file_url (link , loc )
548
+ if only_download :
549
+ loc = download_dir
550
+ else :
551
+ loc = location
552
+ unpack_vcs_link (link , loc , only_download )
553
+
554
+ # file urls
555
+ elif is_file_url (link ):
556
+ unpack_file_url (link , location , download_dir )
557
+ if only_download :
558
+ write_delete_marker_file (location )
559
+
560
+ # http urls
516
561
else :
517
- if self .download_cache :
518
- self .download_cache = os .path .expanduser (self .download_cache )
519
- retval = unpack_http_url (
562
+ unpack_http_url (
520
563
link ,
521
564
location ,
522
565
self .download_cache ,
523
- self . download_dir ,
566
+ download_dir ,
524
567
self .session ,
525
568
)
526
569
if only_download :
527
570
write_delete_marker_file (location )
528
- return retval
529
571
530
572
def install (self , install_options , global_options = (), * args , ** kwargs ):
531
573
"""
0 commit comments