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

Skip to content

Commit 62926ee

Browse files
committed
Closes #18434: Merged documentation update from 3.3.
2 parents ae95b4f + 3c557f2 commit 62926ee

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
@@ -186,7 +186,7 @@ An example of extending ``EnvBuilder``
186186
--------------------------------------
187187

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

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

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

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

244246
def reader(self, stream, context):
@@ -268,10 +270,14 @@ subclass which installs Distribute and pip into a created venv::
268270
# Download script into the env's binaries folder
269271
urlretrieve(url, distpath)
270272
progress = self.progress
273+
if self.verbose:
274+
term = '\n'
275+
else:
276+
term = ''
271277
if progress is not None:
272-
progress('Installing %s' %name, 'main')
278+
progress('Installing %s ...%s' % (name, term), 'main')
273279
else:
274-
sys.stderr.write('Installing %s ' % name)
280+
sys.stderr.write('Installing %s ...%s' % (name, term))
275281
sys.stderr.flush()
276282
# Install in the env
277283
args = [context.env_exe, fn]
@@ -290,17 +296,17 @@ subclass which installs Distribute and pip into a created venv::
290296
# Clean up - no longer needed
291297
os.unlink(distpath)
292298

293-
def install_distribute(self, context):
299+
def install_setuptools(self, context):
294300
"""
295-
Install Distribute in the environment.
301+
Install setuptools in the environment.
296302

297303
:param context: The information for the environment creation request
298304
being processed.
299305
"""
300-
url = 'http://python-distribute.org/distribute_setup.py'
301-
self.install_script(context, 'distribute', url)
302-
# clear up the distribute archive which gets downloaded
303-
pred = lambda o: o.startswith('distribute-') and o.endswith('.tar.gz')
306+
url = 'https://bitbucket.org/pypa/setuptools/downloads/ez_setup.py'
307+
self.install_script(context, 'setuptools', url)
308+
# clear up the setuptools archive which gets downloaded
309+
pred = lambda o: o.startswith('setuptools-') and o.endswith('.tar.gz')
304310
files = filter(pred, os.listdir(context.bin_path))
305311
for f in files:
306312
f = os.path.join(context.bin_path, f)
@@ -335,10 +341,10 @@ subclass which installs Distribute and pip into a created venv::
335341
'directories.')
336342
parser.add_argument('dirs', metavar='ENV_DIR', nargs='+',
337343
help='A directory to create the environment in.')
338-
parser.add_argument('--no-distribute', default=False,
344+
parser.add_argument('--no-setuptools', default=False,
339345
action='store_true', dest='nodist',
340-
help="Don't install Distribute in the virtual "
341-
"environment.")
346+
help="Don't install setuptools or pip in the "
347+
"virtual environment.")
342348
parser.add_argument('--no-pip', default=False,
343349
action='store_true', dest='nopip',
344350
help="Don't install pip in the virtual "
@@ -369,11 +375,11 @@ subclass which installs Distribute and pip into a created venv::
369375
parser.add_argument('--verbose', default=False, action='store_true',
370376
dest='verbose', help='Display the output '
371377
'from the scripts which '
372-
'install Distribute and pip.')
378+
'install setuptools and pip.')
373379
options = parser.parse_args(args)
374380
if options.upgrade and options.clear:
375381
raise ValueError('you cannot supply --upgrade and --clear together.')
376-
builder = DistributeEnvBuilder(system_site_packages=options.system_site,
382+
builder = ExtendedEnvBuilder(system_site_packages=options.system_site,
377383
clear=options.clear,
378384
symlinks=options.symlinks,
379385
upgrade=options.upgrade,
@@ -392,5 +398,6 @@ subclass which installs Distribute and pip into a created venv::
392398
print('Error: %s' % e, file=sys.stderr)
393399
sys.exit(rc)
394400

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

0 commit comments

Comments
 (0)