Skip to content

Commit f936d4a

Browse files
committed
--site-packages
Signed-off-by: Kenneth Reitz <[email protected]>
1 parent 0df5afb commit f936d4a

File tree

1 file changed

+27
-10
lines changed

1 file changed

+27
-10
lines changed

pipenv/cli.py

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,7 @@ def activate_pyenv():
476476
return path_to_python
477477

478478

479-
def ensure_virtualenv(three=None, python=None):
479+
def ensure_virtualenv(three=None, python=None, site_packages=False):
480480
"""Creates a virtualenv, if one doesn't exist."""
481481

482482
global USING_DEFAULT_PYTHON
@@ -490,15 +490,15 @@ def ensure_virtualenv(three=None, python=None):
490490
python = ensure_python(three=three, python=python)
491491

492492
# Create the virtualenv.
493-
do_create_virtualenv(python=python)
493+
do_create_virtualenv(python=python, site_packages=site_packages)
494494

495495
except KeyboardInterrupt:
496496
# If interrupted, cleanup the virtualenv.
497497
cleanup_virtualenv(bare=False)
498498
sys.exit(1)
499499

500500
# 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):
502502
click.echo(crayons.red('Virtualenv already exists!'), err=True)
503503
click.echo(crayons.white(u'Removing existing virtualenv…', bold=True), err=True)
504504

@@ -508,18 +508,18 @@ def ensure_virtualenv(three=None, python=None):
508508
cleanup_virtualenv(bare=True)
509509

510510
# Call this function again.
511-
ensure_virtualenv(three=three, python=python)
511+
ensure_virtualenv(three=three, python=python, site_packages=site_packages)
512512

513513

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):
515515
"""Ensures both Pipfile and virtualenv exist for the project."""
516516

517517
if not project.pipfile_exists:
518518
project.touch_pipfile()
519519

520520
# Skip virtualenv creation when --system was used.
521521
if not system:
522-
ensure_virtualenv(three=three, python=python)
522+
ensure_virtualenv(three=three, python=python, site_packages=site_packages)
523523

524524
if warn:
525525
# Warn users if they are using the wrong version of Python.
@@ -787,14 +787,18 @@ def convert_three_to_python(three, python):
787787
return python
788788

789789

790-
def do_create_virtualenv(python=None):
790+
def do_create_virtualenv(python=None, site_packages=False):
791791
"""Creates a virtualenv."""
792792

793793
click.echo(crayons.white(u'Creating a virtualenv for this project…', bold=True), err=True)
794794

795795
# The user wants the virtualenv in the project.
796796
if PIPENV_VENV_IN_PROJECT:
797797
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']
798802
else:
799803
# Default: use pew.
800804
cmd = ['pew', 'new', project.virtualenv_name, '-d']
@@ -827,6 +831,17 @@ def do_create_virtualenv(python=None):
827831
)
828832
sys.exit(1)
829833

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+
830845
click.echo(crayons.blue(c.out), err=True)
831846

832847
# Say where the virtualenv is.
@@ -1347,12 +1362,14 @@ def kr_easter_egg(package_name):
13471362
@click.option('--three/--two', is_flag=True, default=None, help="Use Python 3/2 when creating virtualenv.")
13481363
@click.option('--python', default=False, nargs=1, help="Specify which version of Python virtualenv should use.")
13491364
@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.")
13501366
@click.option('--jumbotron', '-j', is_flag=True, default=False, help="An easter egg, effectively.")
13511367
@click.version_option(prog_name=crayons.yellow('pipenv'), version=__version__)
13521368
@click.pass_context
13531369
def cli(
13541370
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
13561373
):
13571374

13581375
if jumbotron:
@@ -1429,8 +1446,8 @@ def cli(
14291446
sys.exit(1)
14301447

14311448
# --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)
14341451

14351452
# Check this again before exiting for empty ``pipenv`` command.
14361453
elif ctx.invoked_subcommand is None:

0 commit comments

Comments
 (0)