@@ -476,7 +476,7 @@ def activate_pyenv():
476
476
return path_to_python
477
477
478
478
479
- def ensure_virtualenv (three = None , python = None ):
479
+ def ensure_virtualenv (three = None , python = None , site_packages = False ):
480
480
"""Creates a virtualenv, if one doesn't exist."""
481
481
482
482
global USING_DEFAULT_PYTHON
@@ -490,15 +490,15 @@ def ensure_virtualenv(three=None, python=None):
490
490
python = ensure_python (three = three , python = python )
491
491
492
492
# Create the virtualenv.
493
- do_create_virtualenv (python = python )
493
+ do_create_virtualenv (python = python , site_packages = site_packages )
494
494
495
495
except KeyboardInterrupt :
496
496
# If interrupted, cleanup the virtualenv.
497
497
cleanup_virtualenv (bare = False )
498
498
sys .exit (1 )
499
499
500
500
# If --three, --two, or --python were passed...
501
- elif (python ) or (three is not None ):
501
+ elif (python ) or (three is not None ) or ( site_packages is not False ) :
502
502
click .echo (crayons .red ('Virtualenv already exists!' ), err = True )
503
503
click .echo (crayons .white (u'Removing existing virtualenv…' , bold = True ), err = True )
504
504
@@ -508,18 +508,18 @@ def ensure_virtualenv(three=None, python=None):
508
508
cleanup_virtualenv (bare = True )
509
509
510
510
# Call this function again.
511
- ensure_virtualenv (three = three , python = python )
511
+ ensure_virtualenv (three = three , python = python , site_packages = site_packages )
512
512
513
513
514
- def ensure_project (three = None , python = None , validate = True , system = False , warn = True ):
514
+ def ensure_project (three = None , python = None , validate = True , system = False , warn = True , site_packages = False ):
515
515
"""Ensures both Pipfile and virtualenv exist for the project."""
516
516
517
517
if not project .pipfile_exists :
518
518
project .touch_pipfile ()
519
519
520
520
# Skip virtualenv creation when --system was used.
521
521
if not system :
522
- ensure_virtualenv (three = three , python = python )
522
+ ensure_virtualenv (three = three , python = python , site_packages = site_packages )
523
523
524
524
if warn :
525
525
# Warn users if they are using the wrong version of Python.
@@ -787,14 +787,18 @@ def convert_three_to_python(three, python):
787
787
return python
788
788
789
789
790
- def do_create_virtualenv (python = None ):
790
+ def do_create_virtualenv (python = None , site_packages = False ):
791
791
"""Creates a virtualenv."""
792
792
793
793
click .echo (crayons .white (u'Creating a virtualenv for this project…' , bold = True ), err = True )
794
794
795
795
# The user wants the virtualenv in the project.
796
796
if PIPENV_VENV_IN_PROJECT :
797
797
cmd = ['virtualenv' , project .virtualenv_location , '--prompt=({0})' .format (project .name )]
798
+
799
+ # Pass site-packages flag to virtualenv, if desired...
800
+ if site_packages :
801
+ cmd = [cmd ] + ['--system-site-packages' ]
798
802
else :
799
803
# Default: use pew.
800
804
cmd = ['pew' , 'new' , project .virtualenv_name , '-d' ]
@@ -827,6 +831,17 @@ def do_create_virtualenv(python=None):
827
831
)
828
832
sys .exit (1 )
829
833
834
+ # Enable site-packages, if desired...
835
+ if not PIPENV_VENV_IN_PROJECT and site_packages :
836
+ os .environ ['VIRTUAL_ENV' ] = project .virtualenv_location
837
+
838
+ click .echo (crayons .white (u'Making site-packages available…' , bold = True ))
839
+
840
+ c = delegator .run ('pew toggleglobalsitepackages' )
841
+ del os .environ ['VIRTUAL_ENV' ]
842
+
843
+
844
+
830
845
click .echo (crayons .blue (c .out ), err = True )
831
846
832
847
# Say where the virtualenv is.
@@ -1347,12 +1362,14 @@ def kr_easter_egg(package_name):
1347
1362
@click .option ('--three/--two' , is_flag = True , default = None , help = "Use Python 3/2 when creating virtualenv." )
1348
1363
@click .option ('--python' , default = False , nargs = 1 , help = "Specify which version of Python virtualenv should use." )
1349
1364
@click .option ('--help' , '-h' , is_flag = True , default = None , help = "Show this message then exit." )
1365
+ @click .option ('--site-packages' , is_flag = True , default = False , help = "Enable site-packages for the virtualenv." )
1350
1366
@click .option ('--jumbotron' , '-j' , is_flag = True , default = False , help = "An easter egg, effectively." )
1351
1367
@click .version_option (prog_name = crayons .yellow ('pipenv' ), version = __version__ )
1352
1368
@click .pass_context
1353
1369
def cli (
1354
1370
ctx , where = False , venv = False , rm = False , bare = False , three = False ,
1355
- python = False , help = False , update = False , jumbotron = False , py = False
1371
+ python = False , help = False , update = False , jumbotron = False , py = False ,
1372
+ site_packages = False
1356
1373
):
1357
1374
1358
1375
if jumbotron :
@@ -1429,8 +1446,8 @@ def cli(
1429
1446
sys .exit (1 )
1430
1447
1431
1448
# --two / --three was passed...
1432
- if python or three is not None :
1433
- ensure_project (three = three , python = python , warn = True )
1449
+ if ( python or three is not None ) or site_packages :
1450
+ ensure_project (three = three , python = python , warn = True , site_packages = site_packages )
1434
1451
1435
1452
# Check this again before exiting for empty ``pipenv`` command.
1436
1453
elif ctx .invoked_subcommand is None :
0 commit comments