12
12
from pipenv .utils .dependencies import (
13
13
expansive_install_req_from_line ,
14
14
get_lockfile_section_using_pipfile_category ,
15
+ install_req_from_pipfile ,
15
16
)
16
17
from pipenv .utils .indexes import get_source_list
17
18
from pipenv .utils .internet import download_file , is_valid_url
@@ -42,6 +43,7 @@ def do_install(
42
43
site_packages = None ,
43
44
extra_pip_args = None ,
44
45
categories = None ,
46
+ skip_lock = False ,
45
47
):
46
48
requirements_directory = fileutils .create_tracked_tempdir (
47
49
suffix = "-requirements" , prefix = "pipenv-"
@@ -70,7 +72,7 @@ def do_install(
70
72
if not project .pipfile_exists and not (package_args or dev ):
71
73
if not (ignore_pipfile or deploy ):
72
74
raise exceptions .PipfileNotFound (project .path_to ("Pipfile" ))
73
- elif ignore_pipfile and not project .lockfile_exists :
75
+ elif (( skip_lock and deploy ) or ignore_pipfile ) and not project .lockfile_exists :
74
76
raise exceptions .LockfileNotFound (project .path_to ("Pipfile.lock" ))
75
77
# Load the --pre settings from the Pipfile.
76
78
if not pre :
@@ -171,6 +173,7 @@ def do_install(
171
173
pypi_mirror = pypi_mirror ,
172
174
extra_pip_args = extra_pip_args ,
173
175
categories = categories ,
176
+ skip_lock = skip_lock ,
174
177
)
175
178
176
179
# This is for if the user passed in dependencies, then we want to make sure we
@@ -188,6 +191,7 @@ def do_install(
188
191
pypi_mirror = pypi_mirror ,
189
192
extra_pip_args = extra_pip_args ,
190
193
categories = categories ,
194
+ skip_lock = skip_lock ,
191
195
)
192
196
193
197
for pkg_line in pkg_list :
@@ -284,6 +288,7 @@ def do_install(
284
288
pypi_mirror = pypi_mirror ,
285
289
extra_pip_args = extra_pip_args ,
286
290
categories = categories ,
291
+ skip_lock = skip_lock ,
287
292
)
288
293
except Exception as e :
289
294
# If we fail to install, remove the package from the Pipfile.
@@ -358,6 +363,7 @@ def do_install_dependencies(
358
363
pypi_mirror = None ,
359
364
extra_pip_args = None ,
360
365
categories = None ,
366
+ skip_lock = False ,
361
367
):
362
368
"""
363
369
Executes the installation functionality.
@@ -373,17 +379,39 @@ def do_install_dependencies(
373
379
categories = ["packages" ]
374
380
375
381
for category in categories :
376
- lockfile = project .get_or_create_lockfile (categories = categories )
377
- if not bare :
378
- console .print (
379
- f"Installing dependencies from Pipfile.lock "
380
- f"({ lockfile ['_meta' ].get ('hash' , {}).get ('sha256' )[- 6 :]} )..." ,
381
- style = "bold" ,
382
- )
382
+ # Load the lockfile if it exists, or if dev_only is being used.
383
+ lockfile = None
384
+ pipfile = None
385
+ if skip_lock :
386
+ ignore_hashes = True
387
+ if not bare :
388
+ console .print ("Installing dependencies from Pipfile..." , style = "bold" )
389
+ pipfile = project .get_pipfile_section (category )
390
+ else :
391
+ lockfile = project .get_or_create_lockfile (categories = categories )
392
+ if not bare :
393
+ console .print (
394
+ f"Installing dependencies from Pipfile.lock "
395
+ f"({ lockfile ['_meta' ].get ('hash' , {}).get ('sha256' )[- 6 :]} )..." ,
396
+ style = "bold" ,
397
+ )
383
398
dev = dev or dev_only
384
- deps_list = list (
385
- lockfile .get_requirements (dev = dev , only = dev_only , categories = [category ])
386
- )
399
+ if skip_lock :
400
+ deps_list = []
401
+ for req_name , pipfile_entry in pipfile .items ():
402
+ install_req , markers , req_line = install_req_from_pipfile (
403
+ req_name , pipfile_entry
404
+ )
405
+ deps_list .append (
406
+ (
407
+ install_req ,
408
+ req_line ,
409
+ )
410
+ )
411
+ else :
412
+ deps_list = list (
413
+ lockfile .get_requirements (dev = dev , only = dev_only , categories = [category ])
414
+ )
387
415
editable_or_vcs_deps = [
388
416
(dep , pip_line ) for dep , pip_line in deps_list if (dep .link and dep .editable )
389
417
]
@@ -394,15 +422,18 @@ def do_install_dependencies(
394
422
]
395
423
396
424
install_kwargs = {
397
- "no_deps" : True ,
425
+ "no_deps" : not skip_lock ,
398
426
"ignore_hashes" : ignore_hashes ,
399
427
"allow_global" : allow_global ,
400
428
"pypi_mirror" : pypi_mirror ,
401
429
"sequential_deps" : editable_or_vcs_deps ,
402
430
"extra_pip_args" : extra_pip_args ,
403
431
}
404
- lockfile_category = get_lockfile_section_using_pipfile_category (category )
405
- lockfile_section = lockfile [lockfile_category ]
432
+ if skip_lock :
433
+ lockfile_section = pipfile
434
+ else :
435
+ lockfile_category = get_lockfile_section_using_pipfile_category (category )
436
+ lockfile_section = lockfile [lockfile_category ]
406
437
batch_install (
407
438
project ,
408
439
normal_deps ,
@@ -499,8 +530,10 @@ def batch_install(
499
530
deps_by_index = defaultdict (list )
500
531
for dependency , pip_line in deps_to_install :
501
532
index = project .sources_default ["name" ]
502
- if dependency .name and lockfile_section [dependency .name ].get ("index" ):
503
- index = lockfile_section [dependency .name ]["index" ]
533
+ if dependency .name and dependency .name in lockfile_section :
534
+ entry = lockfile_section [dependency .name ]
535
+ if isinstance (entry , dict ) and "index" in entry :
536
+ index = entry ["index" ]
504
537
deps_by_index [index ].append (pip_line )
505
538
# Treat each index as its own pip install phase
506
539
for index_name , dependencies in deps_by_index .items ():
@@ -560,6 +593,7 @@ def do_init(
560
593
pypi_mirror = None ,
561
594
extra_pip_args = None ,
562
595
categories = None ,
596
+ skip_lock = False ,
563
597
):
564
598
"""Executes the init functionality."""
565
599
python = None
@@ -585,7 +619,7 @@ def do_init(
585
619
suffix = "-requirements" , prefix = "pipenv-"
586
620
)
587
621
# Write out the lockfile if it doesn't exist, but not if the Pipfile is being ignored
588
- if project .lockfile_exists and not ignore_pipfile :
622
+ if ( project .lockfile_exists and not ignore_pipfile ) and not skip_lock :
589
623
old_hash = project .get_lockfile_hash ()
590
624
new_hash = project .calculate_pipfile_hash ()
591
625
if new_hash != old_hash :
@@ -620,7 +654,7 @@ def do_init(
620
654
categories = categories ,
621
655
)
622
656
# Write out the lockfile if it doesn't exist.
623
- if not project .lockfile_exists :
657
+ if not project .lockfile_exists and not skip_lock :
624
658
# Unless we're in a virtualenv not managed by pipenv, abort if we're
625
659
# using the system's python.
626
660
if (system or allow_global ) and not (project .s .PIPENV_VIRTUALENV ):
@@ -652,6 +686,7 @@ def do_init(
652
686
pypi_mirror = pypi_mirror ,
653
687
extra_pip_args = extra_pip_args ,
654
688
categories = categories ,
689
+ skip_lock = skip_lock ,
655
690
)
656
691
657
692
# Hint the user what to do to activate the virtualenv.
0 commit comments