Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3c557f2

Browse files
committed
Issue #18434: Updated example script in venv docs to use setuptools rather than Distribute.
1 parent 65171b2 commit 3c557f2

1 file changed

Lines changed: 28 additions & 21 deletions

File tree

Doc/library/venv.rst

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ An example of extending ``EnvBuilder``
187187
--------------------------------------
188188

189189
The following script shows how to extend :class:`EnvBuilder` by implementing a
190-
subclass which installs Distribute and pip into a created venv::
190+
subclass which installs setuptools and pip into a created venv::
191191

192192
import os
193193
import os.path
@@ -198,16 +198,16 @@ subclass which installs Distribute and pip into a created venv::
198198
from urllib.request import urlretrieve
199199
import venv
200200

201-
class DistributeEnvBuilder(venv.EnvBuilder):
201+
class ExtendedEnvBuilder(venv.EnvBuilder):
202202
"""
203-
This builder installs Distribute and pip so that you can pip or
203+
This builder installs setuptools and pip so that you can pip or
204204
easy_install other packages into the created environment.
205205

206-
:param nodist: If True, Distribute is not installed into the created
207-
environment.
206+
:param nodist: If True, setuptools and pip are not installed into the
207+
created environment.
208208
:param nopip: If True, pip is not installed into the created
209209
environment.
210-
:param progress: If Distribute or pip are installed, the progress of the
210+
:param progress: If setuptools or pip are installed, the progress of the
211211
installation can be monitored by passing a progress
212212
callable. If specified, it is called with two
213213
arguments: a string indicating some progress, and a
@@ -237,9 +237,11 @@ subclass which installs Distribute and pip into a created venv::
237237
:param context: The information for the environment creation request
238238
being processed.
239239
"""
240+
os.environ['VIRTUAL_ENV'] = context.env_dir
240241
if not self.nodist:
241-
self.install_distribute(context)
242-
if not self.nopip:
242+
self.install_setuptools(context)
243+
# Can't install pip without setuptools
244+
if not self.nopip and not self.nodist:
243245
self.install_pip(context)
244246

245247
def reader(self, stream, context):
@@ -269,10 +271,14 @@ subclass which installs Distribute and pip into a created venv::
269271
# Download script into the env's binaries folder
270272
urlretrieve(url, distpath)
271273
progress = self.progress
274+
if self.verbose:
275+
term = '\n'
276+
else:
277+
term = ''
272278
if progress is not None:
273-
progress('Installing %s' %name, 'main')
279+
progress('Installing %s ...%s' % (name, term), 'main')
274280
else:
275-
sys.stderr.write('Installing %s ' % name)
281+
sys.stderr.write('Installing %s ...%s' % (name, term))
276282
sys.stderr.flush()
277283
# Install in the env
278284
args = [context.env_exe, fn]
@@ -291,17 +297,17 @@ subclass which installs Distribute and pip into a created venv::
291297
# Clean up - no longer needed
292298
os.unlink(distpath)
293299

294-
def install_distribute(self, context):
300+
def install_setuptools(self, context):
295301
"""
296-
Install Distribute in the environment.
302+
Install setuptools in the environment.
297303

298304
:param context: The information for the environment creation request
299305
being processed.
300306
"""
301-
url = 'http://python-distribute.org/distribute_setup.py'
302-
self.install_script(context, 'distribute', url)
303-
# clear up the distribute archive which gets downloaded
304-
pred = lambda o: o.startswith('distribute-') and o.endswith('.tar.gz')
307+
url = 'https://bitbucket.org/pypa/setuptools/downloads/ez_setup.py'
308+
self.install_script(context, 'setuptools', url)
309+
# clear up the setuptools archive which gets downloaded
310+
pred = lambda o: o.startswith('setuptools-') and o.endswith('.tar.gz')
305311
files = filter(pred, os.listdir(context.bin_path))
306312
for f in files:
307313
f = os.path.join(context.bin_path, f)
@@ -336,10 +342,10 @@ subclass which installs Distribute and pip into a created venv::
336342
'directories.')
337343
parser.add_argument('dirs', metavar='ENV_DIR', nargs='+',
338344
help='A directory to create the environment in.')
339-
parser.add_argument('--no-distribute', default=False,
345+
parser.add_argument('--no-setuptools', default=False,
340346
action='store_true', dest='nodist',
341-
help="Don't install Distribute in the virtual "
342-
"environment.")
347+
help="Don't install setuptools or pip in the "
348+
"virtual environment.")
343349
parser.add_argument('--no-pip', default=False,
344350
action='store_true', dest='nopip',
345351
help="Don't install pip in the virtual "
@@ -370,11 +376,11 @@ subclass which installs Distribute and pip into a created venv::
370376
parser.add_argument('--verbose', default=False, action='store_true',
371377
dest='verbose', help='Display the output '
372378
'from the scripts which '
373-
'install Distribute and pip.')
379+
'install setuptools and pip.')
374380
options = parser.parse_args(args)
375381
if options.upgrade and options.clear:
376382
raise ValueError('you cannot supply --upgrade and --clear together.')
377-
builder = DistributeEnvBuilder(system_site_packages=options.system_site,
383+
builder = ExtendedEnvBuilder(system_site_packages=options.system_site,
378384
clear=options.clear,
379385
symlinks=options.symlinks,
380386
upgrade=options.upgrade,
@@ -393,5 +399,6 @@ subclass which installs Distribute and pip into a created venv::
393399
print('Error: %s' % e, file=sys.stderr)
394400
sys.exit(rc)
395401

402+
396403
This script is also available for download `online
397404
<https://gist.github.com/4673395>`_.

0 commit comments

Comments
 (0)