Skip to content

Commit 57467b7

Browse files
author
Carl Meyer
committed
Merge pull request #178 from mcdonc/feature.invertsitepackages
Invert site-packages behavior. Thanks, Chris McDonough.
2 parents d4e6e6b + fa31b67 commit 57467b7

File tree

3 files changed

+39
-16
lines changed

3 files changed

+39
-16
lines changed

docs/index.txt

+11-11
Original file line numberDiff line numberDiff line change
@@ -207,15 +207,16 @@ On Windows you just do::
207207

208208
And use ``deactivate.bat`` to undo the changes.
209209

210-
The ``--no-site-packages`` Option
210+
The ``--use-site-packages`` Option
211211
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
212212

213-
If you build with ``virtualenv --no-site-packages ENV`` it will *not*
214-
inherit any packages from ``/usr/lib/python2.5/site-packages`` (or
215-
wherever your global site-packages directory is). This can be used if
216-
you don't have control over site-packages and don't want to depend on
217-
the packages there, or you just want more isolation from the global
218-
system.
213+
If you build with ``virtualenv --use-site-packages ENV``, your virtual
214+
environment will inherit packages from ``/usr/lib/python2.5/site-packages``
215+
(or wherever your global site-packages directory is).
216+
217+
This can be used if you have control over the global site-packages directory,
218+
and you want to depend on the packages there. If you want isolation from the
219+
global system, do not use this flag.
219220

220221
Using Virtualenv without ``bin/python``
221222
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -236,8 +237,7 @@ can setup the environment like::
236237
This will change ``sys.path`` and even change ``sys.prefix``, but also allow
237238
you to use an existing interpreter. Items in your environment will show up
238239
first on ``sys.path``, before global items. However, global items will
239-
always be accessible -- this technique does not support the
240-
``--no-site-packages`` flag. Also, this cannot undo the activation of other
240+
always be accessible. Also, this cannot undo the activation of other
241241
environments, or modules that have been imported. You shouldn't try to, for
242242
instance, activate an environment before a web request; you should activate
243243
*one* environment as early as possible, and not do it again in that process.
@@ -277,8 +277,8 @@ libraries on the system, if those C libraries are located somewhere
277277
different (either different versions, or a different filesystem
278278
layout).
279279

280-
Currently the ``--no-site-packages`` option will not be honored if you
281-
use this on an environment.
280+
If you use this flag to create an environment, currently, the
281+
``--use-site-packages`` option will be implied.
282282

283283
The ``--extra-search-dir`` Option
284284
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

docs/news.txt

+10
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,16 @@ Next release (1.7) schedule
66

77
Beta release mid-July 2011, final release early August.
88

9+
Next release
10+
~~~~~~~~~~~~
11+
12+
* Made ``--no-site-packages`` behavior the default behavior. The
13+
``--no-site-packages`` flag is still permitted, but displays a warning when
14+
used.
15+
16+
* New flag: ``--use-site-packages``; this flag should be passed to get the
17+
previous default global-site-package-including behavior back.
18+
919
1.6.4 (2011-07-21)
1020
~~~~~~~~~~~~~~~~~~
1121

virtualenv.py

+18-5
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,7 @@ def _install_req(py_executable, unzip=False, distribute=False,
494494
if not hasattr(pkg_resources, '_distribute'):
495495
location = os.path.dirname(pkg_resources.__file__)
496496
logger.notify("A globally installed setuptools was found (in %s)" % location)
497-
logger.notify("Use the --no-site-packages option to use distribute in "
497+
logger.notify("Refrain from using the --use-site-packages option to use distribute in "
498498
"the virtualenv.")
499499
except ImportError:
500500
pass
@@ -709,6 +709,13 @@ def main():
709709
help="Don't give access to the global site-packages dir to the "
710710
"virtual environment")
711711

712+
parser.add_option(
713+
'--use-site-packages',
714+
dest='use_site_packages',
715+
action='store_true',
716+
help="Give access to the global site-packages dir to the "
717+
"virtual environment")
718+
712719
parser.add_option(
713720
'--unzip-setuptools',
714721
dest='unzip_setuptools',
@@ -802,7 +809,13 @@ def main():
802809
make_environment_relocatable(home_dir)
803810
return
804811

805-
create_environment(home_dir, site_packages=not options.no_site_packages, clear=options.clear,
812+
if options.no_site_packages:
813+
logger.warn('The --no-site-packages flag is deprecated; it is now '
814+
'the default behavior.')
815+
816+
create_environment(home_dir,
817+
site_packages=options.use_site_packages,
818+
clear=options.clear,
806819
unzip_setuptools=options.unzip_setuptools,
807820
use_distribute=options.use_distribute or majver > 2,
808821
prompt=options.prompt,
@@ -882,14 +895,14 @@ def call_subprocess(cmd, show_stdout=True,
882895
% (cmd_desc, proc.returncode))
883896

884897

885-
def create_environment(home_dir, site_packages=True, clear=False,
898+
def create_environment(home_dir, site_packages=False, clear=False,
886899
unzip_setuptools=False, use_distribute=False,
887900
prompt=None, search_dirs=None, never_download=False):
888901
"""
889902
Creates a new environment in ``home_dir``.
890903
891-
If ``site_packages`` is true (the default) then the global
892-
``site-packages/`` directory will be on the path.
904+
If ``site_packages`` is true, then the global ``site-packages/``
905+
directory will be on the path.
893906
894907
If ``clear`` is true (default False) then the environment will
895908
first be cleared.

0 commit comments

Comments
 (0)