Skip to content

Commit

Permalink
added the --distribute option
Browse files Browse the repository at this point in the history
--HG--
branch : trunk
  • Loading branch information
tarek committed Oct 23, 2009
1 parent 31f26bb commit 531ff86
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 17 deletions.
9 changes: 7 additions & 2 deletions bin/refresh-support-files.py
Expand Up @@ -14,6 +14,11 @@
('http://pypi.python.org/packages/2.6/s/setuptools/setuptools-0.6c11-py2.6.egg', 'setuptools-0.6c11-py2.6.egg'),
('http://pypi.python.org/packages/2.5/s/setuptools/setuptools-0.6c11-py2.5.egg', 'setuptools-0.6c11-py2.5.egg'),
('http://pypi.python.org/packages/2.4/s/setuptools/setuptools-0.6c11-py2.4.egg', 'setuptools-0.6c11-py2.4.egg'),
('http://python-distribute.org/distribute_setup.py', 'distribute_setup.py'),
('http://pypi.python.org/packages/2.3/d/distribute/distribute-0.6-py2.3.egg', 'distribute-0.6-py2.3.egg'),
('http://pypi.python.org/packages/2.4/d/distribute/distribute-0.6-py2.4.egg', 'distribute-0.6-py2.4.egg'),
('http://pypi.python.org/packages/2.5/d/distribute/distribute-0.6-py2.5.egg', 'distribute-0.6-py2.5.egg'),
('http://pypi.python.org/packages/2.6/d/distribute/distribute-0.6-py2.6.egg', 'distribute-0.6-py2.6.egg'),
]

def main():
Expand Down Expand Up @@ -41,5 +46,5 @@ def main():

if __name__ == '__main__':
main()


19 changes: 17 additions & 2 deletions docs/index.txt
Expand Up @@ -71,6 +71,16 @@ It also installs `Setuptools
you use ``ENV/bin/easy_install`` the packages will be installed into
the environment.

If you use the ``--distribute`` option, it wil installs `distribute
<http://pypi.python.org/pypi/distribute>`_ for you, instead of setuptools,
and if you use `ENV/bin/easy_install`` the packages will be installed into the
environment.

To use Distribute just call virtualenv like this::

$ python virtualenv.py --distribute ENV


Creating Your Own Bootstrap Scripts
-----------------------------------

Expand Down Expand Up @@ -218,8 +228,8 @@ command::

$ virtualenv --relocatable ENV

This will make some of the files created by setuptools use relative
paths, and will change all the scripts to use ``activate_this.py``
This will make some of the files created by setuptools or distribute
use relative paths, and will change all the scripts to use ``activate_this.py``
instead of using the location of the Python interpreter to select the
environment.

Expand Down Expand Up @@ -307,6 +317,11 @@ Other Documentation and Links
Changes & News
--------------

trunk
~~~~~

* Added the --distribute option

1.3.4
~~~~~

Expand Down
52 changes: 39 additions & 13 deletions virtualenv.py
Expand Up @@ -243,8 +243,8 @@ def make_exe(fn):
os.chmod(fn, newmode)
logger.info('Changed mode of %s to %s', fn, oct(newmode))

def install_setuptools(py_executable, unzip=False):
setup_fn = 'setuptools-0.6c11-py%s.egg' % sys.version[:3]
def _install_distribute_or_setuptools(setup_fn, project_name, py_executable,
unzip=False):
search_dirs = ['.', os.path.dirname(__file__), join(os.path.dirname(__file__), 'virtualenv_support')]
if os.path.splitext(os.path.dirname(__file__))[0] != 'virtualenv':
# Probably some boot script; just in case virtualenv is installed...
Expand Down Expand Up @@ -274,23 +274,29 @@ def install_setuptools(py_executable, unzip=False):
if logger.stdout_level_matches(logger.DEBUG):
cmd.append('-v')
if os.path.exists(setup_fn):
logger.info('Using existing Setuptools egg: %s', setup_fn)
logger.info('Using existing %s egg: %s' % (project_name, setup_fn))
cmd.append(setup_fn)
if os.environ.get('PYTHONPATH'):
env['PYTHONPATH'] = setup_fn + os.path.pathsep + os.environ['PYTHONPATH']
else:
env['PYTHONPATH'] = setup_fn
else:
logger.info('No Setuptools egg found; downloading')
cmd.extend(['--always-copy', '-U', 'setuptools'])
logger.start_progress('Installing setuptools...')
logger.info('No %s egg found; downloading' % project_name)
cmd.extend(['--always-copy', '-U', project_name])
logger.start_progress('Installing %s...' % project_name)
logger.indent += 2
cwd = None

def _filter_ez_setup(line):
def __filter_ez_setup(line):
return filter_ez_setup(line, project_name)
return __filter_ez_setup

if not os.access(os.getcwd(), os.W_OK):
cwd = '/tmp'
try:
call_subprocess(cmd, show_stdout=False,
filter_stdout=filter_ez_setup,
filter_stdout=_filter_ez_setup,
extra_env=env,
cwd=cwd)
finally:
Expand All @@ -299,11 +305,21 @@ def install_setuptools(py_executable, unzip=False):
if is_jython and os._name == 'nt':
os.remove(ez_setup)

def filter_ez_setup(line):
def install_setuptools(py_executable, unzip=False):
setup_fn = 'setuptools-0.6c11-py%s.egg' % sys.version[:3]
_install_distribute_or_setuptools(setup_fn, 'setuptools', py_executable,
unzip)

def install_distribute(py_executable, unzip=False):
setup_fn = 'distribute-0.6-py%s.egg' % sys.version[:3]
_install_distribute_or_setuptools(setup_fn, 'distribute', py_executable,
unzip)

def filter_ez_setup(line, project_name='setuptools'):
if not line.strip():
return Logger.DEBUG
for prefix in ['Reading ', 'Best match', 'Processing setuptools',
'Copying setuptools', 'Adding setuptools',
for prefix in ['Reading ', 'Best match', 'Processing %s' % project_name,
'Copying setuptools', 'Adding %s' % project_name,
'Installing ', 'Installed ']:
if line.startswith(prefix):
return Logger.DEBUG
Expand Down Expand Up @@ -362,6 +378,12 @@ def main():
help='Make an EXISTING virtualenv environment relocatable. '
'This fixes up scripts and makes all .pth files relative')

parser.add_option(
'--distribute',
dest='use_distribute',
action='store_true',
help="Use Distribute instead of Setuptools")

if 'extend_parser' in globals():
extend_parser(parser)

Expand Down Expand Up @@ -417,7 +439,8 @@ def main():
return

create_environment(home_dir, site_packages=not options.no_site_packages, clear=options.clear,
unzip_setuptools=options.unzip_setuptools)
unzip_setuptools=options.unzip_setuptools,
use_distribute=options.use_distribute)
if 'after_install' in globals():
after_install(options, home_dir)

Expand Down Expand Up @@ -486,7 +509,7 @@ def call_subprocess(cmd, show_stdout=True,


def create_environment(home_dir, site_packages=True, clear=False,
unzip_setuptools=False):
unzip_setuptools=False, use_distribute=False):
"""
Creates a new environment in ``home_dir``.
Expand All @@ -504,7 +527,10 @@ def create_environment(home_dir, site_packages=True, clear=False,

install_distutils(lib_dir, home_dir)

install_setuptools(py_executable, unzip=unzip_setuptools)
if use_distribute:
install_distribute(py_executable, unzip=unzip_setuptools):
else:
install_setuptools(py_executable, unzip=unzip_setuptools)

install_activate(home_dir, bin_dir)

Expand Down

0 comments on commit 531ff86

Please sign in to comment.