Commit 83d53da5 authored by Jim Fulton's avatar Jim Fulton

checkout: core tests passing w python 3.2

parent 493394b7
...@@ -18,7 +18,7 @@ The script accepts buildout command-line options, so you can ...@@ -18,7 +18,7 @@ The script accepts buildout command-line options, so you can
use the -c option to specify an alternate configuration file. use the -c option to specify an alternate configuration file.
""" """
import os, shutil, sys, tempfile, urllib2 import os, shutil, sys, tempfile, urllib.request, urllib.error, urllib.parse
from optparse import OptionParser from optparse import OptionParser
tmpeggs = tempfile.mkdtemp() tmpeggs = tempfile.mkdtemp()
...@@ -80,9 +80,9 @@ try: ...@@ -80,9 +80,9 @@ try:
raise ImportError raise ImportError
except ImportError: except ImportError:
ez = {} ez = {}
exec urllib2.urlopen( exec(urllib.request.urlopen(
'http://python-distribute.org/distribute_setup.py' 'http://python-distribute.org/distribute_setup.py'
).read() in ez ).read(), ez)
setup_args = dict(to_dir=tmpeggs, download_delay=0, no_fake=True) setup_args = dict(to_dir=tmpeggs, download_delay=0, no_fake=True)
ez['use_setuptools'](**setup_args) ez['use_setuptools'](**setup_args)
......
...@@ -9,7 +9,7 @@ eggs = zc.buildout ...@@ -9,7 +9,7 @@ eggs = zc.buildout
interpreter = py interpreter = py
[test] [test]
recipe = zc.recipe.testrunner recipe = zc.recipe.testrunner ==1.3.0
eggs = eggs =
zc.buildout[test] zc.buildout[test]
zc.recipe.egg zc.recipe.egg
......
...@@ -17,7 +17,7 @@ This is different from a normal boostrapping process because the ...@@ -17,7 +17,7 @@ This is different from a normal boostrapping process because the
buildout egg itself is installed as a develop egg. buildout egg itself is installed as a develop egg.
""" """
import os, shutil, sys, subprocess, urllib2 import os, shutil, sys, subprocess, urllib.request, urllib.error, urllib.parse
for d in 'eggs', 'develop-eggs', 'bin', 'parts': for d in 'eggs', 'develop-eggs', 'bin', 'parts':
if not os.path.exists(d): if not os.path.exists(d):
...@@ -57,8 +57,8 @@ else: ...@@ -57,8 +57,8 @@ else:
###################################################################### ######################################################################
# Install distribute # Install distribute
ez = {} ez = {}
exec urllib2.urlopen( exec(urllib.request.urlopen(
'http://python-distribute.org/distribute_setup.py').read() in ez 'http://python-distribute.org/distribute_setup.py').read(), ez)
ez['use_setuptools'](to_dir='eggs', download_delay=0) ez['use_setuptools'](to_dir='eggs', download_delay=0)
import pkg_resources import pkg_resources
......
...@@ -19,4 +19,4 @@ class UserError(Exception): ...@@ -19,4 +19,4 @@ class UserError(Exception):
""" """
def __str__(self): def __str__(self):
return " ".join(map(str, self)) return " ".join(map(str, self.args))
...@@ -55,7 +55,7 @@ local files:: ...@@ -55,7 +55,7 @@ local files::
Now we can run the buildout and make sure all attempts to dist.plone.org fails:: Now we can run the buildout and make sure all attempts to dist.plone.org fails::
>>> print system(buildout) >>> print_(system(buildout))
Develop: '/sample-buildout/allowdemo' Develop: '/sample-buildout/allowdemo'
Installing eggs. Installing eggs.
<BLANKLINE> <BLANKLINE>
...@@ -91,7 +91,7 @@ XXX (showcase with a svn:// file) ...@@ -91,7 +91,7 @@ XXX (showcase with a svn:// file)
Now we can run the buildout and make sure all attempts to dist.plone.org fails:: Now we can run the buildout and make sure all attempts to dist.plone.org fails::
>>> print system(buildout) >>> print_(system(buildout))
Develop: '/sample-buildout/allowdemo' Develop: '/sample-buildout/allowdemo'
Installing eggs. Installing eggs.
<BLANKLINE> <BLANKLINE>
...@@ -121,7 +121,7 @@ Test for 1.0.5 breakage as in https://bugs.launchpad.net/zc.buildout/+bug/239212 ...@@ -121,7 +121,7 @@ Test for 1.0.5 breakage as in https://bugs.launchpad.net/zc.buildout/+bug/239212
... eggs=zc.buildout ... eggs=zc.buildout
... interpreter=python ... interpreter=python
... ''') ... ''')
>>> print 'XX'; print system(buildout) # doctest: +ELLIPSIS >>> print_('XX'; print system(buildout)) # doctest: +ELLIPSIS
X... X...
Unused options for buildout: 'foo'. Unused options for buildout: 'foo'.
Installing python. Installing python.
......
...@@ -20,9 +20,9 @@ Make sure the bootstrap script actually works:: ...@@ -20,9 +20,9 @@ Make sure the bootstrap script actually works::
... parts = ... parts =
... ''') ... ''')
>>> write('bootstrap.py', open(bootstrap_py).read()) >>> write('bootstrap.py', open(bootstrap_py).read())
>>> print 'X'; print system( >>> print_('X'; print system(
... zc.buildout.easy_install._safe_arg(sys.executable)+' '+ ... zc.buildout.easy_install._safe_arg(sys.executable)+' '+
... 'bootstrap.py'); print 'X' # doctest: +ELLIPSIS ... 'bootstrap.py')); print_('X') # doctest: +ELLIPSIS
X... X...
Creating directory '/sample/bin'. Creating directory '/sample/bin'.
Creating directory '/sample/parts'. Creating directory '/sample/parts'.
...@@ -43,7 +43,7 @@ Make sure the bootstrap script actually works:: ...@@ -43,7 +43,7 @@ Make sure the bootstrap script actually works::
>>> ls(sample_buildout, 'bin') >>> ls(sample_buildout, 'bin')
- buildout - buildout
>>> print 'X'; ls(sample_buildout, 'eggs') # doctest: +ELLIPSIS >>> print_('X'); ls(sample_buildout, 'eggs') # doctest: +ELLIPSIS
X... X...
d zc.buildout-...egg d zc.buildout-...egg
...@@ -52,9 +52,9 @@ Now trying the `--version` option, that let you define a version for ...@@ -52,9 +52,9 @@ Now trying the `--version` option, that let you define a version for
Let's try with an unknown version:: Let's try with an unknown version::
>>> print 'X'; print system( >>> print_('X'); print_(system(
... zc.buildout.easy_install._safe_arg(sys.executable)+' '+ ... zc.buildout.easy_install._safe_arg(sys.executable)+' '+
... 'bootstrap.py --version UNKNOWN'); print 'X' # doctest: +ELLIPSIS ... 'bootstrap.py --version UNKNOWN')); print_('X') # doctest: +ELLIPSIS
... ...
X X
... ...
...@@ -63,9 +63,9 @@ Let's try with an unknown version:: ...@@ -63,9 +63,9 @@ Let's try with an unknown version::
Now let's try with `1.1.2`, which happens to exist:: Now let's try with `1.1.2`, which happens to exist::
>>> print 'X'; print system( >>> print_('X'); print_(system(
... zc.buildout.easy_install._safe_arg(sys.executable)+' '+ ... zc.buildout.easy_install._safe_arg(sys.executable)+' '+
... 'bootstrap.py --version 1.1.2'); print 'X' ... 'bootstrap.py --version 1.1.2')); print_('X')
... # doctest: +ELLIPSIS ... # doctest: +ELLIPSIS
X X
... ...
...@@ -78,7 +78,7 @@ Let's make sure the generated `buildout` script uses it:: ...@@ -78,7 +78,7 @@ Let's make sure the generated `buildout` script uses it::
>>> buildout_script = join(sample_buildout, 'bin', 'buildout') >>> buildout_script = join(sample_buildout, 'bin', 'buildout')
>>> if sys.platform.startswith('win'): >>> if sys.platform.startswith('win'):
... buildout_script += '-script.py' ... buildout_script += '-script.py'
>>> print open(buildout_script).read() # doctest: +ELLIPSIS >>> print_(open(buildout_script).read()) # doctest: +ELLIPSIS
#... #...
<BLANKLINE> <BLANKLINE>
import sys import sys
...@@ -95,9 +95,9 @@ Let's make sure the generated `buildout` script uses it:: ...@@ -95,9 +95,9 @@ Let's make sure the generated `buildout` script uses it::
Let's try with `1.2.1`:: Let's try with `1.2.1`::
>>> print 'X'; print system( >>> print_('X'); print_(system(
... zc.buildout.easy_install._safe_arg(sys.executable)+' '+ ... zc.buildout.easy_install._safe_arg(sys.executable)+' '+
... 'bootstrap.py --version 1.2.1'); print 'X' # doctest: +ELLIPSIS ... 'bootstrap.py --version 1.2.1')); print_('X') # doctest: +ELLIPSIS
... ...
X X
... ...
...@@ -107,7 +107,7 @@ Let's try with `1.2.1`:: ...@@ -107,7 +107,7 @@ Let's try with `1.2.1`::
Let's make sure the generated `buildout` script uses it:: Let's make sure the generated `buildout` script uses it::
>>> print open(buildout_script).read() # doctest: +ELLIPSIS >>> print_(open(buildout_script).read()) # doctest: +ELLIPSIS
#... #...
<BLANKLINE> <BLANKLINE>
import sys import sys
......
...@@ -18,10 +18,15 @@ ...@@ -18,10 +18,15 @@
import zc.buildout.easy_install import zc.buildout.easy_install
no_site = zc.buildout.easy_install.no_site no_site = zc.buildout.easy_install.no_site
from rmtree import rmtree from .rmtree import rmtree
from hashlib import md5 from hashlib import md5
import ConfigParser try:
from UserDict import DictMixin
except ImportError:
from collections import MutableMapping as DictMixin
import zc.buildout.configparser
import copy import copy
import distutils.errors import distutils.errors
import glob import glob
...@@ -34,10 +39,17 @@ import shutil ...@@ -34,10 +39,17 @@ import shutil
import subprocess import subprocess
import sys import sys
import tempfile import tempfile
import UserDict
import zc.buildout import zc.buildout
import zc.buildout.download import zc.buildout.download
def _print_options(sep=' ', end='\n', file=None):
return sep, end, file
def print_(*args, **kw):
sep, end, file = _print_options(**kw)
if file is None:
file = sys.stdout
file.write(sep.join(map(str, args))+end)
realpath = zc.buildout.easy_install.realpath realpath = zc.buildout.easy_install.realpath
...@@ -69,20 +81,20 @@ def _annotate(data, note): ...@@ -69,20 +81,20 @@ def _annotate(data, note):
return data return data
def _print_annotate(data): def _print_annotate(data):
sections = data.keys() sections = list(data.keys())
sections.sort() sections.sort()
print print_()
print "Annotated sections" print_("Annotated sections")
print "="*len("Annotated sections") print_("="*len("Annotated sections"))
for section in sections: for section in sections:
print print_()
print '[%s]' % section print_('[%s]' % section)
keys = data[section].keys() keys = list(data[section].keys())
keys.sort() keys.sort()
for key in keys: for key in keys:
value, notes = data[section][key] value, notes = data[section][key]
keyvalue = "%s= %s" % (key, value) keyvalue = "%s= %s" % (key, value)
print keyvalue print_(keyvalue)
line = ' ' line = ' '
for note in notes.split(): for note in notes.split():
if note == '[+]': if note == '[+]':
...@@ -90,9 +102,9 @@ def _print_annotate(data): ...@@ -90,9 +102,9 @@ def _print_annotate(data):
elif note == '[-]': elif note == '[-]':
line = '-= ' line = '-= '
else: else:
print line, note print_(line, note)
line = ' ' line = ' '
print print_()
def _unannotate_section(section): def _unannotate_section(section):
...@@ -127,24 +139,7 @@ _buildout_default_options = _annotate_section({ ...@@ -127,24 +139,7 @@ _buildout_default_options = _annotate_section({
'use-dependency-links': 'true', 'use-dependency-links': 'true',
}, 'DEFAULT_VALUE') }, 'DEFAULT_VALUE')
# _buildout_version and _buildout_1_4_default_versions are part of a class Buildout(DictMixin):
# hack specific to zc.buildout 1.4.4. Search for
# _buildout_1_4_default_versions below to see the usage.
_buildout_version = pkg_resources.working_set.find(
pkg_resources.Requirement.parse('zc.buildout')).version
_buildout_1_4_default_versions = {
# Buildout and recipes that are likely to change to 1.5.0 sooner rather
# than later.
'zc.buildout': _buildout_version,
# 'zc.recipe.egg': '1.2.2',
'zc.recipe.testrunner': '1.3.0',
'z3c.recipe.i18n': '0.7.0',
'z3c.recipe.tag:': '0.3.0',
'djangorecipe': '0.20',
}
class Buildout(UserDict.DictMixin):
def __init__(self, config_file, cloptions, def __init__(self, config_file, cloptions,
user_defaults=True, windows_restart=False, user_defaults=True, windows_restart=False,
...@@ -295,7 +290,7 @@ class Buildout(UserDict.DictMixin): ...@@ -295,7 +290,7 @@ class Buildout(UserDict.DictMixin):
# of it is to keep from migrating to 1.5 unless explicitly # of it is to keep from migrating to 1.5 unless explicitly
# requested. This lets 1.4.4 be an "aspirin release" that people can # requested. This lets 1.4.4 be an "aspirin release" that people can
# use if they are having trouble with the 1.5 releases. # use if they are having trouble with the 1.5 releases.
versions = _buildout_1_4_default_versions.copy() versions = {}
versions_section = options.get('versions') versions_section = options.get('versions')
if versions_section: if versions_section:
versions.update(dict(self[versions_section])) versions.update(dict(self[versions_section]))
...@@ -392,7 +387,7 @@ class Buildout(UserDict.DictMixin): ...@@ -392,7 +387,7 @@ class Buildout(UserDict.DictMixin):
self['buildout']['bin-directory']) self['buildout']['bin-directory'])
def _init_config(self, config_file, args): def _init_config(self, config_file, args):
print 'Creating %r.' % config_file print_('Creating %r.' % config_file)
f = open(config_file, 'w') f = open(config_file, 'w')
sep = re.compile(r'[\\/]') sep = re.compile(r'[\\/]')
if args: if args:
...@@ -477,11 +472,11 @@ class Buildout(UserDict.DictMixin): ...@@ -477,11 +472,11 @@ class Buildout(UserDict.DictMixin):
if self._log_level < logging.DEBUG: if self._log_level < logging.DEBUG:
sections = list(self) sections = list(self)
sections.sort() sections.sort()
print print_()
print 'Configuration data:' print_('Configuration data:')
for section in self._data: for section in self._data:
_save_options(section, self[section], sys.stdout) _save_options(section, self[section], sys.stdout)
print print_()
# compute new part recipe signatures # compute new part recipe signatures
...@@ -628,7 +623,7 @@ class Buildout(UserDict.DictMixin): ...@@ -628,7 +623,7 @@ class Buildout(UserDict.DictMixin):
installed = self['buildout']['installed'] installed = self['buildout']['installed']
f = open(installed, 'a') f = open(installed, 'a')
f.write('\n[buildout]\n') f.write('\n[buildout]\n')
for option, value in buildout_options.items(): for option, value in list(buildout_options.items()):
_save_option(option, value, f) _save_option(option, value, f)
f.close() f.close()
...@@ -644,7 +639,7 @@ class Buildout(UserDict.DictMixin): ...@@ -644,7 +639,7 @@ class Buildout(UserDict.DictMixin):
recipe, 'zc.buildout.uninstall', entry, self) recipe, 'zc.buildout.uninstall', entry, self)
self._logger.info('Running uninstall recipe.') self._logger.info('Running uninstall recipe.')
uninstaller(part, installed_part_options[part]) uninstaller(part, installed_part_options[part])
except (ImportError, pkg_resources.DistributionNotFound), v: except (ImportError, pkg_resources.DistributionNotFound):
pass pass
# remove created files and directories # remove created files and directories
...@@ -734,17 +729,15 @@ class Buildout(UserDict.DictMixin): ...@@ -734,17 +729,15 @@ class Buildout(UserDict.DictMixin):
def _read_installed_part_options(self): def _read_installed_part_options(self):
old = self['buildout']['installed'] old = self['buildout']['installed']
if old and os.path.isfile(old): if old and os.path.isfile(old):
parser = ConfigParser.RawConfigParser() with open(old) as fp:
parser.optionxform = lambda s: s sections = zc.buildout.configparser.parse(fp, old)
parser.read(old)
result = {} result = {}
for section in parser.sections(): for section, options in sections.items():
options = {} for option, value in options.items():
for option, value in parser.items(section):
if '%(' in value: if '%(' in value:
for k, v in _spacey_defaults: for k, v in _spacey_defaults:
value = value.replace(k, v) value = value.replace(k, v)
options[option] = value options[option] = value
result[section] = Options(self, section, options) result[section] = Options(self, section, options)
return result, True return result, True
...@@ -784,7 +777,7 @@ class Buildout(UserDict.DictMixin): ...@@ -784,7 +777,7 @@ class Buildout(UserDict.DictMixin):
installed = recipe_class(self, part, options).install() installed = recipe_class(self, part, options).install()
if installed is None: if installed is None:
installed = [] installed = []
elif isinstance(installed, basestring): elif isinstance(installed, str):
installed = [installed] installed = [installed]
base = self._buildout_path('') base = self._buildout_path('')
installed = [d.startswith(base) and d[len(base):] or d installed = [d.startswith(base) and d[len(base):] or d
...@@ -799,7 +792,7 @@ class Buildout(UserDict.DictMixin): ...@@ -799,7 +792,7 @@ class Buildout(UserDict.DictMixin):
f = open(installed, 'w') f = open(installed, 'w')
_save_options('buildout', installed_options['buildout'], f) _save_options('buildout', installed_options['buildout'], f)
for part in installed_options['buildout']['parts'].split(): for part in installed_options['buildout']['parts'].split():
print >>f print_(file=f)
_save_options(part, installed_options[part], f) _save_options(part, installed_options[part], f)
f.close() f.close()
...@@ -808,7 +801,7 @@ class Buildout(UserDict.DictMixin): ...@@ -808,7 +801,7 @@ class Buildout(UserDict.DictMixin):
def _setup_socket_timeout(self): def _setup_socket_timeout(self):
timeout = self['buildout']['socket-timeout'] timeout = self['buildout']['socket-timeout']
if timeout <> '': if timeout != '':
try: try:
timeout = int(timeout) timeout = int(timeout)
import socket import socket
...@@ -901,7 +894,7 @@ class Buildout(UserDict.DictMixin): ...@@ -901,7 +894,7 @@ class Buildout(UserDict.DictMixin):
return return
if sys.platform == 'win32' and not self.__windows_restart: if sys.platform == 'win32' and not self.__windows_restart:
args = map(zc.buildout.easy_install._safe_arg, sys.argv) args = list(map(zc.buildout.easy_install._safe_arg, sys.argv))
args.insert(1, '-W') args.insert(1, '-W')
if not __debug__: if not __debug__:
args.insert(0, '-O') args.insert(0, '-O')
...@@ -986,12 +979,12 @@ class Buildout(UserDict.DictMixin): ...@@ -986,12 +979,12 @@ class Buildout(UserDict.DictMixin):
fd, tsetup = tempfile.mkstemp() fd, tsetup = tempfile.mkstemp()
try: try:
os.write(fd, zc.buildout.easy_install.runsetup_template % dict( os.write(fd, (zc.buildout.easy_install.runsetup_template % dict(
distribute=pkg_resources_loc, distribute=pkg_resources_loc,
setupdir=os.path.dirname(setup), setupdir=os.path.dirname(setup),
setup=setup, setup=setup,
__file__ = setup, __file__ = setup,
)) )).encode())
args = [sys.executable, tsetup] + args args = [sys.executable, tsetup] + args
if no_site: if no_site:
args.insert(1, '-S') args.insert(1, '-S')
...@@ -1029,11 +1022,14 @@ class Buildout(UserDict.DictMixin): ...@@ -1029,11 +1022,14 @@ class Buildout(UserDict.DictMixin):
raise NotImplementedError('__delitem__') raise NotImplementedError('__delitem__')
def keys(self): def keys(self):
return self._raw.keys() return list(self._raw.keys())
def __iter__(self): def __iter__(self):
return iter(self._raw) return iter(self._raw)
def __len__(self):
return len(self._raw)
def _install_and_load(spec, group, entry, buildout): def _install_and_load(spec, group, entry, buildout):
__doing__ = 'Loading recipe %r.', spec __doing__ = 'Loading recipe %r.', spec
...@@ -1066,14 +1062,15 @@ def _install_and_load(spec, group, entry, buildout): ...@@ -1066,14 +1062,15 @@ def _install_and_load(spec, group, entry, buildout):
return pkg_resources.load_entry_point( return pkg_resources.load_entry_point(
req.project_name, group, entry) req.project_name, group, entry)
except Exception, v: except Exception:
v = sys.exc_info()[1]
buildout._logger.log( buildout._logger.log(
1, 1,
"Could't load %s entry point %s\nfrom %s:\n%s.", "Could't load %s entry point %s\nfrom %s:\n%s.",
group, entry, spec, v) group, entry, spec, v)
raise raise
class Options(UserDict.DictMixin): class Options(DictMixin):
def __init__(self, buildout, section, data): def __init__(self, buildout, section, data):
self.buildout = buildout self.buildout = buildout
...@@ -1090,7 +1087,7 @@ class Options(UserDict.DictMixin): ...@@ -1090,7 +1087,7 @@ class Options(UserDict.DictMixin):
self._raw = self._do_extend_raw(name, self._raw, []) self._raw = self._do_extend_raw(name, self._raw, [])
# force substitutions # force substitutions
for k, v in self._raw.items(): for k, v in list(self._raw.items()):
if '${' in v: if '${' in v:
self._dosub(k, v) self._dosub(k, v)
...@@ -1241,12 +1238,18 @@ class Options(UserDict.DictMixin): ...@@ -1241,12 +1238,18 @@ class Options(UserDict.DictMixin):
elif key in self._data: elif key in self._data:
del self._data[key] del self._data[key]
else: else:
raise KeyError, key raise KeyError(key)
def keys(self): def keys(self):
raw = self._raw raw = self._raw
return list(self._raw) + [k for k in self._data if k not in raw] return list(self._raw) + [k for k in self._data if k not in raw]
def __iter__(self):
return iter(self.keys())
def __len__(self):
return len(self.keys())
def copy(self): def copy(self):
result = self._raw.copy() result = self._raw.copy()
result.update(self._cooked) result.update(self._cooked)
...@@ -1317,11 +1320,11 @@ def _save_option(option, value, f): ...@@ -1317,11 +1320,11 @@ def _save_option(option, value, f):
value = '%(__buildout_space_n__)s' + value[2:] value = '%(__buildout_space_n__)s' + value[2:]
if value.endswith('\n\t'): if value.endswith('\n\t'):
value = value[:-2] + '%(__buildout_space_n__)s' value = value[:-2] + '%(__buildout_space_n__)s'
print >>f, option, '=', value print_(option, '=', value, file=f)
def _save_options(section, options, f): def _save_options(section, options, f):
print >>f, '[%s]' % section print_('[%s]' % section, file=f)
items = options.items() items = list(options.items())
items.sort() items.sort()
for option, value in items: for option, value in items:
_save_option(option, value, f) _save_option(option, value, f)
...@@ -1374,25 +1377,17 @@ def _open(base, filename, seen, dl_options, override, downloaded): ...@@ -1374,25 +1377,17 @@ def _open(base, filename, seen, dl_options, override, downloaded):
root_config_file = not seen root_config_file = not seen
seen.append(filename) seen.append(filename)
result = {} result = zc.buildout.configparser.parse(fp, filename)
fp.close()
parser = ConfigParser.RawConfigParser()
parser.optionxform = lambda s: s
parser.readfp(fp)
if is_temp: if is_temp:
fp.close()
os.remove(path) os.remove(path)
extends = None options = result.get('buildout', {})
for section in parser.sections(): extends = options.pop('extends', None)
options = dict(parser.items(section)) if 'extended-by' in options:
if section == 'buildout': raise zc.buildout.UserError(
extends = options.pop('extends', extends) 'No-longer supported "extended-by" option found in %s.' %
if 'extended-by' in options: filename)
raise zc.buildout.UserError(
'No-longer supported "extended-by" option found in %s.' %
filename)
result[section] = options
result = _annotate(result, filename) result = _annotate(result, filename)
...@@ -1425,11 +1420,11 @@ def _dir_hash(dir): ...@@ -1425,11 +1420,11 @@ def _dir_hash(dir):
if (not (f.endswith('pyc') or f.endswith('pyo')) if (not (f.endswith('pyc') or f.endswith('pyo'))
and os.path.exists(os.path.join(dirpath, f))) and os.path.exists(os.path.join(dirpath, f)))
] ]
hash.update(' '.join(dirnames)) hash.update(' '.join(dirnames).encode())
hash.update(' '.join(filenames)) hash.update(' '.join(filenames).encode())
for name in filenames: for name in filenames:
hash.update(open(os.path.join(dirpath, name)).read()) hash.update(open(os.path.join(dirpath, name), 'rb').read())
_dir_hashes[dir] = dir_hash = hash.digest().encode('base64').strip() _dir_hashes[dir] = dir_hash = hash.hexdigest()
return dir_hash return dir_hash
def _dists_sig(dists): def _dists_sig(dists):
...@@ -1444,7 +1439,7 @@ def _dists_sig(dists): ...@@ -1444,7 +1439,7 @@ def _dists_sig(dists):
def _update_section(s1, s2): def _update_section(s1, s2):
s2 = s2.copy() # avoid mutating the second argument, which is unexpected s2 = s2.copy() # avoid mutating the second argument, which is unexpected
for k, v in s2.items(): for k, v in list(s2.items()):
v2, note2 = v v2, note2 = v
if k.endswith('+'): if k.endswith('+'):
key = k.rstrip(' +') key = k.rstrip(' +')
...@@ -1631,7 +1626,7 @@ Commands: ...@@ -1631,7 +1626,7 @@ Commands:
""" """
def _help(): def _help():
print _usage print_(_usage)
sys.exit(0) sys.exit(0)
def main(args=None): def main(args=None):
...@@ -1728,7 +1723,8 @@ def main(args=None): ...@@ -1728,7 +1723,8 @@ def main(args=None):
getattr(buildout, command)(args) getattr(buildout, command)(args)
except SystemExit: except SystemExit:
pass pass
except Exception, v: except Exception:
v = sys.exc_info()[1]
_doing() _doing()
exc_info = sys.exc_info() exc_info = sys.exc_info()
import pdb, traceback import pdb, traceback
...@@ -1738,7 +1734,7 @@ def main(args=None): ...@@ -1738,7 +1734,7 @@ def main(args=None):
pdb.post_mortem(exc_info[2]) pdb.post_mortem(exc_info[2])
else: else:
if isinstance(v, (zc.buildout.UserError, if isinstance(v, (zc.buildout.UserError,
distutils.errors.DistutilsError, distutils.errors.DistutilsError
) )
): ):
_error(str(v)) _error(str(v))
......
...@@ -284,7 +284,7 @@ buildout: ...@@ -284,7 +284,7 @@ buildout:
>>> import os >>> import os
>>> os.chdir(sample_buildout) >>> os.chdir(sample_buildout)
>>> buildout = os.path.join(sample_buildout, 'bin', 'buildout') >>> buildout = os.path.join(sample_buildout, 'bin', 'buildout')
>>> print system(buildout), >>> print_(system(buildout), end='')
Develop: '/sample-buildout/recipes' Develop: '/sample-buildout/recipes'
Installing data-dir. Installing data-dir.
data-dir: Creating directory mystuff data-dir: Creating directory mystuff
...@@ -333,7 +333,7 @@ we'll see that the directory gets removed and recreated: ...@@ -333,7 +333,7 @@ we'll see that the directory gets removed and recreated:
... path = mydata ... path = mydata
... """) ... """)
>>> print system(buildout), >>> print_(system(buildout), end='')
Develop: '/sample-buildout/recipes' Develop: '/sample-buildout/recipes'
Uninstalling data-dir. Uninstalling data-dir.
Installing data-dir. Installing data-dir.
...@@ -353,7 +353,7 @@ If any of the files or directories created by a recipe are removed, ...@@ -353,7 +353,7 @@ If any of the files or directories created by a recipe are removed,
the part will be reinstalled: the part will be reinstalled:
>>> rmdir(sample_buildout, 'mydata') >>> rmdir(sample_buildout, 'mydata')
>>> print system(buildout), >>> print_(system(buildout), end='')
Develop: '/sample-buildout/recipes' Develop: '/sample-buildout/recipes'
Uninstalling data-dir. Uninstalling data-dir.
Installing data-dir. Installing data-dir.
...@@ -384,7 +384,7 @@ non-existent directory to create the directory in: ...@@ -384,7 +384,7 @@ non-existent directory to create the directory in:
We'll get a user error, not a traceback. We'll get a user error, not a traceback.
>>> print system(buildout), >>> print_(system(buildout), end='')
Develop: '/sample-buildout/recipes' Develop: '/sample-buildout/recipes'
data-dir: Cannot create /xxx/mydata. /xxx is not a directory. data-dir: Cannot create /xxx/mydata. /xxx is not a directory.
While: While:
...@@ -449,7 +449,7 @@ leave previously created paths in place: ...@@ -449,7 +449,7 @@ leave previously created paths in place:
... path = foo bin ... path = foo bin
... """) ... """)
>>> print system(buildout), # doctest: +ELLIPSIS >>> print_(system(buildout)) # doctest: +ELLIPSIS
Develop: '/sample-buildout/recipes' Develop: '/sample-buildout/recipes'
Uninstalling data-dir. Uninstalling data-dir.
Installing data-dir. Installing data-dir.
...@@ -483,7 +483,7 @@ If we fix the typo: ...@@ -483,7 +483,7 @@ If we fix the typo:
... path = foo bins ... path = foo bins
... """) ... """)
>>> print system(buildout), # doctest: +ELLIPSIS >>> print_(system(buildout)) # doctest: +ELLIPSIS
Develop: '/sample-buildout/recipes' Develop: '/sample-buildout/recipes'
Installing data-dir. Installing data-dir.
data-dir: Creating directory foo data-dir: Creating directory foo
...@@ -565,7 +565,7 @@ And put back the typo: ...@@ -565,7 +565,7 @@ And put back the typo:
When we rerun the buildout: When we rerun the buildout:
>>> print system(buildout), # doctest: +ELLIPSIS >>> print_(system(buildout)) # doctest: +ELLIPSIS
Develop: '/sample-buildout/recipes' Develop: '/sample-buildout/recipes'
Installing data-dir. Installing data-dir.
data-dir: Creating directory foo data-dir: Creating directory foo
...@@ -638,7 +638,12 @@ recipe: ...@@ -638,7 +638,12 @@ recipe:
.. ..
>>> remove(sample_buildout, 'recipes', 'mkdir.pyc') >>> for path in (
... join(sample_buildout, 'recipes', 'mkdir.pyc'),
... join(sample_buildout, 'recipes', '__pycache__', 'mkdir.pyc'),
... ):
... if os.path.exists(path):
... remove(path)
We returned by calling created, taking advantage of the fact that it We returned by calling created, taking advantage of the fact that it
returns the registered paths. We did this for illustrative purposes. returns the registered paths. We did this for illustrative purposes.
...@@ -647,7 +652,7 @@ It would be simpler just to return the paths as before. ...@@ -647,7 +652,7 @@ It would be simpler just to return the paths as before.
If we rerun the buildout, again, we'll get the error and no If we rerun the buildout, again, we'll get the error and no
directories will be created: directories will be created:
>>> print system(buildout), # doctest: +ELLIPSIS >>> print_(system(buildout)) # doctest: +ELLIPSIS
Develop: '/sample-buildout/recipes' Develop: '/sample-buildout/recipes'
Installing data-dir. Installing data-dir.
data-dir: Creating directory foo data-dir: Creating directory foo
...@@ -677,7 +682,7 @@ Now, we'll fix the typo again and we'll get the directories we expect: ...@@ -677,7 +682,7 @@ Now, we'll fix the typo again and we'll get the directories we expect:
... path = foo bins ... path = foo bins
... """) ... """)
>>> print system(buildout), >>> print_(system(buildout), end='')
Develop: '/sample-buildout/recipes' Develop: '/sample-buildout/recipes'
Installing data-dir. Installing data-dir.
data-dir: Creating directory foo data-dir: Creating directory foo
...@@ -724,7 +729,7 @@ all key-value pairs are displayed, sorted alphabetically, along with ...@@ -724,7 +729,7 @@ all key-value pairs are displayed, sorted alphabetically, along with
the origin of the value (file name or COMPUTED_VALUE, DEFAULT_VALUE, the origin of the value (file name or COMPUTED_VALUE, DEFAULT_VALUE,
COMMAND_LINE_VALUE). COMMAND_LINE_VALUE).
>>> print system(buildout+ ' annotate'), >>> print_(system(buildout+ ' annotate'), end='')
... # doctest: +ELLIPSIS +NORMALIZE_WHITESPACE ... # doctest: +ELLIPSIS +NORMALIZE_WHITESPACE
<BLANKLINE> <BLANKLINE>
Annotated sections Annotated sections
...@@ -790,6 +795,7 @@ allow us to see interactions with the buildout: ...@@ -790,6 +795,7 @@ allow us to see interactions with the buildout:
>>> write(sample_buildout, 'recipes', 'debug.py', >>> write(sample_buildout, 'recipes', 'debug.py',
... """ ... """
... import sys
... class Debug: ... class Debug:
... ...
... def __init__(self, buildout, name, options): ... def __init__(self, buildout, name, options):
...@@ -798,10 +804,8 @@ allow us to see interactions with the buildout: ...@@ -798,10 +804,8 @@ allow us to see interactions with the buildout:
... self.options = options ... self.options = options
... ...
... def install(self): ... def install(self):
... items = self.options.items() ... for option, value in sorted(self.options.items()):
... items.sort() ... sys.stdout.write('%s %s\\n' % (option, value))
... for option, value in items:
... print option, value
... return () ... return ()
... ...
... update = install ... update = install
...@@ -857,7 +861,7 @@ and option name joined by a colon. ...@@ -857,7 +861,7 @@ and option name joined by a colon.
Now, if we run the buildout, we'll see the options with the values Now, if we run the buildout, we'll see the options with the values
substituted. substituted.
>>> print system(buildout), >>> print_(system(buildout), end='')
Develop: '/sample-buildout/recipes' Develop: '/sample-buildout/recipes'
Uninstalling data-dir. Uninstalling data-dir.
Installing data-dir. Installing data-dir.
...@@ -876,7 +880,7 @@ The buildout system didn't know if this module could effect the mkdir ...@@ -876,7 +880,7 @@ The buildout system didn't know if this module could effect the mkdir
recipe, so it assumed it could and reinstalled mydata. If we rerun recipe, so it assumed it could and reinstalled mydata. If we rerun
the buildout: the buildout:
>>> print system(buildout), >>> print_(system(buildout), end='')
Develop: '/sample-buildout/recipes' Develop: '/sample-buildout/recipes'
Updating data-dir. Updating data-dir.
Updating debug. Updating debug.
...@@ -915,7 +919,7 @@ _buildout_section_name_ to get the current section name. ...@@ -915,7 +919,7 @@ _buildout_section_name_ to get the current section name.
... path = mydata ... path = mydata
... """) ... """)
>>> print system(buildout), >>> print_(system(buildout), end='')
Develop: '/sample-buildout/recipes' Develop: '/sample-buildout/recipes'
Uninstalling debug. Uninstalling debug.
Updating data-dir. Updating data-dir.
...@@ -953,7 +957,7 @@ example, we can leave data-dir out of the parts list: ...@@ -953,7 +957,7 @@ example, we can leave data-dir out of the parts list:
It will still be treated as a part: It will still be treated as a part:
>>> print system(buildout), >>> print_(system(buildout), end='')
Develop: '/sample-buildout/recipes' Develop: '/sample-buildout/recipes'
Uninstalling debug. Uninstalling debug.
Updating data-dir. Updating data-dir.
...@@ -992,7 +996,7 @@ the data-dir part after the debug part, it will be included before: ...@@ -992,7 +996,7 @@ the data-dir part after the debug part, it will be included before:
It will still be treated as a part: It will still be treated as a part:
>>> print system(buildout), >>> print_(system(buildout), end='')
Develop: '/sample-buildout/recipes' Develop: '/sample-buildout/recipes'
Updating data-dir. Updating data-dir.
Updating debug. Updating debug.
...@@ -1041,7 +1045,7 @@ of the current section allows sections to be used as macros. ...@@ -1041,7 +1045,7 @@ of the current section allows sections to be used as macros.
... path = mydata ... path = mydata
... """) ... """)
>>> print system(buildout), >>> print_(system(buildout), end='')
Develop: '/sample-buildout/recipes' Develop: '/sample-buildout/recipes'
Uninstalling debug. Uninstalling debug.
Uninstalling data-dir. Uninstalling data-dir.
...@@ -1132,9 +1136,11 @@ extension that prints out the options. ...@@ -1132,9 +1136,11 @@ extension that prints out the options.
>>> mkdir(sample_buildout, 'demo') >>> mkdir(sample_buildout, 'demo')
>>> write(sample_buildout, 'demo', 'demo.py', >>> write(sample_buildout, 'demo', 'demo.py',
... """ ... """
... import sys
... def ext(buildout): ... def ext(buildout):
... print [part['option'] for name, part in buildout.items() \ ... sys.stdout.write(str(
... if name.startswith('part')] ... [part['option'] for name, part in buildout.items()
... if name.startswith('part')])+'\\n')
... """) ... """)
>>> write(sample_buildout, 'demo', 'setup.py', >>> write(sample_buildout, 'demo', 'setup.py',
...@@ -1157,13 +1163,9 @@ Set up a buildout configuration for this extension. ...@@ -1157,13 +1163,9 @@ Set up a buildout configuration for this extension.
... """) ... """)
>>> os.chdir(sample_buildout) >>> os.chdir(sample_buildout)
>>> print system(os.path.join(sample_buildout, 'bin', 'buildout')), >>> print_(system(os.path.join(sample_buildout, 'bin', 'buildout')), end='')
Develop: '/sample-buildout/demo' ... # doctest: +ELLIPSIS
Uninstalling myfiles. Develop: '/sample-buildout/demo'...
Getting distribution for 'recipes'.
zip_safe flag not set; analyzing archive contents...
Got recipes 0.0.0.
warning: install_lib: 'build/lib' does not exist -- no Python modules to install
Verify option values. Verify option values.
...@@ -1175,14 +1177,14 @@ Verify option values. ...@@ -1175,14 +1177,14 @@ Verify option values.
... extends = extension2.cfg ... extends = extension2.cfg
... """) ... """)
>>> print system(os.path.join('bin', 'buildout')), >>> print_(system(os.path.join('bin', 'buildout')), end='')
['a1 a2/na3 a4/na5', 'b1 b2 b3 b4', 'c1 c2/nc3 c4 c5', 'h1 h2'] ['a1 a2/na3 a4/na5', 'b1 b2 b3 b4', 'c1 c2/nc3 c4 c5', 'h1 h2']
Develop: '/sample-buildout/demo' Develop: '/sample-buildout/demo'
Annotated sections output shows which files are responsible for which Annotated sections output shows which files are responsible for which
operations. operations.
>>> print system(os.path.join('bin', 'buildout') + ' annotate'), >>> print_(system(os.path.join('bin', 'buildout') + ' annotate'), end='')
... # doctest: +ELLIPSIS +NORMALIZE_WHITESPACE ... # doctest: +ELLIPSIS +NORMALIZE_WHITESPACE
<BLANKLINE> <BLANKLINE>
Annotated sections Annotated sections
...@@ -1258,7 +1260,7 @@ To see how this works, we use an example: ...@@ -1258,7 +1260,7 @@ To see how this works, we use an example:
... op = base ... op = base
... """) ... """)
>>> print system(buildout), >>> print_(system(buildout), end='')
Develop: '/sample-buildout/recipes' Develop: '/sample-buildout/recipes'
Installing debug. Installing debug.
op buildout op buildout
...@@ -1328,7 +1330,7 @@ Here is a more elaborate example. ...@@ -1328,7 +1330,7 @@ Here is a more elaborate example.
... name = base ... name = base
... """) ... """)
>>> print system(buildout), >>> print_(system(buildout), end='')
Develop: '/sample-buildout/recipes' Develop: '/sample-buildout/recipes'
Uninstalling debug. Uninstalling debug.
Installing debug. Installing debug.
...@@ -1390,7 +1392,7 @@ we'll set up a web server with some configuration files. ...@@ -1390,7 +1392,7 @@ we'll set up a web server with some configuration files.
... """ % dict(url=server_url)) ... """ % dict(url=server_url))
>>> print system(buildout+ ' -c client.cfg'), >>> print_(system(buildout+ ' -c client.cfg'), end='')
Develop: '/sample-buildout/recipes' Develop: '/sample-buildout/recipes'
Uninstalling debug. Uninstalling debug.
Installing debug. Installing debug.
...@@ -1421,7 +1423,7 @@ buildout. ...@@ -1421,7 +1423,7 @@ buildout.
... name = remote ... name = remote
... """) ... """)
>>> print system(buildout + ' -c ' + server_url + '/remote.cfg'), >>> print_(system(buildout + ' -c ' + server_url + '/remote.cfg'), end='')
While: While:
Initializing. Initializing.
Error: Missing option: buildout:directory Error: Missing option: buildout:directory
...@@ -1431,10 +1433,10 @@ containing a configuration file. This won't work for configuration ...@@ -1431,10 +1433,10 @@ containing a configuration file. This won't work for configuration
files loaded from URLs. In this case, the buildout directory would files loaded from URLs. In this case, the buildout directory would
normally be defined on the command line: normally be defined on the command line:
>>> print system(buildout >>> print_(system(buildout
... + ' -c ' + server_url + '/remote.cfg' ... + ' -c ' + server_url + '/remote.cfg'
... + ' buildout:directory=' + sample_buildout ... + ' buildout:directory=' + sample_buildout
... ), ... ), end='')
Develop: '/sample-buildout/recipes' Develop: '/sample-buildout/recipes'
Uninstalling debug. Uninstalling debug.
Installing debug. Installing debug.
...@@ -1463,7 +1465,7 @@ delimiter.) ...@@ -1463,7 +1465,7 @@ delimiter.)
... """) ... """)
>>> os.environ['HOME'] = home >>> os.environ['HOME'] = home
>>> print system(buildout), >>> print_(system(buildout), end='')
Develop: '/sample-buildout/recipes' Develop: '/sample-buildout/recipes'
Uninstalling debug. Uninstalling debug.
Installing debug. Installing debug.
...@@ -1480,7 +1482,7 @@ delimiter.) ...@@ -1480,7 +1482,7 @@ delimiter.)
A buildout command-line argument, -U, can be used to suppress reading A buildout command-line argument, -U, can be used to suppress reading
user defaults: user defaults:
>>> print system(buildout + ' -U'), >>> print_(system(buildout + ' -U'), end='')
Develop: '/sample-buildout/recipes' Develop: '/sample-buildout/recipes'
Uninstalling debug. Uninstalling debug.
Installing debug. Installing debug.
...@@ -1509,7 +1511,7 @@ set the logging level to WARNING ...@@ -1509,7 +1511,7 @@ set the logging level to WARNING
... extends = b1.cfg b2.cfg ... extends = b1.cfg b2.cfg
... """) ... """)
>>> print system(buildout), >>> print_(system(buildout), end='')
name base name base
op1 b1 1 op1 b1 1
op2 b2 2 op2 b2 2
...@@ -1534,7 +1536,7 @@ configured in the buildout section. Its value is configured in seconds. ...@@ -1534,7 +1536,7 @@ configured in the buildout section. Its value is configured in seconds.
... op = timeout ... op = timeout
... """) ... """)
>>> print system(buildout), >>> print_(system(buildout), end='')
Setting socket time out to 5 seconds. Setting socket time out to 5 seconds.
Develop: '/sample-buildout/recipes' Develop: '/sample-buildout/recipes'
Uninstalling debug. Uninstalling debug.
...@@ -1557,7 +1559,7 @@ timeout of the Python socket module is used. ...@@ -1557,7 +1559,7 @@ timeout of the Python socket module is used.
... op = timeout ... op = timeout
... """) ... """)
>>> print system(buildout), >>> print_(system(buildout), end='')
Default socket timeout is used ! Default socket timeout is used !
Value in configuration is not numeric: [5s]. Value in configuration is not numeric: [5s].
<BLANKLINE> <BLANKLINE>
...@@ -1594,6 +1596,7 @@ with an uninstall recipe that simulates removing the service. ...@@ -1594,6 +1596,7 @@ with an uninstall recipe that simulates removing the service.
>>> write(sample_buildout, 'recipes', 'service.py', >>> write(sample_buildout, 'recipes', 'service.py',
... """ ... """
... import sys
... class Service: ... class Service:
... ...
... def __init__(self, buildout, name, options): ... def __init__(self, buildout, name, options):
...@@ -1602,7 +1605,8 @@ with an uninstall recipe that simulates removing the service. ...@@ -1602,7 +1605,8 @@ with an uninstall recipe that simulates removing the service.
... self.options = options ... self.options = options
... ...
... def install(self): ... def install(self):
... print "chkconfig --add %s" % self.options['script'] ... sys.stdout.write("chkconfig --add %s\\n"
... % self.options['script'])
... return () ... return ()
... ...
... def update(self): ... def update(self):
...@@ -1610,7 +1614,7 @@ with an uninstall recipe that simulates removing the service. ...@@ -1610,7 +1614,7 @@ with an uninstall recipe that simulates removing the service.
... ...
... ...
... def uninstall_service(name, options): ... def uninstall_service(name, options):
... print "chkconfig --del %s" % options['script'] ... sys.stdout.write("chkconfig --del %s\\n" % options['script'])
... """) ... """)
To use these recipes we must register them using entry points. Make To use these recipes we must register them using entry points. Make
...@@ -1649,20 +1653,18 @@ Here's how these recipes could be used in a buildout: ...@@ -1649,20 +1653,18 @@ Here's how these recipes could be used in a buildout:
When the buildout is run the service will be installed When the buildout is run the service will be installed
>>> print system(buildout) >>> print_(system(buildout), end='')
Develop: '/sample-buildout/recipes' Develop: '/sample-buildout/recipes'
Uninstalling debug. Uninstalling debug.
Installing service. Installing service.
chkconfig --add /path/to/script chkconfig --add /path/to/script
<BLANKLINE>
The service has been installed. If the buildout is run again with no The service has been installed. If the buildout is run again with no
changes, the service shouldn't be changed. changes, the service shouldn't be changed.
>>> print system(buildout) >>> print_(system(buildout), end='')
Develop: '/sample-buildout/recipes' Develop: '/sample-buildout/recipes'
Updating service. Updating service.
<BLANKLINE>
Now we change the service part to trigger uninstallation and Now we change the service part to trigger uninstallation and
re-installation. re-installation.
...@@ -1678,14 +1680,13 @@ re-installation. ...@@ -1678,14 +1680,13 @@ re-installation.
... script = /path/to/a/different/script ... script = /path/to/a/different/script
... """) ... """)
>>> print system(buildout) >>> print_(system(buildout), end='')
Develop: '/sample-buildout/recipes' Develop: '/sample-buildout/recipes'
Uninstalling service. Uninstalling service.
Running uninstall recipe. Running uninstall recipe.
chkconfig --del /path/to/script chkconfig --del /path/to/script
Installing service. Installing service.
chkconfig --add /path/to/a/different/script chkconfig --add /path/to/a/different/script
<BLANKLINE>
Now we remove the service part, and add another part. Now we remove the service part, and add another part.
...@@ -1699,14 +1700,13 @@ Now we remove the service part, and add another part. ...@@ -1699,14 +1700,13 @@ Now we remove the service part, and add another part.
... recipe = recipes:debug ... recipe = recipes:debug
... """) ... """)
>>> print system(buildout) >>> print_(system(buildout), end='')
Develop: '/sample-buildout/recipes' Develop: '/sample-buildout/recipes'
Uninstalling service. Uninstalling service.
Running uninstall recipe. Running uninstall recipe.
chkconfig --del /path/to/a/different/script chkconfig --del /path/to/a/different/script
Installing debug. Installing debug.
recipe recipes:debug recipe recipes:debug
<BLANKLINE>
Uninstall recipes don't have to take care of removing all the files Uninstall recipes don't have to take care of removing all the files
and directories created by the part. This is still done automatically, and directories created by the part. This is still done automatically,
...@@ -1720,11 +1720,12 @@ mkdir recipe introduced earlier. ...@@ -1720,11 +1720,12 @@ mkdir recipe introduced earlier.
>>> write(sample_buildout, 'recipes', 'backup.py', >>> write(sample_buildout, 'recipes', 'backup.py',
... """ ... """
... import os ... import os, sys
... def backup_directory(name, options): ... def backup_directory(name, options):
... path = options['path'] ... path = options['path']
... size = len(os.listdir(path)) ... size = len(os.listdir(path))
... print "backing up directory %s of size %s" % (path, size) ... sys.stdout.write("backing up directory %s of size %s\\n"
... % (path, size))
... """) ... """)
It must be registered with the zc.buildout.uninstall entry It must be registered with the zc.buildout.uninstall entry
...@@ -1766,14 +1767,13 @@ Now we can use it with a mkdir part. ...@@ -1766,14 +1767,13 @@ Now we can use it with a mkdir part.
Run the buildout to install the part. Run the buildout to install the part.
>>> print system(buildout) >>> print_(system(buildout), end='')
Develop: '/sample-buildout/recipes' Develop: '/sample-buildout/recipes'
Uninstalling debug. Uninstalling debug.
Installing dir. Installing dir.
dir: Creating directory my_directory dir: Creating directory my_directory
Installing debug. Installing debug.
recipe recipes:debug recipe recipes:debug
<BLANKLINE>
Now we remove the part from the configuration file. Now we remove the part from the configuration file.
...@@ -1790,14 +1790,13 @@ Now we remove the part from the configuration file. ...@@ -1790,14 +1790,13 @@ Now we remove the part from the configuration file.
When the buildout is run the part is removed, and the uninstall recipe When the buildout is run the part is removed, and the uninstall recipe
is run before the directory is deleted. is run before the directory is deleted.
>>> print system(buildout) >>> print_(system(buildout), end='')
Develop: '/sample-buildout/recipes' Develop: '/sample-buildout/recipes'
Uninstalling dir. Uninstalling dir.
Running uninstall recipe. Running uninstall recipe.
backing up directory /sample-buildout/my_directory of size 0 backing up directory /sample-buildout/my_directory of size 0
Updating debug. Updating debug.
recipe recipes:debug recipe recipes:debug
<BLANKLINE>
Now we will return the registration to normal for the benefit of the Now we will return the registration to normal for the benefit of the
rest of the examples. rest of the examples.
...@@ -1895,7 +1894,7 @@ Here's an example: ...@@ -1895,7 +1894,7 @@ Here's an example:
Note that we used the installed buildout option to specify an Note that we used the installed buildout option to specify an
alternate file to store information about installed parts. alternate file to store information about installed parts.
>>> print system(buildout+' -c other.cfg debug:op1=foo -v'), >>> print_(system(buildout+' -c other.cfg debug:op1=foo -v'), end='')
Develop: '/sample-buildout/recipes' Develop: '/sample-buildout/recipes'
Installing debug. Installing debug.
name other name other
...@@ -1908,7 +1907,7 @@ WARNING. ...@@ -1908,7 +1907,7 @@ WARNING.
Options can also be combined in the usual Unix way, as in: Options can also be combined in the usual Unix way, as in:
>>> print system(buildout+' -vcother.cfg debug:op1=foo'), >>> print_(system(buildout+' -vcother.cfg debug:op1=foo'), end='')
Develop: '/sample-buildout/recipes' Develop: '/sample-buildout/recipes'
Updating debug. Updating debug.
name other name other
...@@ -1949,7 +1948,7 @@ the buildout in the usual way: ...@@ -1949,7 +1948,7 @@ the buildout in the usual way:
... recipe = recipes:debug ... recipe = recipes:debug
... """) ... """)
>>> print system(buildout), >>> print_(system(buildout), end='')
Develop: '/sample-buildout/recipes' Develop: '/sample-buildout/recipes'
Uninstalling debug. Uninstalling debug.
Installing debug. Installing debug.
...@@ -2033,7 +2032,7 @@ Now we'll update our configuration file: ...@@ -2033,7 +2032,7 @@ Now we'll update our configuration file:
and run the buildout specifying just d3 and d4: and run the buildout specifying just d3 and d4:
>>> print system(buildout+' install d3 d4'), >>> print_(system(buildout+' install d3 d4'), end='')
Develop: '/sample-buildout/recipes' Develop: '/sample-buildout/recipes'
Uninstalling d3. Uninstalling d3.
Installing d3. Installing d3.
...@@ -2104,7 +2103,7 @@ directories are still there. ...@@ -2104,7 +2103,7 @@ directories are still there.
Now, if we run the buildout without the install command: Now, if we run the buildout without the install command:
>>> print system(buildout), >>> print_(system(buildout), end='')
Develop: '/sample-buildout/recipes' Develop: '/sample-buildout/recipes'
Uninstalling d2. Uninstalling d2.
Uninstalling d1. Uninstalling d1.
...@@ -2161,7 +2160,7 @@ provide alternate locations, and even names for these directories. ...@@ -2161,7 +2160,7 @@ provide alternate locations, and even names for these directories.
... work = os.path.join(alt, 'work'), ... work = os.path.join(alt, 'work'),
... )) ... ))
>>> print system(buildout), >>> print_(system(buildout), end='')
Creating directory '/sample-alt/scripts'. Creating directory '/sample-alt/scripts'.
Creating directory '/sample-alt/work'. Creating directory '/sample-alt/work'.
Creating directory '/sample-alt/basket'. Creating directory '/sample-alt/basket'.
...@@ -2197,7 +2196,7 @@ You can also specify an alternate buildout directory: ...@@ -2197,7 +2196,7 @@ You can also specify an alternate buildout directory:
... recipes=os.path.join(sample_buildout, 'recipes'), ... recipes=os.path.join(sample_buildout, 'recipes'),
... )) ... ))
>>> print system(buildout), >>> print_(system(buildout), end='')
Creating directory '/sample-alt/bin'. Creating directory '/sample-alt/bin'.
Creating directory '/sample-alt/parts'. Creating directory '/sample-alt/parts'.
Creating directory '/sample-alt/eggs'. Creating directory '/sample-alt/eggs'.
...@@ -2249,7 +2248,7 @@ can be a numeric value and that the verbosity can be specified in the ...@@ -2249,7 +2248,7 @@ can be a numeric value and that the verbosity can be specified in the
configuration file. Because the verbosity is subtracted from the log configuration file. Because the verbosity is subtracted from the log
level, we get a final log level of 20, which is the INFO level. level, we get a final log level of 20, which is the INFO level.
>>> print system(buildout), >>> print_(system(buildout), end='')
INFO Develop: '/sample-buildout/recipes' INFO Develop: '/sample-buildout/recipes'
Predefined buildout options Predefined buildout options
...@@ -2267,7 +2266,7 @@ database is shown. ...@@ -2267,7 +2266,7 @@ database is shown.
... parts = ... parts =
... """) ... """)
>>> print system(buildout+' -vv'), # doctest: +NORMALIZE_WHITESPACE >>> print_(system(buildout+' -vv'), end='') # doctest: +NORMALIZE_WHITESPACE
Installing 'zc.buildout', 'distribute'. Installing 'zc.buildout', 'distribute'.
We have a develop egg: zc.buildout 1.0.0. We have a develop egg: zc.buildout 1.0.0.
We have the best distribution that satisfies 'distribute'. We have the best distribution that satisfies 'distribute'.
...@@ -2492,9 +2491,9 @@ local buildout scripts. ...@@ -2492,9 +2491,9 @@ local buildout scripts.
>>> sample_bootstrapped = tmpdir('sample-bootstrapped') >>> sample_bootstrapped = tmpdir('sample-bootstrapped')
>>> print system(buildout >>> print_(system(buildout
... +' -c'+os.path.join(sample_bootstrapped, 'setup.cfg') ... +' -c'+os.path.join(sample_bootstrapped, 'setup.cfg')
... +' init'), ... +' init'), end='')
Creating '/sample-bootstrapped/setup.cfg'. Creating '/sample-bootstrapped/setup.cfg'.
Creating directory '/sample-bootstrapped/bin'. Creating directory '/sample-bootstrapped/bin'.
Creating directory '/sample-bootstrapped/parts'. Creating directory '/sample-bootstrapped/parts'.
...@@ -2541,9 +2540,9 @@ if there isn't a configuration file: ...@@ -2541,9 +2540,9 @@ if there isn't a configuration file:
>>> sample_bootstrapped2 = tmpdir('sample-bootstrapped2') >>> sample_bootstrapped2 = tmpdir('sample-bootstrapped2')
>>> print system(buildout >>> print_(system(buildout
... +' -c'+os.path.join(sample_bootstrapped2, 'setup.cfg') ... +' -c'+os.path.join(sample_bootstrapped2, 'setup.cfg')
... +' bootstrap'), ... +' bootstrap'), end='')
While: While:
Initializing. Initializing.
Error: Couldn't open /sample-bootstrapped2/setup.cfg Error: Couldn't open /sample-bootstrapped2/setup.cfg
...@@ -2554,9 +2553,9 @@ if there isn't a configuration file: ...@@ -2554,9 +2553,9 @@ if there isn't a configuration file:
... parts = ... parts =
... """) ... """)
>>> print system(buildout >>> print_(system(buildout
... +' -c'+os.path.join(sample_bootstrapped2, 'setup.cfg') ... +' -c'+os.path.join(sample_bootstrapped2, 'setup.cfg')
... +' bootstrap'), ... +' bootstrap'), end='')
Creating directory '/sample-bootstrapped2/bin'. Creating directory '/sample-bootstrapped2/bin'.
Creating directory '/sample-bootstrapped2/parts'. Creating directory '/sample-bootstrapped2/parts'.
Creating directory '/sample-bootstrapped2/eggs'. Creating directory '/sample-bootstrapped2/eggs'.
...@@ -2567,9 +2566,9 @@ Similarly, if there is a configuration file and we use the init ...@@ -2567,9 +2566,9 @@ Similarly, if there is a configuration file and we use the init
command, we'll get an error that the configuration file already command, we'll get an error that the configuration file already
exists: exists:
>>> print system(buildout >>> print_(system(buildout
... +' -c'+os.path.join(sample_bootstrapped, 'setup.cfg') ... +' -c'+os.path.join(sample_bootstrapped, 'setup.cfg')
... +' init'), ... +' init'), end='')
While: While:
Initializing. Initializing.
Error: '/sample-bootstrapped/setup.cfg' already exists. Error: '/sample-bootstrapped/setup.cfg' already exists.
...@@ -2583,7 +2582,7 @@ or paths to use: ...@@ -2583,7 +2582,7 @@ or paths to use:
>>> cd(sample_bootstrapped) >>> cd(sample_bootstrapped)
>>> remove('setup.cfg') >>> remove('setup.cfg')
>>> remove('bin', 'buildout') >>> remove('bin', 'buildout')
>>> print system(buildout + ' -csetup.cfg init demo other ./src'), >>> print_(system(buildout + ' -csetup.cfg init demo other ./src'), end='')
Creating '/sample-bootstrapped/setup.cfg'. Creating '/sample-bootstrapped/setup.cfg'.
Generated script '/sample-bootstrapped/bin/buildout'. Generated script '/sample-bootstrapped/bin/buildout'.
Getting distribution for 'zc.recipe.egg'. Getting distribution for 'zc.recipe.egg'.
...@@ -2642,7 +2641,7 @@ for us: ...@@ -2642,7 +2641,7 @@ for us:
>>> cd(sample_bootstrapped) >>> cd(sample_bootstrapped)
>>> _ = system(buildout + ' -csetup.cfg buildout:parts=') >>> _ = system(buildout + ' -csetup.cfg buildout:parts=')
>>> remove('setup.cfg') >>> remove('setup.cfg')
>>> print system(buildout + ' -csetup.cfg init demo other ./src'), >>> print_(system(buildout + ' -csetup.cfg init demo other ./src'), end='')
Creating '/sample-bootstrapped/setup.cfg'. Creating '/sample-bootstrapped/setup.cfg'.
Installing py. Installing py.
Generated script '/sample-bootstrapped/bin/demo'. Generated script '/sample-bootstrapped/bin/demo'.
...@@ -2692,7 +2691,7 @@ or on the command line: ...@@ -2692,7 +2691,7 @@ or on the command line:
... recipe = recipes:debug ... recipe = recipes:debug
... """) ... """)
>>> print system(buildout+' buildout:installed=inst.cfg'), >>> print_(system(buildout+' buildout:installed=inst.cfg'), end='')
Develop: '/sample-buildout/recipes' Develop: '/sample-buildout/recipes'
Installing debug. Installing debug.
recipe recipes:debug recipe recipes:debug
...@@ -2714,7 +2713,7 @@ The installation database can be disabled by supplying an empty ...@@ -2714,7 +2713,7 @@ The installation database can be disabled by supplying an empty
buildout installed option: buildout installed option:
>>> os.remove('inst.cfg') >>> os.remove('inst.cfg')
>>> print system(buildout+' buildout:installed='), >>> print_(system(buildout+' buildout:installed='), end='')
Develop: '/sample-buildout/recipes' Develop: '/sample-buildout/recipes'
Installing debug. Installing debug.
recipe recipes:debug recipe recipes:debug
...@@ -2740,7 +2739,7 @@ Note that there will be no installation database if there are no parts: ...@@ -2740,7 +2739,7 @@ Note that there will be no installation database if there are no parts:
... parts = ... parts =
... """) ... """)
>>> print system(buildout+' buildout:installed=inst.cfg'), >>> print_(system(buildout+' buildout:installed=inst.cfg'), end='')
>>> ls(sample_buildout) >>> ls(sample_buildout)
- b1.cfg - b1.cfg
...@@ -2776,10 +2775,11 @@ previous section: ...@@ -2776,10 +2775,11 @@ previous section:
>>> write(sample_bootstrapped, 'demo', 'demo.py', >>> write(sample_bootstrapped, 'demo', 'demo.py',
... """ ... """
... import sys
... def ext(buildout): ... def ext(buildout):
... print 'ext', list(buildout) ... sys.stdout.write('%s %s\\n' % ('ext', list(buildout)))
... def unload(buildout): ... def unload(buildout):
... print 'unload', list(buildout) ... sys.stdout.write('%s %s\\n' % ('unload', list(buildout)))
... """) ... """)
>>> write(sample_bootstrapped, 'demo', 'setup.py', >>> write(sample_bootstrapped, 'demo', 'setup.py',
...@@ -2809,7 +2809,8 @@ egg to be built: ...@@ -2809,7 +2809,8 @@ egg to be built:
... """) ... """)
>>> os.chdir(sample_bootstrapped) >>> os.chdir(sample_bootstrapped)
>>> print system(os.path.join(sample_bootstrapped, 'bin', 'buildout')), >>> print_(system(os.path.join(sample_bootstrapped, 'bin', 'buildout')),
... end='')
Develop: '/sample-bootstrapped/demo' Develop: '/sample-bootstrapped/demo'
Now we can add the extensions option. We were a bit tricky and ran Now we can add the extensions option. We were a bit tricky and ran
...@@ -2829,7 +2830,8 @@ the network, we wouldn't need to do anything special. ...@@ -2829,7 +2830,8 @@ the network, we wouldn't need to do anything special.
We see that our extension is loaded and executed: We see that our extension is loaded and executed:
>>> print system(os.path.join(sample_bootstrapped, 'bin', 'buildout')), >>> print_(system(os.path.join(sample_bootstrapped, 'bin', 'buildout')),
... end='')
ext ['buildout'] ext ['buildout']
Develop: '/sample-bootstrapped/demo' Develop: '/sample-bootstrapped/demo'
unload ['buildout'] unload ['buildout']
##############################################################################
#
# Copyright Zope Foundation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
# The following copied from Python 2 config parser because:
# - The py3 configparser isn't backward compatible
# - Both strip option values in undesireable ways
# - dict of dicts is a much simpler api
import re
class Error(Exception):
"""Base class for ConfigParser exceptions."""
def _get_message(self):
"""Getter for 'message'; needed only to override deprecation in
BaseException."""
return self.__message
def _set_message(self, value):
"""Setter for 'message'; needed only to override deprecation in
BaseException."""
self.__message = value
# BaseException.message has been deprecated since Python 2.6. To prevent
# DeprecationWarning from popping up over this pre-existing attribute, use
# a new property that takes lookup precedence.
message = property(_get_message, _set_message)
def __init__(self, msg=''):
self.message = msg
Exception.__init__(self, msg)
def __repr__(self):
return self.message
class ParsingError(Error):
"""Raised when a configuration file does not follow legal syntax."""
def __init__(self, filename):
Error.__init__(self, 'File contains parsing errors: %s' % filename)
self.filename = filename
self.errors = []
def append(self, lineno, line):
self.errors.append((lineno, line))
self.message += '\n\t[line %2d]: %s' % (lineno, line)
class MissingSectionHeaderError(ParsingError):
"""Raised when a key-value pair is found before any section header."""
def __init__(self, filename, lineno, line):
Error.__init__(
self,
'File contains no section headers.\nfile: %s, line: %d\n%r' %
(filename, lineno, line))
self.filename = filename
self.lineno = lineno
self.line = line
SECTCRE = re.compile(
r'\[' # [
r'(?P<header>[^]]+)' # very permissive!
r'\]' # ]
)
OPTCRE = re.compile(
r'(?P<option>[^:=\s][^:=]*)' # very permissive!
r'\s*(?P<vi>[:=])\s*' # any number of space/tab,
# followed by separator
# (either : or =), followed
# by any # space/tab
r'(?P<value>.*)$' # everything up to eol
)
def parse(fp, fpname):
"""Parse a sectioned setup file.
The sections in setup file contains a title line at the top,
indicated by a name in square brackets (`[]'), plus key/value
options lines, indicated by `name: value' format lines.
Continuations are represented by an embedded newline then
leading whitespace. Blank lines, lines beginning with a '#',
and just about everything else are ignored.
"""
_sections = {}
cursect = None # None, or a dictionary
optname = None
lineno = 0
e = None # None, or an exception
while True:
line = fp.readline()
if not line:
break
lineno = lineno + 1
# comment or blank line?
if line.strip() == '' or line[0] in '#;':
continue
if line.split(None, 1)[0].lower() == 'rem' and line[0] in "rR":
# no leading whitespace
continue
# continuation line?
if line[0].isspace() and cursect is not None and optname:
value = line.strip()
if value:
cursect[optname] = "%s\n%s" % (cursect[optname], value)
# a section header or option header?
else:
# is it a section header?
mo = SECTCRE.match(line)
if mo:
sectname = mo.group('header')
if sectname in _sections:
cursect = _sections[sectname]
else:
cursect = {}
_sections[sectname] = cursect
# So sections can't start with a continuation line
optname = None
# no section header in the file?
elif cursect is None:
raise MissingSectionHeaderError(fpname, lineno, line)
# an option line?
else:
mo = OPTCRE.match(line)
if mo:
optname, vi, optval = mo.group('option', 'vi', 'value')
# This check is fine because the OPTCRE cannot
# match if it would set optval to None
if optval is not None:
if vi in ('=', ':') and ';' in optval:
# ';' is a comment delimiter only if it follows
# a spacing character
pos = optval.find(';')
if pos != -1 and optval[pos-1].isspace():
optval = optval[:pos]
optval = optval.strip()
# allow empty values
if optval == '""':
optval = ''
optname = optname.rstrip()
cursect[optname] = optval
else:
# a non-fatal parsing error occurred. set up the
# exception but keep going. the exception will be
# raised at the end of the file and will contain a
# list of all bogus lines
if not e:
e = ParsingError(fpname)
e.append(lineno, repr(line))
# if any parsing errors occurred, raise an exception
if e:
raise e
return _sections
...@@ -56,7 +56,7 @@ And create a buildout that uses it: ...@@ -56,7 +56,7 @@ And create a buildout that uses it:
If we run the buildout, we'll get an error: If we run the buildout, we'll get an error:
>>> print system(buildout), >>> print_(system(buildout), end='')
Develop: '/sample-buildout/recipes' Develop: '/sample-buildout/recipes'
Installing data-dir. Installing data-dir.
While: While:
...@@ -67,11 +67,11 @@ If we run the buildout, we'll get an error: ...@@ -67,11 +67,11 @@ If we run the buildout, we'll get an error:
If we want to debug the error, we can add the -D option. Here's we'll If we want to debug the error, we can add the -D option. Here's we'll
supply some input: supply some input:
>>> print system(buildout+" -D", """\ >>> print_(system(buildout+" -D", """\
... up ... up
... p self.options.keys() ... p self.options.keys()
... q ... q
... """), ... """), end='')
Develop: '/sample-buildout/recipes' Develop: '/sample-buildout/recipes'
Installing data-dir. Installing data-dir.
> /zc/buildout/buildout.py(925)__getitem__() > /zc/buildout/buildout.py(925)__getitem__()
......
...@@ -54,14 +54,13 @@ Now let's configure the buildout to use the develop egg. ...@@ -54,14 +54,13 @@ Now let's configure the buildout to use the develop egg.
Now we can run the buildout. Now we can run the buildout.
>>> print system(buildout) >>> print_(system(buildout), end='')
GET 200 / GET 200 /
GET 200 /demoneeded-1.2c1.zip GET 200 /demoneeded-1.2c1.zip
Develop: '/sample-buildout/depdemo' Develop: '/sample-buildout/depdemo'
Installing eggs. Installing eggs.
Getting distribution for 'demoneeded'. Getting distribution for 'demoneeded'.
Got demoneeded 1.2c1. Got demoneeded 1.2c1.
<BLANKLINE>
Notice that the egg was retrieved from the logging server. Notice that the egg was retrieved from the logging server.
...@@ -83,7 +82,7 @@ buildout to see where the egg comes from this time. ...@@ -83,7 +82,7 @@ buildout to see where the egg comes from this time.
... for egg in glob(join(sample_buildout, 'eggs', 'demoneeded*.egg')): ... for egg in glob(join(sample_buildout, 'eggs', 'demoneeded*.egg')):
... remove(sample_buildout, 'eggs', egg) ... remove(sample_buildout, 'eggs', egg)
>>> remove_demoneeded_egg() >>> remove_demoneeded_egg()
>>> print system(buildout) >>> print_(system(buildout), end='')
Develop: '/sample-buildout/depdemo' Develop: '/sample-buildout/depdemo'
Updating eggs. Updating eggs.
Couldn't find index page for 'demoneeded' (maybe misspelled?) Couldn't find index page for 'demoneeded' (maybe misspelled?)
...@@ -92,7 +91,6 @@ buildout to see where the egg comes from this time. ...@@ -92,7 +91,6 @@ buildout to see where the egg comes from this time.
Updating eggs. Updating eggs.
Getting distribution for 'demoneeded'. Getting distribution for 'demoneeded'.
Error: Couldn't find a distribution for 'demoneeded'. Error: Couldn't find a distribution for 'demoneeded'.
<BLANKLINE>
Now it can't find the dependency since neither the buildout Now it can't find the dependency since neither the buildout
configuration nor setup specifies where to look. configuration nor setup specifies where to look.
...@@ -112,12 +110,11 @@ to look for eggs. ...@@ -112,12 +110,11 @@ to look for eggs.
... eggs = depdemo ... eggs = depdemo
... ''' % link_server) ... ''' % link_server)
>>> print system(buildout) >>> print_(system(buildout), end='')
Develop: '/sample-buildout/depdemo' Develop: '/sample-buildout/depdemo'
Installing eggs. Installing eggs.
Getting distribution for 'demoneeded'. Getting distribution for 'demoneeded'.
Got demoneeded 1.2c1. Got demoneeded 1.2c1.
<BLANKLINE>
This time the dependency egg was found on the server without logging This time the dependency egg was found on the server without logging
configured. configured.
...@@ -134,13 +131,12 @@ specify different places to look for the dependency egg. ...@@ -134,13 +131,12 @@ specify different places to look for the dependency egg.
... ''' % link_server2) ... ''' % link_server2)
>>> remove_demoneeded_egg() >>> remove_demoneeded_egg()
>>> print system(buildout) #doctest: +ELLIPSIS >>> print_(system(buildout), end='') #doctest: +ELLIPSIS
GET 200 /... GET 200 /...
Develop: '/sample-buildout/depdemo' Develop: '/sample-buildout/depdemo'
Updating eggs. Updating eggs.
Getting distribution for 'demoneeded'. Getting distribution for 'demoneeded'.
Got demoneeded 1.2c1. Got demoneeded 1.2c1.
<BLANKLINE>
So when both setuptools and buildout specify places to search for So when both setuptools and buildout specify places to search for
eggs, the dependency_links takes precedence over find-links. eggs, the dependency_links takes precedence over find-links.
...@@ -166,12 +162,11 @@ Here is an example of using this option to disable dependency_links. ...@@ -166,12 +162,11 @@ Here is an example of using this option to disable dependency_links.
... ''' % link_server) ... ''' % link_server)
>>> remove_demoneeded_egg() >>> remove_demoneeded_egg()
>>> print system(buildout) >>> print_(system(buildout), end='')
Develop: '/sample-buildout/depdemo' Develop: '/sample-buildout/depdemo'
Updating eggs. Updating eggs.
Getting distribution for 'demoneeded'. Getting distribution for 'demoneeded'.
Got demoneeded 1.2c1. Got demoneeded 1.2c1.
<BLANKLINE>
Notice that this time the egg isn't downloaded from the logging server. Notice that this time the egg isn't downloaded from the logging server.
...@@ -191,10 +186,9 @@ before. The dependency's are looked for first in the logging server. ...@@ -191,10 +186,9 @@ before. The dependency's are looked for first in the logging server.
... eggs = depdemo ... eggs = depdemo
... ''' % link_server) ... ''' % link_server)
>>> remove_demoneeded_egg() >>> remove_demoneeded_egg()
>>> print system(buildout) #doctest: +ELLIPSIS >>> print_(system(buildout), end='') #doctest: +ELLIPSIS
GET 200 /... GET 200 /...
Develop: '/sample-buildout/depdemo' Develop: '/sample-buildout/depdemo'
Updating eggs. Updating eggs.
Getting distribution for 'demoneeded'. Getting distribution for 'demoneeded'.
Got demoneeded 1.2c1. Got demoneeded 1.2c1.
<BLANKLINE>
...@@ -24,13 +24,13 @@ import os.path ...@@ -24,13 +24,13 @@ import os.path
import re import re
import shutil import shutil
import tempfile import tempfile
import urllib import urllib.request, urllib.parse, urllib.error
import urlparse import urllib.parse
import zc.buildout import zc.buildout
class URLOpener(urllib.FancyURLopener): class URLOpener(urllib.request.FancyURLopener):
http_error_default = urllib.URLopener.http_error_default http_error_default = urllib.request.URLopener.http_error_default
class ChecksumError(zc.buildout.UserError): class ChecksumError(zc.buildout.UserError):
...@@ -157,7 +157,7 @@ class Download(object): ...@@ -157,7 +157,7 @@ class Download(object):
if re.match(r"^[A-Za-z]:\\", url): if re.match(r"^[A-Za-z]:\\", url):
url = 'file:' + url url = 'file:' + url
parsed_url = urlparse.urlparse(url, 'file') parsed_url = urllib.parse.urlparse(url, 'file')
url_scheme, _, url_path = parsed_url[:3] url_scheme, _, url_path = parsed_url[:3]
if url_scheme == 'file': if url_scheme == 'file':
self.logger.debug('Using local resource %s' % url) self.logger.debug('Using local resource %s' % url)
...@@ -172,18 +172,19 @@ class Download(object): ...@@ -172,18 +172,19 @@ class Download(object):
"Couldn't download %r in offline mode." % url) "Couldn't download %r in offline mode." % url)
self.logger.info('Downloading %s' % url) self.logger.info('Downloading %s' % url)
urllib._urlopener = url_opener urllib.request._urlopener = url_opener
handle, tmp_path = tempfile.mkstemp(prefix='buildout-') handle, tmp_path = tempfile.mkstemp(prefix='buildout-')
try: try:
tmp_path, headers = urllib.urlretrieve(url, tmp_path) tmp_path, headers = urllib.request.urlretrieve(url, tmp_path)
if not check_md5sum(tmp_path, md5sum): if not check_md5sum(tmp_path, md5sum):
raise ChecksumError( raise ChecksumError(
'MD5 checksum mismatch downloading %r' % url) 'MD5 checksum mismatch downloading %r' % url)
except IOError, e: except IOError:
e = sys.exc_info()[1]
os.remove(tmp_path) os.remove(tmp_path)
raise zc.buildout.UserError("Error downloading extends for URL " raise zc.buildout.UserError("Error downloading extends for URL "
"%s: %r" % (url, e[1:3])) "%s: %r" % (url, e[1:3]))
except Exception, e: except Exception:
os.remove(tmp_path) os.remove(tmp_path)
raise raise
finally: finally:
...@@ -204,7 +205,7 @@ class Download(object): ...@@ -204,7 +205,7 @@ class Download(object):
else: else:
if re.match(r"^[A-Za-z]:\\", url): if re.match(r"^[A-Za-z]:\\", url):
url = 'file:' + url url = 'file:' + url
parsed = urlparse.urlparse(url, 'file') parsed = urllib.parse.urlparse(url, 'file')
url_path = parsed[2] url_path = parsed[2]
if parsed[0] == 'file': if parsed[0] == 'file':
......
...@@ -28,7 +28,7 @@ without any arguments: ...@@ -28,7 +28,7 @@ without any arguments:
>>> from zc.buildout.download import Download >>> from zc.buildout.download import Download
>>> download = Download() >>> download = Download()
>>> print download.cache_dir >>> print_(download.cache_dir)
None None
Downloading a file is achieved by calling the utility with the URL as an Downloading a file is achieved by calling the utility with the URL as an
...@@ -37,7 +37,7 @@ of the file and a boolean value indicating whether this is a temporary file ...@@ -37,7 +37,7 @@ of the file and a boolean value indicating whether this is a temporary file
meant to be cleaned up during the same buildout run: meant to be cleaned up during the same buildout run:
>>> path, is_temp = download(server_url+'foo.txt') >>> path, is_temp = download(server_url+'foo.txt')
>>> print path >>> print_(path)
/.../buildout-... /.../buildout-...
>>> cat(path) >>> cat(path)
This is a foo text. This is a foo text.
...@@ -59,8 +59,8 @@ We are responsible for cleaning up temporary files behind us: ...@@ -59,8 +59,8 @@ We are responsible for cleaning up temporary files behind us:
When trying to access a file that doesn't exist, we'll get an exception: When trying to access a file that doesn't exist, we'll get an exception:
>>> try: download(server_url+'not-there') # doctest: +ELLIPSIS >>> try: download(server_url+'not-there') # doctest: +ELLIPSIS
... except: print 'download error' ... except: print_('download error')
... else: print 'woops' ... else: print_('woops')
download error download error
Downloading a local file doesn't produce a temporary file but simply returns Downloading a local file doesn't produce a temporary file but simply returns
...@@ -102,7 +102,7 @@ Finally, we can download the file to a specified place in the file system: ...@@ -102,7 +102,7 @@ Finally, we can download the file to a specified place in the file system:
>>> target_dir = tmpdir('download-target') >>> target_dir = tmpdir('download-target')
>>> path, is_temp = download(server_url+'foo.txt', >>> path, is_temp = download(server_url+'foo.txt',
... path=join(target_dir, 'downloaded.txt')) ... path=join(target_dir, 'downloaded.txt'))
>>> print path >>> print_(path)
/download-target/downloaded.txt /download-target/downloaded.txt
>>> cat(path) >>> cat(path)
This is a foo text. This is a foo text.
...@@ -136,7 +136,7 @@ attribute upon instantiation: ...@@ -136,7 +136,7 @@ attribute upon instantiation:
>>> cache = tmpdir('download-cache') >>> cache = tmpdir('download-cache')
>>> download = Download(cache=cache) >>> download = Download(cache=cache)
>>> print download.cache_dir >>> print_(download.cache_dir)
/download-cache/ /download-cache/
Simple usage Simple usage
...@@ -148,7 +148,7 @@ to the cached copy: ...@@ -148,7 +148,7 @@ to the cached copy:
>>> ls(cache) >>> ls(cache)
>>> path, is_temp = download(server_url+'foo.txt') >>> path, is_temp = download(server_url+'foo.txt')
>>> print path >>> print_(path)
/download-cache/foo.txt /download-cache/foo.txt
>>> cat(path) >>> cat(path)
This is a foo text. This is a foo text.
...@@ -160,7 +160,7 @@ the file on the server to see this: ...@@ -160,7 +160,7 @@ the file on the server to see this:
>>> write(server_data, 'foo.txt', 'The wrong text.') >>> write(server_data, 'foo.txt', 'The wrong text.')
>>> path, is_temp = download(server_url+'foo.txt') >>> path, is_temp = download(server_url+'foo.txt')
>>> print path >>> print_(path)
/download-cache/foo.txt /download-cache/foo.txt
>>> cat(path) >>> cat(path)
This is a foo text. This is a foo text.
...@@ -179,7 +179,7 @@ will result in the cached copy being used: ...@@ -179,7 +179,7 @@ will result in the cached copy being used:
>>> mkdir(server_data, 'other') >>> mkdir(server_data, 'other')
>>> write(server_data, 'other', 'foo.txt', 'The wrong text.') >>> write(server_data, 'other', 'foo.txt', 'The wrong text.')
>>> path, is_temp = download(server_url+'other/foo.txt') >>> path, is_temp = download(server_url+'other/foo.txt')
>>> print path >>> print_(path)
/download-cache/foo.txt /download-cache/foo.txt
>>> cat(path) >>> cat(path)
This is a foo text. This is a foo text.
...@@ -194,7 +194,7 @@ cached copy: ...@@ -194,7 +194,7 @@ cached copy:
>>> path, is_temp = download(server_url+'foo.txt', >>> path, is_temp = download(server_url+'foo.txt',
... path=join(target_dir, 'downloaded.txt')) ... path=join(target_dir, 'downloaded.txt'))
>>> print path >>> print_(path)
/download-target/downloaded.txt /download-target/downloaded.txt
>>> cat(path) >>> cat(path)
This is a foo text. This is a foo text.
...@@ -208,7 +208,7 @@ False ...@@ -208,7 +208,7 @@ False
>>> path, is_temp = download(server_url+'foo.txt', >>> path, is_temp = download(server_url+'foo.txt',
... path=join(target_dir, 'downloaded.txt')) ... path=join(target_dir, 'downloaded.txt'))
>>> print path >>> print_(path)
/download-target/downloaded.txt /download-target/downloaded.txt
>>> cat(path) >>> cat(path)
This is a foo text. This is a foo text.
...@@ -281,7 +281,7 @@ namespaces to use, so the download utility stored files directly inside the ...@@ -281,7 +281,7 @@ namespaces to use, so the download utility stored files directly inside the
download cache. Let's use a namespace "test" instead: download cache. Let's use a namespace "test" instead:
>>> download = Download(cache=cache, namespace='test') >>> download = Download(cache=cache, namespace='test')
>>> print download.cache_dir >>> print_(download.cache_dir)
/download-cache/test /download-cache/test
The namespace sub-directory hasn't been created yet: The namespace sub-directory hasn't been created yet:
...@@ -292,7 +292,7 @@ Downloading a file now creates the namespace sub-directory and places a copy ...@@ -292,7 +292,7 @@ Downloading a file now creates the namespace sub-directory and places a copy
of the file inside it: of the file inside it:
>>> path, is_temp = download(server_url+'foo.txt') >>> path, is_temp = download(server_url+'foo.txt')
>>> print path >>> print_(path)
/download-cache/test/foo.txt /download-cache/test/foo.txt
>>> ls(cache) >>> ls(cache)
d test d test
...@@ -311,7 +311,7 @@ different content both on the server and in the cache's root directory: ...@@ -311,7 +311,7 @@ different content both on the server and in the cache's root directory:
>>> write(cache, 'foo.txt', 'The wrong text.') >>> write(cache, 'foo.txt', 'The wrong text.')
>>> path, is_temp = download(server_url+'foo.txt') >>> path, is_temp = download(server_url+'foo.txt')
>>> print path >>> print_(path)
/download-cache/test/foo.txt /download-cache/test/foo.txt
>>> cat(path) >>> cat(path)
This is a foo text. This is a foo text.
...@@ -332,7 +332,7 @@ be used as the filename in the cache: ...@@ -332,7 +332,7 @@ be used as the filename in the cache:
>>> download = Download(cache=cache, hash_name=True) >>> download = Download(cache=cache, hash_name=True)
>>> path, is_temp = download(server_url+'foo.txt') >>> path, is_temp = download(server_url+'foo.txt')
>>> print path >>> print_(path)
/download-cache/09f5793fcdc1716727f72d49519c688d /download-cache/09f5793fcdc1716727f72d49519c688d
>>> cat(path) >>> cat(path)
This is a foo text. This is a foo text.
...@@ -362,7 +362,7 @@ file the same, the file will be downloaded again this time and put in the ...@@ -362,7 +362,7 @@ file the same, the file will be downloaded again this time and put in the
cache under a different name: cache under a different name:
>>> path2, is_temp = download(server_url+'other/foo.txt') >>> path2, is_temp = download(server_url+'other/foo.txt')
>>> print path2 >>> print_(path2)
/download-cache/537b6d73267f8f4447586989af8c470e /download-cache/537b6d73267f8f4447586989af8c470e
>>> path == path2 >>> path == path2
False False
...@@ -390,7 +390,7 @@ down or if we are in offline mode. This mode is only in effect if a download ...@@ -390,7 +390,7 @@ down or if we are in offline mode. This mode is only in effect if a download
cache is configured in the first place: cache is configured in the first place:
>>> download = Download(cache=cache, fallback=True) >>> download = Download(cache=cache, fallback=True)
>>> print download.cache_dir >>> print_(download.cache_dir)
/download-cache/ /download-cache/
A downloaded file will be cached: A downloaded file will be cached:
...@@ -408,8 +408,8 @@ If the file cannot be served, the cached copy will be used: ...@@ -408,8 +408,8 @@ If the file cannot be served, the cached copy will be used:
>>> remove(server_data, 'foo.txt') >>> remove(server_data, 'foo.txt')
>>> try: Download()(server_url+'foo.txt') # doctest: +ELLIPSIS >>> try: Download()(server_url+'foo.txt') # doctest: +ELLIPSIS
... except: print 'download error' ... except: print_('download error')
... else: print 'woops' ... else: print_('woops')
download error download error
>>> path, is_temp = download(server_url+'foo.txt') >>> path, is_temp = download(server_url+'foo.txt')
>>> cat(path) >>> cat(path)
...@@ -426,7 +426,7 @@ using the cache: ...@@ -426,7 +426,7 @@ using the cache:
>>> offline_download = Download(cache=cache, offline=True, fallback=True) >>> offline_download = Download(cache=cache, offline=True, fallback=True)
>>> path, is_temp = offline_download(server_url+'foo.txt') >>> path, is_temp = offline_download(server_url+'foo.txt')
>>> print path >>> print_(path)
/download-cache/foo.txt /download-cache/foo.txt
>>> cat(path) >>> cat(path)
This is a foo text. This is a foo text.
...@@ -466,7 +466,7 @@ The location of the download cache is specified by the ``download-cache`` ...@@ -466,7 +466,7 @@ The location of the download cache is specified by the ``download-cache``
option: option:
>>> download = Download({'download-cache': cache}, namespace='cmmi') >>> download = Download({'download-cache': cache}, namespace='cmmi')
>>> print download.cache_dir >>> print_(download.cache_dir)
/download-cache/cmmi /download-cache/cmmi
If the ``download-cache`` option specifies a relative path, it is understood If the ``download-cache`` option specifies a relative path, it is understood
...@@ -474,18 +474,18 @@ relative to the current working directory, or to the buildout directory if ...@@ -474,18 +474,18 @@ relative to the current working directory, or to the buildout directory if
that is given: that is given:
>>> download = Download({'download-cache': 'relative-cache'}) >>> download = Download({'download-cache': 'relative-cache'})
>>> print download.cache_dir >>> print_(download.cache_dir)
/sample-buildout/relative-cache/ /sample-buildout/relative-cache/
>>> download = Download({'directory': join(sample_buildout, 'root'), >>> download = Download({'directory': join(sample_buildout, 'root'),
... 'download-cache': 'relative-cache'}) ... 'download-cache': 'relative-cache'})
>>> print download.cache_dir >>> print_(download.cache_dir)
/sample-buildout/root/relative-cache/ /sample-buildout/root/relative-cache/
Keyword parameters take precedence over the corresponding options: Keyword parameters take precedence over the corresponding options:
>>> download = Download({'download-cache': cache}, cache=None) >>> download = Download({'download-cache': cache}, cache=None)
>>> print download.cache_dir >>> print_(download.cache_dir)
None None
Whether to assume offline mode can be inferred from either the ``offline`` or Whether to assume offline mode can be inferred from either the ``offline`` or
......
...@@ -31,7 +31,7 @@ And set up a buildout that downloads some eggs: ...@@ -31,7 +31,7 @@ And set up a buildout that downloads some eggs:
We specified a link server that has some distributions available for We specified a link server that has some distributions available for
download: download:
>>> print get(link_server), >>> print_(get(link_server), end='')
<html><body> <html><body>
<a href="bigdemo-0.1-py2.4.egg">bigdemo-0.1-py2.4.egg</a><br> <a href="bigdemo-0.1-py2.4.egg">bigdemo-0.1-py2.4.egg</a><br>
<a href="demo-0.1-py2.4.egg">demo-0.1-py2.4.egg</a><br> <a href="demo-0.1-py2.4.egg">demo-0.1-py2.4.egg</a><br>
...@@ -59,7 +59,7 @@ We also specified a download cache. ...@@ -59,7 +59,7 @@ We also specified a download cache.
If we run the buildout, we'll see the eggs installed from the link If we run the buildout, we'll see the eggs installed from the link
server as usual: server as usual:
>>> print system(buildout), >>> print_(system(buildout), end='')
GET 200 / GET 200 /
GET 200 /demo-0.2-py2.4.egg GET 200 /demo-0.2-py2.4.egg
GET 200 /demoneeded-1.2c1.zip GET 200 /demoneeded-1.2c1.zip
...@@ -89,7 +89,7 @@ If we remove the installed eggs from eggs directory and re-run the buildout: ...@@ -89,7 +89,7 @@ If we remove the installed eggs from eggs directory and re-run the buildout:
... if f.startswith('demo'): ... if f.startswith('demo'):
... remove('eggs', f) ... remove('eggs', f)
>>> print system(buildout), >>> print_(system(buildout), end='')
GET 200 / GET 200 /
Updating eggs. Updating eggs.
Getting distribution for 'demo==0.2'. Getting distribution for 'demo==0.2'.
...@@ -132,7 +132,7 @@ install-from-cache option set to true: ...@@ -132,7 +132,7 @@ install-from-cache option set to true:
... eggs = demo ... eggs = demo
... ''' % globals()) ... ''' % globals())
>>> print system(buildout), >>> print_(system(buildout), end='')
Uninstalling eggs. Uninstalling eggs.
Installing eggs. Installing eggs.
Getting distribution for 'demo'. Getting distribution for 'demo'.
......
...@@ -611,8 +611,9 @@ class Installer: ...@@ -611,8 +611,9 @@ class Installer:
while 1: while 1:
try: try:
ws.resolve(requirements) ws.resolve(requirements)
except pkg_resources.DistributionNotFound, err: except pkg_resources.DistributionNotFound:
[requirement] = err err = sys.exc_info()[1]
[requirement] = err.args
requirement = self._constrain(requirement) requirement = self._constrain(requirement)
if dest: if dest:
logger.debug('Getting required %r', str(requirement)) logger.debug('Getting required %r', str(requirement))
...@@ -623,7 +624,8 @@ class Installer: ...@@ -623,7 +624,8 @@ class Installer:
for dist in self._get_dist(requirement, ws): for dist in self._get_dist(requirement, ws):
ws.add(dist) ws.add(dist)
self._maybe_add_distribute(ws, dist) self._maybe_add_distribute(ws, dist)
except pkg_resources.VersionConflict, err: except pkg_resources.VersionConflict:
err = sys.exc_info()[1]
raise VersionConflict(err, ws) raise VersionConflict(err, ws)
else: else:
break break
...@@ -813,12 +815,12 @@ def develop(setup, dest, ...@@ -813,12 +815,12 @@ def develop(setup, dest,
undo.append(lambda: os.remove(tsetup)) undo.append(lambda: os.remove(tsetup))
undo.append(lambda: os.close(fd)) undo.append(lambda: os.close(fd))
os.write(fd, runsetup_template % dict( os.write(fd, (runsetup_template % dict(
distribute=distribute_loc, distribute=distribute_loc,
setupdir=directory, setupdir=directory,
setup=setup, setup=setup,
__file__ = setup, __file__ = setup,
)) )).encode())
tmp3 = tempfile.mkdtemp('build', dir=dest) tmp3 = tempfile.mkdtemp('build', dir=dest)
undo.append(lambda : shutil.rmtree(tmp3)) undo.append(lambda : shutil.rmtree(tmp3))
...@@ -871,7 +873,7 @@ def scripts(reqs, working_set, executable, dest=None, ...@@ -871,7 +873,7 @@ def scripts(reqs, working_set, executable, dest=None,
for p in path: for p in path:
if p not in unique_path: if p not in unique_path:
unique_path.append(p) unique_path.append(p)
path = map(realpath, unique_path) path = list(map(realpath, unique_path))
generated = [] generated = []
...@@ -1073,7 +1075,7 @@ def _create_script(contents, dest): ...@@ -1073,7 +1075,7 @@ def _create_script(contents, dest):
logger.info("Generated script %r.", script) logger.info("Generated script %r.", script)
try: try:
os.chmod(dest, 0755) os.chmod(dest, 0o755)
except (AttributeError, os.error): except (AttributeError, os.error):
pass pass
...@@ -1110,8 +1112,7 @@ sys.path[0:0] = [ ...@@ -1110,8 +1112,7 @@ sys.path[0:0] = [
] ]
%(initialization)s %(initialization)s
%(original_content)s %(original_content)s'''
'''
def _pyscript(path, dest, rsetup): def _pyscript(path, dest, rsetup):
...@@ -1142,7 +1143,7 @@ def _pyscript(path, dest, rsetup): ...@@ -1142,7 +1143,7 @@ def _pyscript(path, dest, rsetup):
if changed: if changed:
open(dest, 'w').write(contents) open(dest, 'w').write(contents)
try: try:
os.chmod(dest,0755) os.chmod(dest,0o755)
except (AttributeError, os.error): except (AttributeError, os.error):
pass pass
logger.info("Generated interpreter %r.", script) logger.info("Generated interpreter %r.", script)
...@@ -1167,7 +1168,7 @@ if len(sys.argv) > 1: ...@@ -1167,7 +1168,7 @@ if len(sys.argv) > 1:
if _opt == '-i': if _opt == '-i':
_interactive = True _interactive = True
elif _opt == '-c': elif _opt == '-c':
exec _val exec(_val)
elif _opt == '-m': elif _opt == '-m':
sys.argv[1:] = _args sys.argv[1:] = _args
_args = [] _args = []
...@@ -1178,7 +1179,9 @@ if len(sys.argv) > 1: ...@@ -1178,7 +1179,9 @@ if len(sys.argv) > 1:
sys.argv[:] = _args sys.argv[:] = _args
__file__ = _args[0] __file__ = _args[0]
del _options, _args del _options, _args
execfile(__file__) __file__f = open(__file__)
exec(compile(__file__f.read(), __file__, "exec"))
__file__f.close(); del __file__f
if _interactive: if _interactive:
del _interactive del _interactive
...@@ -1195,7 +1198,8 @@ __file__ = %(__file__)r ...@@ -1195,7 +1198,8 @@ __file__ = %(__file__)r
os.chdir(%(setupdir)r) os.chdir(%(setupdir)r)
sys.argv[0] = %(setup)r sys.argv[0] = %(setup)r
execfile(%(setup)r)
exec(compile(open(%(setup)r).read(), %(setup)r, 'exec'))
""" """
......
...@@ -91,7 +91,7 @@ needed to meet the given requirements. ...@@ -91,7 +91,7 @@ needed to meet the given requirements.
We have a link server that has a number of eggs: We have a link server that has a number of eggs:
>>> print get(link_server), >>> print_(get(link_server), end='')
<html><body> <html><body>
<a href="bigdemo-0.1-py2.4.egg">bigdemo-0.1-py2.4.egg</a><br> <a href="bigdemo-0.1-py2.4.egg">bigdemo-0.1-py2.4.egg</a><br>
<a href="demo-0.1-py2.4.egg">demo-0.1-py2.4.egg</a><br> <a href="demo-0.1-py2.4.egg">demo-0.1-py2.4.egg</a><br>
...@@ -107,1216 +107,1222 @@ We have a link server that has a number of eggs: ...@@ -107,1216 +107,1222 @@ We have a link server that has a number of eggs:
<a href="other-1.0-py2.4.egg">other-1.0-py2.4.egg</a><br> <a href="other-1.0-py2.4.egg">other-1.0-py2.4.egg</a><br>
</body></html> </body></html>
Let's make a directory and install the demo egg to it, using the demo: Let's make a directory and install the demo egg to it, using the demo:
>>> dest = tmpdir('sample-install') >>> dest = tmpdir('sample-install')
>>> import zc.buildout.easy_install >>> import zc.buildout.easy_install
>>> ws = zc.buildout.easy_install.install( >>> ws = zc.buildout.easy_install.install(
... ['demo==0.2'], dest, ... ['demo==0.2'], dest,
... links=[link_server], index=link_server+'index/') ... links=[link_server], index=link_server+'index/')
We requested version 0.2 of the demo distribution to be installed into We requested version 0.2 of the demo distribution to be installed into
the destination server. We specified that we should search for links the destination server. We specified that we should search for links
on the link server and that we should use the (empty) link server on the link server and that we should use the (empty) link server
index directory as a package index. index directory as a package index.
The working set contains the distributions we retrieved. The working set contains the distributions we retrieved.
>>> for dist in ws: >>> for dist in ws:
... print dist ... print_(dist)
demo 0.2 demo 0.2
demoneeded 1.1 demoneeded 1.1
We got demoneeded because it was a dependency of demo. We got demoneeded because it was a dependency of demo.
And the actual eggs were added to the eggs directory. And the actual eggs were added to the eggs directory.
>>> ls(dest) >>> ls(dest)
d demo-0.2-py2.4.egg d demo-0.2-py2.4.egg
d demoneeded-1.1-py2.4.egg d demoneeded-1.1-py2.4.egg
If we remove the version restriction on demo, but specify a false If we remove the version restriction on demo, but specify a false
value for newest, no new distributions will be installed: value for newest, no new distributions will be installed:
>>> ws = zc.buildout.easy_install.install( >>> ws = zc.buildout.easy_install.install(
... ['demo'], dest, links=[link_server], index=link_server+'index/', ... ['demo'], dest, links=[link_server], index=link_server+'index/',
... newest=False) ... newest=False)
>>> ls(dest) >>> ls(dest)
d demo-0.2-py2.4.egg d demo-0.2-py2.4.egg
d demoneeded-1.1-py2.4.egg d demoneeded-1.1-py2.4.egg
If we leave off the newest option, we'll get an update for demo: If we leave off the newest option, we'll get an update for demo:
>>> ws = zc.buildout.easy_install.install( >>> ws = zc.buildout.easy_install.install(
... ['demo'], dest, links=[link_server], index=link_server+'index/') ... ['demo'], dest, links=[link_server], index=link_server+'index/')
>>> ls(dest) >>> ls(dest)
d demo-0.2-py2.4.egg d demo-0.2-py2.4.egg
d demo-0.3-py2.4.egg d demo-0.3-py2.4.egg
d demoneeded-1.1-py2.4.egg d demoneeded-1.1-py2.4.egg
Note that we didn't get the newest versions available. There were Note that we didn't get the newest versions available. There were
release candidates for newer versions of both packages. By default, release candidates for newer versions of both packages. By default,
final releases are preferred. We can change this behavior using the final releases are preferred. We can change this behavior using the
prefer_final function: prefer_final function:
>>> zc.buildout.easy_install.prefer_final(False) >>> zc.buildout.easy_install.prefer_final(False)
True True
The old setting is returned. The old setting is returned.
>>> ws = zc.buildout.easy_install.install( >>> ws = zc.buildout.easy_install.install(
... ['demo'], dest, links=[link_server], index=link_server+'index/') ... ['demo'], dest, links=[link_server], index=link_server+'index/')
>>> for dist in ws: >>> for dist in ws:
... print dist ... print_(dist)
demo 0.4c1 demo 0.4c1
demoneeded 1.2c1 demoneeded 1.2c1
>>> ls(dest) >>> ls(dest)
d demo-0.2-py2.4.egg d demo-0.2-py2.4.egg
d demo-0.3-py2.4.egg d demo-0.3-py2.4.egg
d demo-0.4c1-py2.4.egg d demo-0.4c1-py2.4.egg
d demoneeded-1.1-py2.4.egg d demoneeded-1.1-py2.4.egg
d demoneeded-1.2c1-py2.4.egg d demoneeded-1.2c1-py2.4.egg
Let's put the setting back to the default. Let's put the setting back to the default.
>>> zc.buildout.easy_install.prefer_final(True) >>> zc.buildout.easy_install.prefer_final(True)
False False
We can supply additional distributions. We can also supply We can supply additional distributions. We can also supply
specifications for distributions that would normally be found via specifications for distributions that would normally be found via
dependencies. We might do this to specify a specific version. dependencies. We might do this to specify a specific version.
>>> ws = zc.buildout.easy_install.install( >>> ws = zc.buildout.easy_install.install(
... ['demo', 'other', 'demoneeded==1.0'], dest, ... ['demo', 'other', 'demoneeded==1.0'], dest,
... links=[link_server], index=link_server+'index/') ... links=[link_server], index=link_server+'index/')
>>> for dist in ws: >>> for dist in ws:
... print dist ... print_(dist)
demo 0.3 demo 0.3
other 1.0 other 1.0
demoneeded 1.0 demoneeded 1.0
>>> ls(dest) >>> ls(dest)
d demo-0.2-py2.4.egg d demo-0.2-py2.4.egg
d demo-0.3-py2.4.egg d demo-0.3-py2.4.egg
d demo-0.4c1-py2.4.egg d demo-0.4c1-py2.4.egg
d demoneeded-1.0-py2.4.egg d demoneeded-1.0-py2.4.egg
d demoneeded-1.1-py2.4.egg d demoneeded-1.1-py2.4.egg
d demoneeded-1.2c1-py2.4.egg d demoneeded-1.2c1-py2.4.egg
d other-1.0-py2.4.egg d other-1.0-py2.4.egg
>>> rmdir(dest) >>> rmdir(dest)
Specifying version information independent of requirements Specifying version information independent of requirements
---------------------------------------------------------- ----------------------------------------------------------
Sometimes it's useful to specify version information independent of Sometimes it's useful to specify version information independent of
normal requirements specifications. For example, a buildout may need normal requirements specifications. For example, a buildout may need
to lock down a set of versions, without having to put put version to lock down a set of versions, without having to put put version
numbers in setup files or part definitions. If a dictionary is passed numbers in setup files or part definitions. If a dictionary is passed
to the install function, mapping project names to version numbers, to the install function, mapping project names to version numbers,
then the versions numbers will be used. then the versions numbers will be used.
>>> ws = zc.buildout.easy_install.install( >>> ws = zc.buildout.easy_install.install(
... ['demo'], dest, links=[link_server], index=link_server+'index/', ... ['demo'], dest, links=[link_server], index=link_server+'index/',
... versions = dict(demo='0.2', demoneeded='1.0')) ... versions = dict(demo='0.2', demoneeded='1.0'))
>>> [d.version for d in ws] >>> [d.version for d in ws]
['0.2', '1.0'] ['0.2', '1.0']
In this example, we specified a version for demoneeded, even though we In this example, we specified a version for demoneeded, even though we
didn't define a requirement for it. The versions specified apply to didn't define a requirement for it. The versions specified apply to
dependencies as well as the specified requirements. dependencies as well as the specified requirements.
If we specify a version that's incompatible with a requirement, then If we specify a version that's incompatible with a requirement, then
we'll get an error: we'll get an error:
>>> from zope.testing.loggingsupport import InstalledHandler >>> from zope.testing.loggingsupport import InstalledHandler
>>> handler = InstalledHandler('zc.buildout.easy_install') >>> handler = InstalledHandler('zc.buildout.easy_install')
>>> import logging >>> import logging
>>> logging.getLogger('zc.buildout.easy_install').propagate = False >>> logging.getLogger('zc.buildout.easy_install').propagate = False
>>> ws = zc.buildout.easy_install.install( >>> ws = zc.buildout.easy_install.install(
... ['demo >0.2'], dest, links=[link_server], ... ['demo >0.2'], dest, links=[link_server],
... index=link_server+'index/', ... index=link_server+'index/',
... versions = dict(demo='0.2', demoneeded='1.0')) ... versions = dict(demo='0.2', demoneeded='1.0'))
Traceback (most recent call last): Traceback (most recent call last):
... ...
IncompatibleVersionError: Bad version 0.2 IncompatibleVersionError: Bad version 0.2
>>> print handler >>> print_(handler)
zc.buildout.easy_install DEBUG zc.buildout.easy_install DEBUG
Installing 'demo >0.2'. Installing 'demo >0.2'.
zc.buildout.easy_install ERROR zc.buildout.easy_install ERROR
The version, 0.2, is not consistent with the requirement, 'demo>0.2'. The version, 0.2, is not consistent with the requirement, 'demo>0.2'.
>>> handler.clear() >>> handler.clear()
If no versions are specified, a debugging message will be output If no versions are specified, a debugging message will be output
reporting that a version was picked automatically: reporting that a version was picked automatically:
>>> ws = zc.buildout.easy_install.install( >>> ws = zc.buildout.easy_install.install(
... ['demo'], dest, links=[link_server], index=link_server+'index/', ... ['demo'], dest, links=[link_server], index=link_server+'index/',
... ) ... )
>>> print handler # doctest: +ELLIPSIS >>> print_(handler) # doctest: +ELLIPSIS
zc.buildout.easy_install DEBUG zc.buildout.easy_install DEBUG
Installing 'demo'. Installing 'demo'.
zc.buildout.easy_install INFO zc.buildout.easy_install INFO
Getting distribution for 'demo'. Getting distribution for 'demo'.
zc.buildout.easy_install INFO zc.buildout.easy_install INFO
Got demo 0.3. Got demo 0.3.
zc.buildout.easy_install DEBUG zc.buildout.easy_install DEBUG
Picked: demo = 0.3 Picked: demo = 0.3
zc.buildout.easy_install DEBUG zc.buildout.easy_install DEBUG
Getting required 'demoneeded' Getting required 'demoneeded'
zc.buildout.easy_install DEBUG zc.buildout.easy_install DEBUG
required by demo 0.3. required by demo 0.3.
zc.buildout.easy_install INFO zc.buildout.easy_install INFO
Getting distribution for 'demoneeded'. Getting distribution for 'demoneeded'.
zc.buildout.easy_install DEBUG zc.buildout.easy_install DEBUG
Running easy_install:... Running easy_install:...
zc.buildout.easy_install INFO zc.buildout.easy_install INFO
Got demoneeded 1.1. Got demoneeded 1.1.
zc.buildout.easy_install DEBUG zc.buildout.easy_install DEBUG
Picked: demoneeded = 1.1 Picked: demoneeded = 1.1
zc.buildout.easy_install DEBUG zc.buildout.easy_install DEBUG
Installing 'demo'. Installing 'demo'.
zc.buildout.easy_install DEBUG zc.buildout.easy_install DEBUG
We have the best distribution that satisfies 'demo'. We have the best distribution that satisfies 'demo'.
zc.buildout.easy_install DEBUG zc.buildout.easy_install DEBUG
Picked: demo = 0.3 Picked: demo = 0.3
zc.buildout.easy_install DEBUG zc.buildout.easy_install DEBUG
Getting required 'demoneeded' Getting required 'demoneeded'
zc.buildout.easy_install DEBUG zc.buildout.easy_install DEBUG
required by demo 0.3. required by demo 0.3.
zc.buildout.easy_install DEBUG zc.buildout.easy_install DEBUG
We have the best distribution that satisfies 'demoneeded'. We have the best distribution that satisfies 'demoneeded'.
zc.buildout.easy_install DEBUG zc.buildout.easy_install DEBUG
Picked: demoneeded = 1.1 Picked: demoneeded = 1.1
>>> handler.uninstall() >>> handler.uninstall()
>>> logging.getLogger('zc.buildout.easy_install').propagate = True >>> logging.getLogger('zc.buildout.easy_install').propagate = True
We can request that we get an error if versions are picked: We can request that we get an error if versions are picked:
>>> zc.buildout.easy_install.allow_picked_versions(False) >>> zc.buildout.easy_install.allow_picked_versions(False)
True True
(The old setting is returned.) (The old setting is returned.)
>>> ws = zc.buildout.easy_install.install( >>> ws = zc.buildout.easy_install.install(
... ['demo'], dest, links=[link_server], index=link_server+'index/', ... ['demo'], dest, links=[link_server], index=link_server+'index/',
... ) ... )
Traceback (most recent call last): Traceback (most recent call last):
... ...
UserError: Picked: demo = 0.3 UserError: Picked: demo = 0.3
>>> zc.buildout.easy_install.allow_picked_versions(True) >>> zc.buildout.easy_install.allow_picked_versions(True)
False False
The function default_versions can be used to get and set default The function default_versions can be used to get and set default
version information to be used when no version information is passes. version information to be used when no version information is passes.
If called with an argument, it sets the default versions: If called with an argument, it sets the default versions:
>>> zc.buildout.easy_install.default_versions(dict(demoneeded='1')) >>> zc.buildout.easy_install.default_versions(dict(demoneeded='1'))
... # doctest: +ELLIPSIS ... # doctest: +ELLIPSIS
{...} {...}
It always returns the previous default versions. If called without an It always returns the previous default versions. If called without an
argument, it simply returns the default versions without changing argument, it simply returns the default versions without changing
them: them:
>>> zc.buildout.easy_install.default_versions() >>> zc.buildout.easy_install.default_versions()
{'demoneeded': '1'} {'demoneeded': '1'}
So with the default versions set, we'll get the requested version even So with the default versions set, we'll get the requested version even
if the versions option isn't used: if the versions option isn't used:
>>> ws = zc.buildout.easy_install.install( >>> ws = zc.buildout.easy_install.install(
... ['demo'], dest, links=[link_server], index=link_server+'index/', ... ['demo'], dest, links=[link_server], index=link_server+'index/',
... ) ... )
>>> [d.version for d in ws] >>> [d.version for d in ws]
['0.3', '1.0'] ['0.3', '1.0']
Of course, we can unset the default versions by passing an empty Of course, we can unset the default versions by passing an empty
dictionary: dictionary:
>>> zc.buildout.easy_install.default_versions({}) >>> zc.buildout.easy_install.default_versions({})
{'demoneeded': '1'} {'demoneeded': '1'}
>>> ws = zc.buildout.easy_install.install( >>> ws = zc.buildout.easy_install.install(
... ['demo'], dest, links=[link_server], index=link_server+'index/', ... ['demo'], dest, links=[link_server], index=link_server+'index/',
... ) ... )
>>> [d.version for d in ws] >>> [d.version for d in ws]
['0.3', '1.1'] ['0.3', '1.1']
Dependency links Dependency links
---------------- ----------------
Setuptools allows metadata that describes where to search for package Setuptools allows metadata that describes where to search for package
dependencies. This option is called dependency_links. Buildout has its dependencies. This option is called dependency_links. Buildout has its
own notion of where to look for dependencies, but it also uses the own notion of where to look for dependencies, but it also uses the
setup tools dependency_links information if it's available. setup tools dependency_links information if it's available.
Let's demo this by creating an egg that specifies dependency_links. Let's demo this by creating an egg that specifies dependency_links.
To begin, let's create a new egg repository. This repository hold a To begin, let's create a new egg repository. This repository hold a
newer version of the 'demoneeded' egg than the sample repository does. newer version of the 'demoneeded' egg than the sample repository does.
>>> repoloc = tmpdir('repo') >>> repoloc = tmpdir('repo')
>>> from zc.buildout.tests import create_egg >>> from zc.buildout.tests import create_egg
>>> create_egg('demoneeded', '1.2', repoloc) >>> create_egg('demoneeded', '1.2', repoloc)
>>> link_server2 = start_server(repoloc) >>> link_server2 = start_server(repoloc)
Turn on logging on this server so that we can see when eggs are pulled Turn on logging on this server so that we can see when eggs are pulled
from it. from it.
>>> get(link_server2 + 'enable_server_logging') >>> get(link_server2 + 'enable_server_logging')
GET 200 /enable_server_logging GET 200 /enable_server_logging
'' ''
Now we can create an egg that specifies that its dependencies are Now we can create an egg that specifies that its dependencies are
found on this server. found on this server.
>>> repoloc = tmpdir('repo2') >>> repoloc = tmpdir('repo2')
>>> create_egg('hasdeps', '1.0', repoloc, >>> create_egg('hasdeps', '1.0', repoloc,
... install_requires = "'demoneeded'", ... install_requires = "'demoneeded'",
... dependency_links = [link_server2]) ... dependency_links = [link_server2])
Let's add the egg to another repository. Let's add the egg to another repository.
>>> link_server3 = start_server(repoloc) >>> link_server3 = start_server(repoloc)
Now let's install the egg. Now let's install the egg.
>>> example_dest = tmpdir('example-install') >>> example_dest = tmpdir('example-install')
>>> workingset = zc.buildout.easy_install.install( >>> workingset = zc.buildout.easy_install.install(
... ['hasdeps'], example_dest, ... ['hasdeps'], example_dest,
... links=[link_server3], index=link_server3+'index/') ... links=[link_server3], index=link_server3+'index/')
GET 200 / GET 200 /
GET 200 /demoneeded-1.2-pyN.N.egg GET 200 /demoneeded-1.2-pyN.N.egg
The server logs show that the dependency was retrieved from the server The server logs show that the dependency was retrieved from the server
specified in the dependency_links. specified in the dependency_links.
Now let's see what happens if we provide two different ways to retrieve Now let's see what happens if we provide two different ways to retrieve
the dependencies. the dependencies.
>>> rmdir(example_dest) >>> rmdir(example_dest)
>>> example_dest = tmpdir('example-install') >>> example_dest = tmpdir('example-install')
>>> workingset = zc.buildout.easy_install.install( >>> workingset = zc.buildout.easy_install.install(
... ['hasdeps'], example_dest, index=link_server+'index/', ... ['hasdeps'], example_dest, index=link_server+'index/',
... links=[link_server, link_server3]) ... links=[link_server, link_server3])
GET 200 / GET 200 /
GET 200 /demoneeded-1.2-pyN.N.egg GET 200 /demoneeded-1.2-pyN.N.egg
Once again the dependency is fetched from the logging server even Once again the dependency is fetched from the logging server even
though it is also available from the non-logging server. This is though it is also available from the non-logging server. This is
because the version on the logging server is newer and buildout because the version on the logging server is newer and buildout
normally chooses the newest egg available. normally chooses the newest egg available.
If you wish to control where dependencies come from regardless of If you wish to control where dependencies come from regardless of
dependency_links setup metadata use the 'use_dependency_links' option dependency_links setup metadata use the 'use_dependency_links' option
to zc.buildout.easy_install.install(). to zc.buildout.easy_install.install().
>>> rmdir(example_dest) >>> rmdir(example_dest)
>>> example_dest = tmpdir('example-install') >>> example_dest = tmpdir('example-install')
>>> workingset = zc.buildout.easy_install.install( >>> workingset = zc.buildout.easy_install.install(
... ['hasdeps'], example_dest, index=link_server+'index/', ... ['hasdeps'], example_dest, index=link_server+'index/',
... links=[link_server, link_server3], ... links=[link_server, link_server3],
... use_dependency_links=False) ... use_dependency_links=False)
Notice that this time the dependency egg is not fetched from the Notice that this time the dependency egg is not fetched from the
logging server. When you specify not to use dependency_links, eggs logging server. When you specify not to use dependency_links, eggs
will only be searched for using the links you explicitly provide. will only be searched for using the links you explicitly provide.
Another way to control this option is with the Another way to control this option is with the
zc.buildout.easy_install.use_dependency_links() function. This zc.buildout.easy_install.use_dependency_links() function. This
function sets the default behavior for the zc.buildout.easy_install() function sets the default behavior for the zc.buildout.easy_install()
function. function.
>>> zc.buildout.easy_install.use_dependency_links(False) >>> zc.buildout.easy_install.use_dependency_links(False)
True True
The function returns its previous setting. The function returns its previous setting.
>>> rmdir(example_dest) >>> rmdir(example_dest)
>>> example_dest = tmpdir('example-install') >>> example_dest = tmpdir('example-install')
>>> workingset = zc.buildout.easy_install.install( >>> workingset = zc.buildout.easy_install.install(
... ['hasdeps'], example_dest, index=link_server+'index/', ... ['hasdeps'], example_dest, index=link_server+'index/',
... links=[link_server, link_server3]) ... links=[link_server, link_server3])
It can be overridden by passing a keyword argument to the install It can be overridden by passing a keyword argument to the install
function. function.
>>> rmdir(example_dest) >>> rmdir(example_dest)
>>> example_dest = tmpdir('example-install') >>> example_dest = tmpdir('example-install')
>>> workingset = zc.buildout.easy_install.install( >>> workingset = zc.buildout.easy_install.install(
... ['hasdeps'], example_dest, index=link_server+'index/', ... ['hasdeps'], example_dest, index=link_server+'index/',
... links=[link_server, link_server3], ... links=[link_server, link_server3],
... use_dependency_links=True) ... use_dependency_links=True)
GET 200 /demoneeded-1.2-pyN.N.egg GET 200 /demoneeded-1.2-pyN.N.egg
To return the dependency_links behavior to normal call the function again. To return the dependency_links behavior to normal call the function again.
>>> zc.buildout.easy_install.use_dependency_links(True) >>> zc.buildout.easy_install.use_dependency_links(True)
False False
>>> rmdir(example_dest) >>> rmdir(example_dest)
>>> example_dest = tmpdir('example-install') >>> example_dest = tmpdir('example-install')
>>> workingset = zc.buildout.easy_install.install( >>> workingset = zc.buildout.easy_install.install(
... ['hasdeps'], example_dest, index=link_server+'index/', ... ['hasdeps'], example_dest, index=link_server+'index/',
... links=[link_server, link_server3]) ... links=[link_server, link_server3])
GET 200 /demoneeded-1.2-pyN.N.egg GET 200 /demoneeded-1.2-pyN.N.egg
Script generation Script generation
----------------- -----------------
The easy_install module provides support for creating scripts from The easy_install module provides support for creating scripts from
eggs. It provides a function similar to setuptools except that it eggs. It provides a function similar to setuptools except that it
provides facilities for baking a script's path into the script. This provides facilities for baking a script's path into the script. This
has two advantages: has two advantages:
- The eggs to be used by a script are not chosen at run time, making - The eggs to be used by a script are not chosen at run time, making
startup faster and, more importantly, deterministic. startup faster and, more importantly, deterministic.
- The script doesn't have to import pkg_resources because the logic - The script doesn't have to import pkg_resources because the logic
that pkg_resources would execute at run time is executed at that pkg_resources would execute at run time is executed at
script-creation time. script-creation time.
The scripts method can be used to generate scripts. Let's create a The scripts method can be used to generate scripts. Let's create a
destination directory for it to place them in: destination directory for it to place them in:
>>> import tempfile >>> import tempfile
>>> bin = tmpdir('bin') >>> bin = tmpdir('bin')
Now, we'll use the scripts method to generate scripts in this directory Now, we'll use the scripts method to generate scripts in this directory
from the demo egg: from the demo egg:
>>> import sys >>> import sys
>>> scripts = zc.buildout.easy_install.scripts( >>> scripts = zc.buildout.easy_install.scripts(
... ['demo'], ws, sys.executable, bin) ... ['demo'], ws, sys.executable, bin)
the three arguments we passed were: the three arguments we passed were:
1. A sequence of distribution requirements. These are of the same 1. A sequence of distribution requirements. These are of the same
form as setuptools requirements. Here we passed a single form as setuptools requirements. Here we passed a single
requirement, for the version 0.1 demo distribution. requirement, for the version 0.1 demo distribution.
2. A working set, 2. A working set,
3. The destination directory. 3. The destination directory.
The bin directory now contains a generated script: The bin directory now contains a generated script:
>>> ls(bin) >>> ls(bin)
- demo - demo
The return value is a list of the scripts generated: The return value is a list of the scripts generated:
>>> import os, sys >>> import os, sys
>>> if sys.platform == 'win32': >>> if sys.platform == 'win32':
... scripts == [os.path.join(bin, 'demo.exe'), ... scripts == [os.path.join(bin, 'demo.exe'),
... os.path.join(bin, 'demo-script.py')] ... os.path.join(bin, 'demo-script.py')]
... else: ... else:
... scripts == [os.path.join(bin, 'demo')] ... scripts == [os.path.join(bin, 'demo')]
True True
Note that in Windows, 2 files are generated for each script. A script Note that in Windows, 2 files are generated for each script. A script
file, ending in '-script.py', and an exe file that allows the script file, ending in '-script.py', and an exe file that allows the script
to be invoked directly without having to specify the Python to be invoked directly without having to specify the Python
interpreter and without having to provide a '.py' suffix. interpreter and without having to provide a '.py' suffix.
The demo script run the entry point defined in the demo egg: The demo script run the entry point defined in the demo egg:
>>> cat(bin, 'demo') # doctest: +NORMALIZE_WHITESPACE >>> cat(bin, 'demo') # doctest: +NORMALIZE_WHITESPACE
#!/usr/local/bin/python2.7 #!/usr/local/bin/python2.7
<BLANKLINE> <BLANKLINE>
import sys import sys
sys.path[0:0] = [ sys.path[0:0] = [
'/sample-install/demo-0.3-py2.4.egg', '/sample-install/demo-0.3-py2.4.egg',
'/sample-install/demoneeded-1.1-py2.4.egg', '/sample-install/demoneeded-1.1-py2.4.egg',
] ]
<BLANKLINE> <BLANKLINE>
import eggrecipedemo import eggrecipedemo
<BLANKLINE> <BLANKLINE>
if __name__ == '__main__': if __name__ == '__main__':
sys.exit(eggrecipedemo.main()) sys.exit(eggrecipedemo.main())
Some things to note: Some things to note:
- The demo and demoneeded eggs are added to the beginning of sys.path. - The demo and demoneeded eggs are added to the beginning of sys.path.
- The module for the script entry point is imported and the entry - The module for the script entry point is imported and the entry
point, in this case, 'main', is run. point, in this case, 'main', is run.
Rather than requirement strings, you can pass tuples containing 3 Rather than requirement strings, you can pass tuples containing 3
strings: strings:
- A script name, - A script name,
- A module, - A module,
- An attribute expression for an entry point within the module. - An attribute expression for an entry point within the module.
For example, we could have passed entry point information directly For example, we could have passed entry point information directly
rather than passing a requirement: rather than passing a requirement:
>>> scripts = zc.buildout.easy_install.scripts( >>> scripts = zc.buildout.easy_install.scripts(
... [('demo', 'eggrecipedemo', 'main')], ws, ... [('demo', 'eggrecipedemo', 'main')], ws,
... sys.executable, bin) ... sys.executable, bin)
>>> cat(bin, 'demo') # doctest: +NORMALIZE_WHITESPACE >>> cat(bin, 'demo') # doctest: +NORMALIZE_WHITESPACE
#!/usr/local/bin/python2.7 #!/usr/local/bin/python2.7
<BLANKLINE> <BLANKLINE>
import sys import sys
sys.path[0:0] = [ sys.path[0:0] = [
'/sample-install/demo-0.3-py2.4.egg', '/sample-install/demo-0.3-py2.4.egg',
'/sample-install/demoneeded-1.1-py2.4.egg', '/sample-install/demoneeded-1.1-py2.4.egg',
] ]
<BLANKLINE> <BLANKLINE>
import eggrecipedemo import eggrecipedemo
<BLANKLINE> <BLANKLINE>
if __name__ == '__main__': if __name__ == '__main__':
sys.exit(eggrecipedemo.main()) sys.exit(eggrecipedemo.main())
Passing entry-point information directly is handy when using eggs (or Passing entry-point information directly is handy when using eggs (or
distributions) that don't declare their entry points, such as distributions) that don't declare their entry points, such as
distributions that aren't based on setuptools. distributions that aren't based on setuptools.
The interpreter keyword argument can be used to generate a script that can The interpreter keyword argument can be used to generate a script that can
be used to invoke the Python interactive interpreter with the path set be used to invoke the Python interactive interpreter with the path set
based on the working set. This generated script can also be used to based on the working set. This generated script can also be used to
run other scripts with the path set on the working set: run other scripts with the path set on the working set:
>>> scripts = zc.buildout.easy_install.scripts( >>> scripts = zc.buildout.easy_install.scripts(
... ['demo'], ws, sys.executable, bin, interpreter='py') ... ['demo'], ws, sys.executable, bin, interpreter='py')
>>> ls(bin) >>> ls(bin)
- demo - demo
- py - py
>>> if sys.platform == 'win32': >>> if sys.platform == 'win32':
... scripts == [os.path.join(bin, 'demo.exe'), ... scripts == [os.path.join(bin, 'demo.exe'),
... os.path.join(bin, 'demo-script.py'), ... os.path.join(bin, 'demo-script.py'),
... os.path.join(bin, 'py.exe'), ... os.path.join(bin, 'py.exe'),
... os.path.join(bin, 'py-script.py')] ... os.path.join(bin, 'py-script.py')]
... else: ... else:
... scripts == [os.path.join(bin, 'demo'), ... scripts == [os.path.join(bin, 'demo'),
... os.path.join(bin, 'py')] ... os.path.join(bin, 'py')]
True True
The py script simply runs the Python interactive interpreter with The py script simply runs the Python interactive interpreter with
the path set: the path set:
>>> cat(bin, 'py') # doctest: +NORMALIZE_WHITESPACE >>> cat(bin, 'py') # doctest: +NORMALIZE_WHITESPACE
#!/usr/local/bin/python2.7 #!/usr/local/bin/python2.7
<BLANKLINE> <BLANKLINE>
import sys import sys
<BLANKLINE> <BLANKLINE>
sys.path[0:0] = [ sys.path[0:0] = [
'/sample-install/demo-0.3-pyN.N.egg', '/sample-install/demo-0.3-pyN.N.egg',
'/sample-install/demoneeded-1.1-pyN.N.egg', '/sample-install/demoneeded-1.1-pyN.N.egg',
] ]
<BLANKLINE> <BLANKLINE>
_interactive = True _interactive = True
if len(sys.argv) > 1: if len(sys.argv) > 1:
_options, _args = __import__("getopt").getopt(sys.argv[1:], 'ic:m:') _options, _args = __import__("getopt").getopt(sys.argv[1:], 'ic:m:')
_interactive = False _interactive = False
for (_opt, _val) in _options: for (_opt, _val) in _options:
if _opt == '-i': if _opt == '-i':
_interactive = True _interactive = True
elif _opt == '-c': elif _opt == '-c':
exec _val exec(_val)
elif _opt == '-m': elif _opt == '-m':
sys.argv[1:] = _args sys.argv[1:] = _args
_args = [] _args = []
__import__("runpy").run_module( __import__("runpy").run_module(
_val, {}, "__main__", alter_sys=True) _val, {}, "__main__", alter_sys=True)
<BLANKLINE> <BLANKLINE>
if _args: if _args:
sys.argv[:] = _args sys.argv[:] = _args
__file__ = _args[0] __file__ = _args[0]
del _options, _args del _options, _args
execfile(__file__) __file__f = open(__file__)
<BLANKLINE> exec(compile(__file__f.read(), __file__, "exec"))
if _interactive: __file__f.close(); del __file__f
del _interactive <BLANKLINE>
__import__("code").interact(banner="", local=globals()) if _interactive:
del _interactive
If invoked with a script name and arguments, it will run that script, instead. __import__("code").interact(banner="", local=globals())
>>> write('ascript', ''' If invoked with a script name and arguments, it will run that script, instead.
... "demo doc"
... print sys.argv >>> write('ascript', r'''
... print (__name__, __file__, __doc__) ... "demo doc"
... ''') ... import sys
>>> print system(join(bin, 'py')+' ascript a b c'), ... print_ = lambda *a: sys.stdout.write(' '.join(map(str, a))+'\n')
['ascript', 'a', 'b', 'c'] ... print_(sys.argv)
('__main__', 'ascript', 'demo doc') ... print_((__name__, __file__, __doc__))
... ''')
For Python 2.5 and higher, you can also use the -m option to run a >>> print_(system(join(bin, 'py')+' ascript a b c'), end='')
module: ['ascript', 'a', 'b', 'c']
('__main__', 'ascript', 'demo doc')
>>> print system(join(bin, 'py')+' -m pdb'),
usage: pdb.py scriptfile [arg] ... For Python 2.5 and higher, you can also use the -m option to run a
module:
>>> print system(join(bin, 'py')+' -m pdb what'),
Error: what does not exist >>> print_(system(join(bin, 'py')+' -m pdb'), end='') # doctest: +ELLIPSIS
usage: pdb.py ...
An additional argument can be passed to define which scripts to install
and to provide script names. The argument is a dictionary mapping >>> print_(system(join(bin, 'py')+' -m pdb what'), end='')
original script names to new script names. Error: what does not exist
>>> bin = tmpdir('bin2') An additional argument can be passed to define which scripts to install
>>> scripts = zc.buildout.easy_install.scripts( and to provide script names. The argument is a dictionary mapping
... ['demo'], ws, sys.executable, bin, dict(demo='run')) original script names to new script names.
>>> if sys.platform == 'win32': >>> bin = tmpdir('bin2')
... scripts == [os.path.join(bin, 'run.exe'), >>> scripts = zc.buildout.easy_install.scripts(
... os.path.join(bin, 'run-script.py')] ... ['demo'], ws, sys.executable, bin, dict(demo='run'))
... else:
... scripts == [os.path.join(bin, 'run')] >>> if sys.platform == 'win32':
True ... scripts == [os.path.join(bin, 'run.exe'),
>>> ls(bin) ... os.path.join(bin, 'run-script.py')]
- run ... else:
... scripts == [os.path.join(bin, 'run')]
>>> print system(os.path.join(bin, 'run')), True
3 1 >>> ls(bin)
- run
Including extra paths in scripts
-------------------------------- >>> print_(system(os.path.join(bin, 'run')), end='')
3 1
We can pass a keyword argument, extra paths, to cause additional paths
to be included in the a generated script: Including extra paths in scripts
--------------------------------
>>> foo = tmpdir('foo')
>>> scripts = zc.buildout.easy_install.scripts( We can pass a keyword argument, extra paths, to cause additional paths
... ['demo'], ws, sys.executable, bin, dict(demo='run'), to be included in the a generated script:
... extra_paths=[foo])
>>> foo = tmpdir('foo')
>>> cat(bin, 'run') # doctest: +NORMALIZE_WHITESPACE >>> scripts = zc.buildout.easy_install.scripts(
#!/usr/local/bin/python2.7 ... ['demo'], ws, sys.executable, bin, dict(demo='run'),
<BLANKLINE> ... extra_paths=[foo])
import sys
sys.path[0:0] = [ >>> cat(bin, 'run') # doctest: +NORMALIZE_WHITESPACE
'/sample-install/demo-0.3-py2.4.egg', #!/usr/local/bin/python2.7
'/sample-install/demoneeded-1.1-py2.4.egg', <BLANKLINE>
'/foo', import sys
] sys.path[0:0] = [
<BLANKLINE> '/sample-install/demo-0.3-py2.4.egg',
import eggrecipedemo '/sample-install/demoneeded-1.1-py2.4.egg',
<BLANKLINE> '/foo',
if __name__ == '__main__': ]
sys.exit(eggrecipedemo.main()) <BLANKLINE>
import eggrecipedemo
Providing script arguments <BLANKLINE>
-------------------------- if __name__ == '__main__':
sys.exit(eggrecipedemo.main())
An "argument" keyword argument can be used to pass arguments to an
entry point. The value passed is a source string to be placed between the Providing script arguments
parentheses in the call: --------------------------
>>> scripts = zc.buildout.easy_install.scripts( An "argument" keyword argument can be used to pass arguments to an
... ['demo'], ws, sys.executable, bin, dict(demo='run'), entry point. The value passed is a source string to be placed between the
... arguments='1, 2') parentheses in the call:
>>> cat(bin, 'run') # doctest: +NORMALIZE_WHITESPACE >>> scripts = zc.buildout.easy_install.scripts(
#!/usr/local/bin/python2.7 ... ['demo'], ws, sys.executable, bin, dict(demo='run'),
import sys ... arguments='1, 2')
sys.path[0:0] = [
'/sample-install/demo-0.3-py2.4.egg', >>> cat(bin, 'run') # doctest: +NORMALIZE_WHITESPACE
'/sample-install/demoneeded-1.1-py2.4.egg', #!/usr/local/bin/python2.7
] import sys
<BLANKLINE> sys.path[0:0] = [
import eggrecipedemo '/sample-install/demo-0.3-py2.4.egg',
<BLANKLINE> '/sample-install/demoneeded-1.1-py2.4.egg',
if __name__ == '__main__': ]
sys.exit(eggrecipedemo.main(1, 2)) <BLANKLINE>
import eggrecipedemo
Passing initialization code <BLANKLINE>
--------------------------- if __name__ == '__main__':
sys.exit(eggrecipedemo.main(1, 2))
You can also pass script initialization code:
Passing initialization code
>>> scripts = zc.buildout.easy_install.scripts( ---------------------------
... ['demo'], ws, sys.executable, bin, dict(demo='run'),
... arguments='1, 2', You can also pass script initialization code:
... initialization='import os\nos.chdir("foo")')
>>> scripts = zc.buildout.easy_install.scripts(
>>> cat(bin, 'run') # doctest: +NORMALIZE_WHITESPACE ... ['demo'], ws, sys.executable, bin, dict(demo='run'),
#!/usr/local/bin/python2.7 ... arguments='1, 2',
import sys ... initialization='import os\nos.chdir("foo")')
sys.path[0:0] = [
'/sample-install/demo-0.3-py2.4.egg', >>> cat(bin, 'run') # doctest: +NORMALIZE_WHITESPACE
'/sample-install/demoneeded-1.1-py2.4.egg', #!/usr/local/bin/python2.7
] import sys
<BLANKLINE> sys.path[0:0] = [
import os '/sample-install/demo-0.3-py2.4.egg',
os.chdir("foo") '/sample-install/demoneeded-1.1-py2.4.egg',
<BLANKLINE> ]
import eggrecipedemo <BLANKLINE>
<BLANKLINE> import os
if __name__ == '__main__': os.chdir("foo")
sys.exit(eggrecipedemo.main(1, 2)) <BLANKLINE>
import eggrecipedemo
Relative paths <BLANKLINE>
-------------- if __name__ == '__main__':
sys.exit(eggrecipedemo.main(1, 2))
Sometimes, you want to be able to move a buildout directory around and
have scripts still work without having to rebuild them. We can Relative paths
control this using the relative_paths option to install. You need --------------
to pass a common base directory of the scripts and eggs:
Sometimes, you want to be able to move a buildout directory around and
>>> bo = tmpdir('bo') have scripts still work without having to rebuild them. We can
>>> ba = tmpdir('ba') control this using the relative_paths option to install. You need
>>> mkdir(bo, 'eggs') to pass a common base directory of the scripts and eggs:
>>> mkdir(bo, 'bin')
>>> mkdir(bo, 'other') >>> bo = tmpdir('bo')
>>> ba = tmpdir('ba')
>>> ws = zc.buildout.easy_install.install( >>> mkdir(bo, 'eggs')
... ['demo'], join(bo, 'eggs'), links=[link_server], >>> mkdir(bo, 'bin')
... index=link_server+'index/') >>> mkdir(bo, 'other')
>>> scripts = zc.buildout.easy_install.scripts( >>> ws = zc.buildout.easy_install.install(
... ['demo'], ws, sys.executable, join(bo, 'bin'), dict(demo='run'), ... ['demo'], join(bo, 'eggs'), links=[link_server],
... extra_paths=[ba, join(bo, 'bar')], ... index=link_server+'index/')
... interpreter='py',
... relative_paths=bo) >>> scripts = zc.buildout.easy_install.scripts(
... ['demo'], ws, sys.executable, join(bo, 'bin'), dict(demo='run'),
>>> cat(bo, 'bin', 'run') ... extra_paths=[ba, join(bo, 'bar')],
#!/usr/local/bin/python2.7 ... interpreter='py',
<BLANKLINE> ... relative_paths=bo)
import os
<BLANKLINE> >>> cat(bo, 'bin', 'run')
join = os.path.join #!/usr/local/bin/python2.7
base = os.path.dirname(os.path.abspath(os.path.realpath(__file__))) <BLANKLINE>
base = os.path.dirname(base) import os
<BLANKLINE> <BLANKLINE>
import sys join = os.path.join
sys.path[0:0] = [ base = os.path.dirname(os.path.abspath(os.path.realpath(__file__)))
join(base, 'eggs/demo-0.3-pyN.N.egg'), base = os.path.dirname(base)
join(base, 'eggs/demoneeded-1.1-pyN.N.egg'), <BLANKLINE>
'/ba', import sys
join(base, 'bar'), sys.path[0:0] = [
] join(base, 'eggs/demo-0.3-pyN.N.egg'),
<BLANKLINE> join(base, 'eggs/demoneeded-1.1-pyN.N.egg'),
import eggrecipedemo '/ba',
<BLANKLINE> join(base, 'bar'),
if __name__ == '__main__': ]
sys.exit(eggrecipedemo.main()) <BLANKLINE>
import eggrecipedemo
Note that the extra path we specified that was outside the directory <BLANKLINE>
passed as relative_paths wasn't converted to a relative path. if __name__ == '__main__':
sys.exit(eggrecipedemo.main())
Of course, running the script works:
Note that the extra path we specified that was outside the directory
>>> print system(join(bo, 'bin', 'run')), passed as relative_paths wasn't converted to a relative path.
3 1
Of course, running the script works:
We specified an interpreter and its paths are adjusted too:
>>> print_(system(join(bo, 'bin', 'run')), end='')
>>> cat(bo, 'bin', 'py') 3 1
#!/usr/local/bin/python2.7
<BLANKLINE> We specified an interpreter and its paths are adjusted too:
import os
<BLANKLINE> >>> cat(bo, 'bin', 'py')
join = os.path.join #!/usr/local/bin/python2.7
base = os.path.dirname(os.path.abspath(os.path.realpath(__file__))) <BLANKLINE>
base = os.path.dirname(base) import os
<BLANKLINE> <BLANKLINE>
import sys join = os.path.join
<BLANKLINE> base = os.path.dirname(os.path.abspath(os.path.realpath(__file__)))
sys.path[0:0] = [ base = os.path.dirname(base)
join(base, 'eggs/demo-0.3-pyN.N.egg'), <BLANKLINE>
join(base, 'eggs/demoneeded-1.1-pyN.N.egg'), import sys
'/ba', <BLANKLINE>
join(base, 'bar'), sys.path[0:0] = [
] join(base, 'eggs/demo-0.3-pyN.N.egg'),
<BLANKLINE> join(base, 'eggs/demoneeded-1.1-pyN.N.egg'),
_interactive = True '/ba',
if len(sys.argv) > 1: join(base, 'bar'),
_options, _args = __import__("getopt").getopt(sys.argv[1:], 'ic:m:') ]
_interactive = False <BLANKLINE>
for (_opt, _val) in _options: _interactive = True
if _opt == '-i': if len(sys.argv) > 1:
_interactive = True _options, _args = __import__("getopt").getopt(sys.argv[1:], 'ic:m:')
elif _opt == '-c': _interactive = False
exec _val for (_opt, _val) in _options:
elif _opt == '-m': if _opt == '-i':
sys.argv[1:] = _args _interactive = True
_args = [] elif _opt == '-c':
__import__("runpy").run_module( exec(_val)
_val, {}, "__main__", alter_sys=True) elif _opt == '-m':
<BLANKLINE> sys.argv[1:] = _args
if _args: _args = []
sys.argv[:] = _args __import__("runpy").run_module(
__file__ = _args[0] _val, {}, "__main__", alter_sys=True)
del _options, _args <BLANKLINE>
execfile(__file__) if _args:
<BLANKLINE> sys.argv[:] = _args
if _interactive: __file__ = _args[0]
del _interactive del _options, _args
__import__("code").interact(banner="", local=globals()) __file__f = open(__file__)
exec(compile(__file__f.read(), __file__, "exec"))
__file__f.close(); del __file__f
Installing distutils-style scripts <BLANKLINE>
---------------------------------- if _interactive:
del _interactive
Most python libraries use the console_scripts entry point nowadays. But __import__("code").interact(banner="", local=globals())
several still have a ``scripts=['bin/something']`` in their setup() call.
Buildout also installs those:
Installing distutils-style scripts
>>> distdir = tmpdir('distutilsscriptdir') ----------------------------------
>>> distbin = tmpdir('distutilsscriptbin')
>>> ws = zc.buildout.easy_install.install( Most python libraries use the console_scripts entry point nowadays. But
... ['other'], distdir, several still have a ``scripts=['bin/something']`` in their setup() call.
... links=[link_server], index=link_server+'index/') Buildout also installs those:
>>> scripts = zc.buildout.easy_install.scripts(
... ['other'], ws, sys.executable, distbin) >>> distdir = tmpdir('distutilsscriptdir')
>>> ls(distbin) >>> distbin = tmpdir('distutilsscriptbin')
- distutilsscript >>> ws = zc.buildout.easy_install.install(
... ['other'], distdir,
It also works for zipped eggs: ... links=[link_server], index=link_server+'index/')
>>> scripts = zc.buildout.easy_install.scripts(
>>> distdir2 = tmpdir('distutilsscriptdir2') ... ['other'], ws, sys.executable, distbin)
>>> distbin2 = tmpdir('distutilsscriptbin2') >>> ls(distbin)
>>> ws = zc.buildout.easy_install.install( - distutilsscript
... ['du_zipped'], distdir2,
... links=[link_server], index=link_server+'index/') It also works for zipped eggs:
>>> scripts = zc.buildout.easy_install.scripts(
... ['du_zipped'], ws, sys.executable, distbin2) >>> distdir2 = tmpdir('distutilsscriptdir2')
>>> ls(distbin2) >>> distbin2 = tmpdir('distutilsscriptbin2')
- distutilsscript >>> ws = zc.buildout.easy_install.install(
... ['du_zipped'], distdir2,
Distutils copies the script files verbatim, apart from a line at the top that ... links=[link_server], index=link_server+'index/')
looks like ``#!/usr/bin/python``, which gets replaced by the actual python >>> scripts = zc.buildout.easy_install.scripts(
interpreter. Buildout does the same, but additionally also adds the sys.path ... ['du_zipped'], ws, sys.executable, distbin2)
like for the console_scripts: >>> ls(distbin2)
- distutilsscript
>>> cat(distbin, 'distutilsscript')
#!/usr/local/bin/python2.7 Distutils copies the script files verbatim, apart from a line at the top that
<BLANKLINE> looks like ``#!/usr/bin/python``, which gets replaced by the actual python
import sys interpreter. Buildout does the same, but additionally also adds the sys.path
sys.path[0:0] = [ like for the console_scripts:
'/distutilsscriptdir/other-1.0-pyN.N.egg',
] >>> cat(distbin, 'distutilsscript')
<BLANKLINE> #!/usr/local/bin/python2.7
<BLANKLINE> <BLANKLINE>
print "distutils!" import sys
sys.path[0:0] = [
Due to the nature of distutils scripts, buildout cannot pass arguments as '/distutilsscriptdir/other-1.0-pyN.N.egg',
there's no specific method to pass them to. ]
<BLANKLINE>
<BLANKLINE>
Handling custom build options for extensions provided in source distributions import sys; sys.stdout.write("distutils!\n")
-----------------------------------------------------------------------------
Due to the nature of distutils scripts, buildout cannot pass arguments as
Sometimes, we need to control how extension modules are built. The there's no specific method to pass them to.
build function provides this level of control. It takes a single
package specification, downloads a source distribution, and builds it
with specified custom build options. Handling custom build options for extensions provided in source distributions
-----------------------------------------------------------------------------
The build function takes 3 positional arguments:
Sometimes, we need to control how extension modules are built. The
spec build function provides this level of control. It takes a single
A package specification for a source distribution package specification, downloads a source distribution, and builds it
with specified custom build options.
dest
A destination directory The build function takes 3 positional arguments:
build_ext spec
A dictionary of options to be passed to the distutils build_ext A package specification for a source distribution
command when building extensions.
dest
A destination directory
build_ext
A dictionary of options to be passed to the distutils build_ext
command when building extensions.
It supports a number of optional keyword arguments:
links
a sequence of URLs, file names, or directories to look for
links to distributions,
index
The URL of an index server, or almost any other valid URL. :)
If not specified, the Python Package Index,
http://pypi.python.org/simple/, is used. You can specify an
alternate index with this option. If you use the links option and
if the links point to the needed distributions, then the index can
be anything and will be largely ignored. In the examples, here,
we'll just point to an empty directory on our link server. This
will make our examples run a little bit faster.
path
A list of additional directories to search for locally-installed
distributions.
newest
A boolean value indicating whether to search for new distributions
when already-installed distributions meet the requirement. When
this is true, the default, and when the destination directory is
not None, then the install function will search for the newest
distributions that satisfy the requirements.
versions
A dictionary mapping project names to version numbers to be used
when selecting distributions. This can be used to specify a set of
distribution versions independent of other requirements.
Our link server included a source distribution that includes a simple
extension, extdemo.c::
#include <Python.h>
#include <extdemo.h>
static PyMethodDef methods[] = {};
PyMODINIT_FUNC
initextdemo(void)
{
PyObject *m;
m = Py_InitModule3("extdemo", methods, "");
#ifdef TWO
PyModule_AddObject(m, "val", PyInt_FromLong(2));
#else
PyModule_AddObject(m, "val", PyInt_FromLong(EXTDEMO));
#endif
}
The extension depends on a system-dependent include file, extdemo.h,
that defines a constant, EXTDEMO, that is exposed by the extension.
We'll add an include directory to our sample buildout and add the
needed include file to it:
>>> mkdir('include')
>>> write('include', 'extdemo.h',
... """
... #define EXTDEMO 42
... """)
Now, we can use the build function to create an egg from the source
distribution:
>>> zc.buildout.easy_install.build(
... 'extdemo', dest,
... {'include-dirs': os.path.join(sample_buildout, 'include')},
... links=[link_server], index=link_server+'index/')
['/sample-install/extdemo-1.4-py2.4-unix-i686.egg']
The function returns the list of eggs
Now if we look in our destination directory, we see we have an extdemo egg:
>>> ls(dest)
d demo-0.2-py2.4.egg
d demo-0.3-py2.4.egg
d demoneeded-1.0-py2.4.egg
d demoneeded-1.1-py2.4.egg
d extdemo-1.4-py2.4-unix-i686.egg
Let's update our link server with a new version of extdemo:
>>> update_extdemo()
>>> print_(get(link_server), end='')
<html><body>
<a href="bigdemo-0.1-py2.4.egg">bigdemo-0.1-py2.4.egg</a><br>
<a href="demo-0.1-py2.4.egg">demo-0.1-py2.4.egg</a><br>
<a href="demo-0.2-py2.4.egg">demo-0.2-py2.4.egg</a><br>
<a href="demo-0.3-py2.4.egg">demo-0.3-py2.4.egg</a><br>
<a href="demo-0.4c1-py2.4.egg">demo-0.4c1-py2.4.egg</a><br>
<a href="demoneeded-1.0.zip">demoneeded-1.0.zip</a><br>
<a href="demoneeded-1.1.zip">demoneeded-1.1.zip</a><br>
<a href="demoneeded-1.2c1.zip">demoneeded-1.2c1.zip</a><br>
<a href="du_zipped-1.0-pyN.N.egg">du_zipped-1.0-pyN.N.egg</a><br>
<a href="extdemo-1.4.zip">extdemo-1.4.zip</a><br>
<a href="extdemo-1.5.zip">extdemo-1.5.zip</a><br>
<a href="index/">index/</a><br>
<a href="other-1.0-py2.4.egg">other-1.0-py2.4.egg</a><br>
</body></html>
The easy_install caches information about servers to reduce network
access. To see the update, we have to call the clear_index_cache
function to clear the index cache:
>>> zc.buildout.easy_install.clear_index_cache()
If we run build with newest set to False, we won't get an update:
>>> zc.buildout.easy_install.build(
... 'extdemo', dest,
... {'include-dirs': os.path.join(sample_buildout, 'include')},
... links=[link_server], index=link_server+'index/',
... newest=False)
['/sample-install/extdemo-1.4-py2.4-linux-i686.egg']
>>> ls(dest)
d demo-0.2-py2.4.egg
d demo-0.3-py2.4.egg
d demoneeded-1.0-py2.4.egg
d demoneeded-1.1-py2.4.egg
d extdemo-1.4-py2.4-unix-i686.egg
But if we run it with the default True setting for newest, then we'll
get an updated egg:
>>> zc.buildout.easy_install.build(
... 'extdemo', dest,
... {'include-dirs': os.path.join(sample_buildout, 'include')},
... links=[link_server], index=link_server+'index/')
['/sample-install/extdemo-1.5-py2.4-unix-i686.egg']
>>> ls(dest)
d demo-0.2-py2.4.egg
d demo-0.3-py2.4.egg
d demoneeded-1.0-py2.4.egg
d demoneeded-1.1-py2.4.egg
d extdemo-1.4-py2.4-unix-i686.egg
d extdemo-1.5-py2.4-unix-i686.egg
The versions option also influences the versions used. For example,
if we specify a version for extdemo, then that will be used, even
though it isn't the newest. Let's clean out the destination directory
first:
>>> import os
>>> for name in os.listdir(dest):
... remove(dest, name)
>>> zc.buildout.easy_install.build(
... 'extdemo', dest,
... {'include-dirs': os.path.join(sample_buildout, 'include')},
... links=[link_server], index=link_server+'index/',
... versions=dict(extdemo='1.4'))
['/sample-install/extdemo-1.4-py2.4-unix-i686.egg']
>>> ls(dest)
d extdemo-1.4-py2.4-unix-i686.egg
Handling custom build options for extensions in develop eggs
------------------------------------------------------------
The develop function is similar to the build function, except that,
rather than building an egg from a source directory containing a
setup.py script.
The develop function takes 2 positional arguments:
setup
The path to a setup script, typically named "setup.py", or a
directory containing a setup.py script.
dest
The directory to install the egg link to
It supports some optional keyword argument:
build_ext
A dictionary of options to be passed to the distutils build_ext
command when building extensions.
We have a local directory containing the extdemo source:
>>> ls(extdemo)
- MANIFEST
- MANIFEST.in
- README
- extdemo.c
- setup.py
Now, we can use the develop function to create a develop egg from the source
distribution:
>>> zc.buildout.easy_install.develop(
... extdemo, dest,
... {'include-dirs': os.path.join(sample_buildout, 'include')})
'/sample-install/extdemo.egg-link'
The name of the egg link created is returned.
Now if we look in our destination directory, we see we have an extdemo
egg link:
>>> ls(dest)
d extdemo-1.4-py2.4-unix-i686.egg
- extdemo.egg-link
And that the source directory contains the compiled extension:
>>> ls(extdemo)
- MANIFEST
- MANIFEST.in
- README
d build
- extdemo.c
d extdemo.egg-info
- extdemo.so
- setup.py
Download cache
--------------
Normally, when distributions are installed, if any processing is
needed, they are downloaded from the internet to a temporary directory
and then installed from there. A download cache can be used to avoid
the download step. This can be useful to reduce network access and to
create source distributions of an entire buildout.
A download cache is specified by calling the download_cache
function. The function always returns the previous setting. If no
argument is passed, then the setting is unchanged. If an argument is
passed, the download cache is set to the given path, which must point
to an existing directory. Passing None clears the cache setting.
To see this work, we'll create a directory and set it as the cache
directory:
>>> cache = tmpdir('cache')
>>> zc.buildout.easy_install.download_cache(cache)
We'll recreate our destination directory:
>>> remove(dest)
>>> dest = tmpdir('sample-install')
We'd like to see what is being fetched from the server, so we'll
enable server logging:
>>> get(link_server+'enable_server_logging')
GET 200 /enable_server_logging
''
It supports a number of optional keyword arguments: Now, if we install demo, and extdemo:
links
a sequence of URLs, file names, or directories to look for
links to distributions,
index
The URL of an index server, or almost any other valid URL. :)
If not specified, the Python Package Index,
http://pypi.python.org/simple/, is used. You can specify an
alternate index with this option. If you use the links option and
if the links point to the needed distributions, then the index can
be anything and will be largely ignored. In the examples, here,
we'll just point to an empty directory on our link server. This
will make our examples run a little bit faster.
path
A list of additional directories to search for locally-installed
distributions.
newest
A boolean value indicating whether to search for new distributions
when already-installed distributions meet the requirement. When
this is true, the default, and when the destination directory is
not None, then the install function will search for the newest
distributions that satisfy the requirements.
versions
A dictionary mapping project names to version numbers to be used
when selecting distributions. This can be used to specify a set of
distribution versions independent of other requirements.
Our link server included a source distribution that includes a simple
extension, extdemo.c::
#include <Python.h>
#include <extdemo.h>
static PyMethodDef methods[] = {};
PyMODINIT_FUNC
initextdemo(void)
{
PyObject *m;
m = Py_InitModule3("extdemo", methods, "");
#ifdef TWO
PyModule_AddObject(m, "val", PyInt_FromLong(2));
#else
PyModule_AddObject(m, "val", PyInt_FromLong(EXTDEMO));
#endif
}
The extension depends on a system-dependent include file, extdemo.h,
that defines a constant, EXTDEMO, that is exposed by the extension.
We'll add an include directory to our sample buildout and add the
needed include file to it:
>>> mkdir('include')
>>> write('include', 'extdemo.h',
... """
... #define EXTDEMO 42
... """)
Now, we can use the build function to create an egg from the source
distribution:
>>> zc.buildout.easy_install.build(
... 'extdemo', dest,
... {'include-dirs': os.path.join(sample_buildout, 'include')},
... links=[link_server], index=link_server+'index/')
['/sample-install/extdemo-1.4-py2.4-unix-i686.egg']
The function returns the list of eggs
Now if we look in our destination directory, we see we have an extdemo egg:
>>> ls(dest)
d demo-0.2-py2.4.egg
d demo-0.3-py2.4.egg
d demoneeded-1.0-py2.4.egg
d demoneeded-1.1-py2.4.egg
d extdemo-1.4-py2.4-unix-i686.egg
Let's update our link server with a new version of extdemo:
>>> update_extdemo()
>>> print get(link_server),
<html><body>
<a href="bigdemo-0.1-py2.4.egg">bigdemo-0.1-py2.4.egg</a><br>
<a href="demo-0.1-py2.4.egg">demo-0.1-py2.4.egg</a><br>
<a href="demo-0.2-py2.4.egg">demo-0.2-py2.4.egg</a><br>
<a href="demo-0.3-py2.4.egg">demo-0.3-py2.4.egg</a><br>
<a href="demo-0.4c1-py2.4.egg">demo-0.4c1-py2.4.egg</a><br>
<a href="demoneeded-1.0.zip">demoneeded-1.0.zip</a><br>
<a href="demoneeded-1.1.zip">demoneeded-1.1.zip</a><br>
<a href="demoneeded-1.2c1.zip">demoneeded-1.2c1.zip</a><br>
<a href="du_zipped-1.0-pyN.N.egg">du_zipped-1.0-pyN.N.egg</a><br>
<a href="extdemo-1.4.zip">extdemo-1.4.zip</a><br>
<a href="extdemo-1.5.zip">extdemo-1.5.zip</a><br>
<a href="index/">index/</a><br>
<a href="other-1.0-py2.4.egg">other-1.0-py2.4.egg</a><br>
</body></html>
The easy_install caches information about servers to reduce network
access. To see the update, we have to call the clear_index_cache
function to clear the index cache:
>>> zc.buildout.easy_install.clear_index_cache()
If we run build with newest set to False, we won't get an update:
>>> zc.buildout.easy_install.build(
... 'extdemo', dest,
... {'include-dirs': os.path.join(sample_buildout, 'include')},
... links=[link_server], index=link_server+'index/',
... newest=False)
['/sample-install/extdemo-1.4-py2.4-linux-i686.egg']
>>> ls(dest)
d demo-0.2-py2.4.egg
d demo-0.3-py2.4.egg
d demoneeded-1.0-py2.4.egg
d demoneeded-1.1-py2.4.egg
d extdemo-1.4-py2.4-unix-i686.egg
But if we run it with the default True setting for newest, then we'll
get an updated egg:
>>> zc.buildout.easy_install.build(
... 'extdemo', dest,
... {'include-dirs': os.path.join(sample_buildout, 'include')},
... links=[link_server], index=link_server+'index/')
['/sample-install/extdemo-1.5-py2.4-unix-i686.egg']
>>> ls(dest)
d demo-0.2-py2.4.egg
d demo-0.3-py2.4.egg
d demoneeded-1.0-py2.4.egg
d demoneeded-1.1-py2.4.egg
d extdemo-1.4-py2.4-unix-i686.egg
d extdemo-1.5-py2.4-unix-i686.egg
The versions option also influences the versions used. For example,
if we specify a version for extdemo, then that will be used, even
though it isn't the newest. Let's clean out the destination directory
first:
>>> import os
>>> for name in os.listdir(dest):
... remove(dest, name)
>>> zc.buildout.easy_install.build(
... 'extdemo', dest,
... {'include-dirs': os.path.join(sample_buildout, 'include')},
... links=[link_server], index=link_server+'index/',
... versions=dict(extdemo='1.4'))
['/sample-install/extdemo-1.4-py2.4-unix-i686.egg']
>>> ls(dest)
d extdemo-1.4-py2.4-unix-i686.egg
Handling custom build options for extensions in develop eggs
------------------------------------------------------------
The develop function is similar to the build function, except that,
rather than building an egg from a source directory containing a
setup.py script.
The develop function takes 2 positional arguments:
setup
The path to a setup script, typically named "setup.py", or a
directory containing a setup.py script.
dest
The directory to install the egg link to
It supports some optional keyword argument:
build_ext
A dictionary of options to be passed to the distutils build_ext
command when building extensions.
We have a local directory containing the extdemo source:
>>> ls(extdemo)
- MANIFEST
- MANIFEST.in
- README
- extdemo.c
- setup.py
Now, we can use the develop function to create a develop egg from the source
distribution:
>>> zc.buildout.easy_install.develop(
... extdemo, dest,
... {'include-dirs': os.path.join(sample_buildout, 'include')})
'/sample-install/extdemo.egg-link'
The name of the egg link created is returned.
Now if we look in our destination directory, we see we have an extdemo
egg link:
>>> ls(dest)
d extdemo-1.4-py2.4-unix-i686.egg
- extdemo.egg-link
And that the source directory contains the compiled extension:
>>> ls(extdemo)
- MANIFEST
- MANIFEST.in
- README
d build
- extdemo.c
d extdemo.egg-info
- extdemo.so
- setup.py
Download cache
--------------
Normally, when distributions are installed, if any processing is
needed, they are downloaded from the internet to a temporary directory
and then installed from there. A download cache can be used to avoid
the download step. This can be useful to reduce network access and to
create source distributions of an entire buildout.
A download cache is specified by calling the download_cache
function. The function always returns the previous setting. If no
argument is passed, then the setting is unchanged. If an argument is
passed, the download cache is set to the given path, which must point
to an existing directory. Passing None clears the cache setting.
To see this work, we'll create a directory and set it as the cache
directory:
>>> cache = tmpdir('cache')
>>> zc.buildout.easy_install.download_cache(cache)
We'll recreate our destination directory:
>>> remove(dest)
>>> dest = tmpdir('sample-install')
We'd like to see what is being fetched from the server, so we'll
enable server logging:
>>> get(link_server+'enable_server_logging')
GET 200 /enable_server_logging
''
Now, if we install demo, and extdemo:
>>> ws = zc.buildout.easy_install.install( >>> ws = zc.buildout.easy_install.install(
... ['demo==0.2'], dest, ... ['demo==0.2'], dest,
... links=[link_server], index=link_server+'index/') ... links=[link_server], index=link_server+'index/')
GET 200 / GET 200 /
GET 404 /index/demo/ GET 404 /index/demo/
GET 200 /index/ GET 200 /index/
GET 200 /demo-0.2-py2.4.egg GET 200 /demo-0.2-py2.4.egg
GET 404 /index/demoneeded/ GET 404 /index/demoneeded/
GET 200 /demoneeded-1.1.zip GET 200 /demoneeded-1.1.zip
>>> zc.buildout.easy_install.build( >>> zc.buildout.easy_install.build(
... 'extdemo', dest, ... 'extdemo', dest,
... {'include-dirs': os.path.join(sample_buildout, 'include')}, ... {'include-dirs': os.path.join(sample_buildout, 'include')},
... links=[link_server], index=link_server+'index/') ... links=[link_server], index=link_server+'index/')
GET 404 /index/extdemo/ GET 404 /index/extdemo/
GET 200 /extdemo-1.5.zip GET 200 /extdemo-1.5.zip
['/sample-install/extdemo-1.5-py2.4-linux-i686.egg'] ['/sample-install/extdemo-1.5-py2.4-linux-i686.egg']
Not only will we get eggs in our destination directory: Not only will we get eggs in our destination directory:
>>> ls(dest) >>> ls(dest)
d demo-0.2-py2.4.egg d demo-0.2-py2.4.egg
d demoneeded-1.1-py2.4.egg d demoneeded-1.1-py2.4.egg
d extdemo-1.5-py2.4-linux-i686.egg d extdemo-1.5-py2.4-linux-i686.egg
But we'll get distributions in the cache directory: But we'll get distributions in the cache directory:
>>> ls(cache) >>> ls(cache)
- demo-0.2-py2.4.egg - demo-0.2-py2.4.egg
- demoneeded-1.1.zip - demoneeded-1.1.zip
- extdemo-1.5.zip - extdemo-1.5.zip
The cache directory contains uninstalled distributions, such as zipped The cache directory contains uninstalled distributions, such as zipped
eggs or source distributions. eggs or source distributions.
Let's recreate our destination directory and clear the index cache: Let's recreate our destination directory and clear the index cache:
>>> remove(dest) >>> remove(dest)
>>> dest = tmpdir('sample-install') >>> dest = tmpdir('sample-install')
>>> zc.buildout.easy_install.clear_index_cache() >>> zc.buildout.easy_install.clear_index_cache()
Now when we install the distributions: Now when we install the distributions:
>>> ws = zc.buildout.easy_install.install( >>> ws = zc.buildout.easy_install.install(
... ['demo==0.2'], dest, ... ['demo==0.2'], dest,
... links=[link_server], index=link_server+'index/') ... links=[link_server], index=link_server+'index/')
GET 200 / GET 200 /
GET 404 /index/demo/ GET 404 /index/demo/
GET 200 /index/ GET 200 /index/
GET 404 /index/demoneeded/ GET 404 /index/demoneeded/
>>> zc.buildout.easy_install.build( >>> zc.buildout.easy_install.build(
... 'extdemo', dest, ... 'extdemo', dest,
... {'include-dirs': os.path.join(sample_buildout, 'include')}, ... {'include-dirs': os.path.join(sample_buildout, 'include')},
... links=[link_server], index=link_server+'index/') ... links=[link_server], index=link_server+'index/')
GET 404 /index/extdemo/ GET 404 /index/extdemo/
['/sample-install/extdemo-1.5-py2.4-linux-i686.egg'] ['/sample-install/extdemo-1.5-py2.4-linux-i686.egg']
>>> ls(dest) >>> ls(dest)
d demo-0.2-py2.4.egg d demo-0.2-py2.4.egg
d demoneeded-1.1-py2.4.egg d demoneeded-1.1-py2.4.egg
d extdemo-1.5-py2.4-linux-i686.egg d extdemo-1.5-py2.4-linux-i686.egg
Note that we didn't download the distributions from the link server. Note that we didn't download the distributions from the link server.
If we remove the restriction on demo, we'll download a newer version If we remove the restriction on demo, we'll download a newer version
from the link server: from the link server:
>>> ws = zc.buildout.easy_install.install( >>> ws = zc.buildout.easy_install.install(
... ['demo'], dest, ... ['demo'], dest,
... links=[link_server], index=link_server+'index/') ... links=[link_server], index=link_server+'index/')
GET 200 /demo-0.3-py2.4.egg GET 200 /demo-0.3-py2.4.egg
Normally, the download cache is the preferred source of downloads, but Normally, the download cache is the preferred source of downloads, but
not the only one. not the only one.
Installing solely from a download cache Installing solely from a download cache
--------------------------------------- ---------------------------------------
A download cache can be used as the basis of application source A download cache can be used as the basis of application source
releases. In an application source release, we want to distribute an releases. In an application source release, we want to distribute an
application that can be built without making any network accesses. In application that can be built without making any network accesses. In
this case, we distribute a download cache and tell the easy_install this case, we distribute a download cache and tell the easy_install
module to install from the download cache only, without making network module to install from the download cache only, without making network
accesses. The install_from_cache function can be used to signal that accesses. The install_from_cache function can be used to signal that
packages should be installed only from the download cache. The packages should be installed only from the download cache. The
function always returns the previous setting. Calling it with no function always returns the previous setting. Calling it with no
arguments returns the current setting without changing it: arguments returns the current setting without changing it:
>>> zc.buildout.easy_install.install_from_cache() >>> zc.buildout.easy_install.install_from_cache()
False False
Calling it with a boolean value changes the setting and returns the Calling it with a boolean value changes the setting and returns the
previous setting: previous setting:
>>> zc.buildout.easy_install.install_from_cache(True) >>> zc.buildout.easy_install.install_from_cache(True)
False False
Let's remove demo-0.3-py2.4.egg from the cache, clear the index cache, Let's remove demo-0.3-py2.4.egg from the cache, clear the index cache,
recreate the destination directory, and reinstall demo: recreate the destination directory, and reinstall demo:
>>> for f in os.listdir(cache): >>> for f in os.listdir(cache):
... if f.startswith('demo-0.3-'): ... if f.startswith('demo-0.3-'):
... remove(cache, f) ... remove(cache, f)
>>> zc.buildout.easy_install.clear_index_cache() >>> zc.buildout.easy_install.clear_index_cache()
>>> remove(dest) >>> remove(dest)
>>> dest = tmpdir('sample-install') >>> dest = tmpdir('sample-install')
>>> ws = zc.buildout.easy_install.install( >>> ws = zc.buildout.easy_install.install(
... ['demo'], dest, ... ['demo'], dest,
... links=[link_server], index=link_server+'index/') ... links=[link_server], index=link_server+'index/')
>>> ls(dest) >>> ls(dest)
d demo-0.2-py2.4.egg d demo-0.2-py2.4.egg
d demoneeded-1.1-py2.4.egg d demoneeded-1.1-py2.4.egg
This time, we didn't download from or even query the link server. This time, we didn't download from or even query the link server.
.. Disable the download cache: .. Disable the download cache:
>>> zc.buildout.easy_install.download_cache(None) >>> zc.buildout.easy_install.download_cache(None)
'/cache' '/cache'
>>> zc.buildout.easy_install.install_from_cache(False) >>> zc.buildout.easy_install.install_from_cache(False)
True True
...@@ -41,20 +41,20 @@ buildout: ...@@ -41,20 +41,20 @@ buildout:
When trying to run this buildout offline, we'll find that we cannot read all When trying to run this buildout offline, we'll find that we cannot read all
of the required configuration: of the required configuration:
>>> print system(buildout + ' -o') >>> print_(system(buildout + ' -o'))
While: While:
Initializing. Initializing.
Error: Couldn't download 'http://localhost/base.cfg' in offline mode. Error: Couldn't download 'http://localhost/base.cfg' in offline mode.
Trying the same online, we can: Trying the same online, we can:
>>> print system(buildout) >>> print_(system(buildout))
Unused options for buildout: 'foo'. Unused options for buildout: 'foo'.
As long as we haven't said anything about caching downloaded configuration, As long as we haven't said anything about caching downloaded configuration,
nothing gets cached. Offline mode will still cause the buildout to fail: nothing gets cached. Offline mode will still cause the buildout to fail:
>>> print system(buildout + ' -o') >>> print_(system(buildout + ' -o'))
While: While:
Initializing. Initializing.
Error: Couldn't download 'http://localhost/base.cfg' in offline mode. Error: Couldn't download 'http://localhost/base.cfg' in offline mode.
...@@ -73,7 +73,7 @@ being a hash of the complete URL): ...@@ -73,7 +73,7 @@ being a hash of the complete URL):
... extends-cache = cache ... extends-cache = cache
... """ % server_url) ... """ % server_url)
>>> print system(buildout) >>> print_(system(buildout))
Unused options for buildout: 'foo'. Unused options for buildout: 'foo'.
>>> cache = join(sample_buildout, 'cache') >>> cache = join(sample_buildout, 'cache')
...@@ -88,7 +88,7 @@ foo = bar ...@@ -88,7 +88,7 @@ foo = bar
We can now run buildout offline as it will read base.cfg from the cache: We can now run buildout offline as it will read base.cfg from the cache:
>>> print system(buildout + ' -o') >>> print_(system(buildout + ' -o'))
Unused options for buildout: 'foo'. Unused options for buildout: 'foo'.
The cache is being used purely as a fall-back in case we are offline or don't The cache is being used purely as a fall-back in case we are offline or don't
...@@ -104,18 +104,18 @@ base.cfg from the cache: ...@@ -104,18 +104,18 @@ base.cfg from the cache:
... bar = baz ... bar = baz
... """) ... """)
>>> print system(buildout + ' -o') >>> print_(system(buildout + ' -o'))
Unused options for buildout: 'foo'. Unused options for buildout: 'foo'.
In online mode, buildout will download and use the modified version: In online mode, buildout will download and use the modified version:
>>> print system(buildout) >>> print_(system(buildout))
Unused options for buildout: 'bar'. Unused options for buildout: 'bar'.
Trying offline mode again, the new version will be used as it has been put in Trying offline mode again, the new version will be used as it has been put in
the cache now: the cache now:
>>> print system(buildout + ' -o') >>> print_(system(buildout + ' -o'))
Unused options for buildout: 'bar'. Unused options for buildout: 'bar'.
Clean up: Clean up:
...@@ -203,7 +203,7 @@ bases, using different caches: ...@@ -203,7 +203,7 @@ bases, using different caches:
Buildout will now assemble its configuration from all of these 6 files, Buildout will now assemble its configuration from all of these 6 files,
defaults first. The online resources end up in the respective extends caches: defaults first. The online resources end up in the respective extends caches:
>>> print system(buildout) >>> print_(system(buildout))
Unused options for buildout: 'foo'. Unused options for buildout: 'foo'.
>>> ls('user-cache') >>> ls('user-cache')
...@@ -249,7 +249,7 @@ Let's rewrite the config files, clean out the caches and re-run buildout: ...@@ -249,7 +249,7 @@ Let's rewrite the config files, clean out the caches and re-run buildout:
>>> remove('user-cache', os.listdir('user-cache')[0]) >>> remove('user-cache', os.listdir('user-cache')[0])
>>> remove('cache', os.listdir('cache')[0]) >>> remove('cache', os.listdir('cache')[0])
>>> print system(buildout) >>> print_(system(buildout))
Unused options for buildout: 'foo'. Unused options for buildout: 'foo'.
>>> ls('user-cache') >>> ls('user-cache')
...@@ -272,7 +272,7 @@ Offline mode and installation from cache ...@@ -272,7 +272,7 @@ Offline mode and installation from cache
If we run buildout in offline mode now, it will fail because it cannot get at If we run buildout in offline mode now, it will fail because it cannot get at
the remote configuration file needed by the user's defaults: the remote configuration file needed by the user's defaults:
>>> print system(buildout + ' -o') >>> print_(system(buildout + ' -o'))
While: While:
Initializing. Initializing.
Error: Couldn't download 'http://localhost/base_default.cfg' in offline mode. Error: Couldn't download 'http://localhost/base_default.cfg' in offline mode.
...@@ -285,7 +285,7 @@ configuration and see when buildout applies this setting in each case: ...@@ -285,7 +285,7 @@ configuration and see when buildout applies this setting in each case:
... extends = fancy_default.cfg ... extends = fancy_default.cfg
... offline = true ... offline = true
... """) ... """)
>>> print system(buildout) >>> print_(system(buildout))
While: While:
Initializing. Initializing.
Error: Couldn't download 'http://localhost/base_default.cfg' in offline mode. Error: Couldn't download 'http://localhost/base_default.cfg' in offline mode.
...@@ -299,7 +299,7 @@ Error: Couldn't download 'http://localhost/base_default.cfg' in offline mode. ...@@ -299,7 +299,7 @@ Error: Couldn't download 'http://localhost/base_default.cfg' in offline mode.
... extends = %sbase_default.cfg ... extends = %sbase_default.cfg
... offline = true ... offline = true
... """ % server_url) ... """ % server_url)
>>> print system(buildout) >>> print_(system(buildout))
While: While:
Initializing. Initializing.
Error: Couldn't download 'http://localhost/base.cfg' in offline mode. Error: Couldn't download 'http://localhost/base.cfg' in offline mode.
...@@ -313,7 +313,7 @@ Error: Couldn't download 'http://localhost/base.cfg' in offline mode. ...@@ -313,7 +313,7 @@ Error: Couldn't download 'http://localhost/base.cfg' in offline mode.
... extends = fancy.cfg ... extends = fancy.cfg
... offline = true ... offline = true
... """) ... """)
>>> print system(buildout) >>> print_(system(buildout))
While: While:
Initializing. Initializing.
Error: Couldn't download 'http://localhost/base.cfg' in offline mode. Error: Couldn't download 'http://localhost/base.cfg' in offline mode.
...@@ -327,7 +327,7 @@ Error: Couldn't download 'http://localhost/base.cfg' in offline mode. ...@@ -327,7 +327,7 @@ Error: Couldn't download 'http://localhost/base.cfg' in offline mode.
... extends = %sbase.cfg ... extends = %sbase.cfg
... offline = true ... offline = true
... """ % server_url) ... """ % server_url)
>>> print system(buildout) >>> print_(system(buildout))
Unused options for buildout: 'foo'. Unused options for buildout: 'foo'.
The ``install-from-cache`` option is treated accordingly: The ``install-from-cache`` option is treated accordingly:
...@@ -337,7 +337,7 @@ The ``install-from-cache`` option is treated accordingly: ...@@ -337,7 +337,7 @@ The ``install-from-cache`` option is treated accordingly:
... extends = fancy_default.cfg ... extends = fancy_default.cfg
... install-from-cache = true ... install-from-cache = true
... """) ... """)
>>> print system(buildout) >>> print_(system(buildout))
While: While:
Initializing. Initializing.
Error: Couldn't download 'http://localhost/base_default.cfg' in offline mode. Error: Couldn't download 'http://localhost/base_default.cfg' in offline mode.
...@@ -351,7 +351,7 @@ Error: Couldn't download 'http://localhost/base_default.cfg' in offline mode. ...@@ -351,7 +351,7 @@ Error: Couldn't download 'http://localhost/base_default.cfg' in offline mode.
... extends = %sbase_default.cfg ... extends = %sbase_default.cfg
... install-from-cache = true ... install-from-cache = true
... """ % server_url) ... """ % server_url)
>>> print system(buildout) >>> print_(system(buildout))
While: While:
Initializing. Initializing.
Error: Couldn't download 'http://localhost/base.cfg' in offline mode. Error: Couldn't download 'http://localhost/base.cfg' in offline mode.
...@@ -365,7 +365,7 @@ Error: Couldn't download 'http://localhost/base.cfg' in offline mode. ...@@ -365,7 +365,7 @@ Error: Couldn't download 'http://localhost/base.cfg' in offline mode.
... extends = fancy.cfg ... extends = fancy.cfg
... install-from-cache = true ... install-from-cache = true
... """) ... """)
>>> print system(buildout) >>> print_(system(buildout))
While: While:
Initializing. Initializing.
Error: Couldn't download 'http://localhost/base.cfg' in offline mode. Error: Couldn't download 'http://localhost/base.cfg' in offline mode.
...@@ -379,7 +379,7 @@ Error: Couldn't download 'http://localhost/base.cfg' in offline mode. ...@@ -379,7 +379,7 @@ Error: Couldn't download 'http://localhost/base.cfg' in offline mode.
... extends = %sbase.cfg ... extends = %sbase.cfg
... install-from-cache = true ... install-from-cache = true
... """ % server_url) ... """ % server_url)
>>> print system(buildout) >>> print_(system(buildout))
While: While:
Installing. Installing.
Checking for upgrades. Checking for upgrades.
...@@ -406,7 +406,7 @@ is already present locally. If we run buildout in newest mode ...@@ -406,7 +406,7 @@ is already present locally. If we run buildout in newest mode
... extends-cache = cache ... extends-cache = cache
... extends = %sbase.cfg ... extends = %sbase.cfg
... """ % server_url) ... """ % server_url)
>>> print system(buildout) >>> print_(system(buildout))
>>> ls('cache') >>> ls('cache')
- 5aedc98d7e769290a29d654a591a3a45 - 5aedc98d7e769290a29d654a591a3a45
>>> cat('cache', os.listdir(cache)[0]) >>> cat('cache', os.listdir(cache)[0])
...@@ -420,7 +420,7 @@ A change to ``base.cfg`` is picked up on the next buildout run: ...@@ -420,7 +420,7 @@ A change to ``base.cfg`` is picked up on the next buildout run:
... parts = ... parts =
... foo = bar ... foo = bar
... """) ... """)
>>> print system(buildout + " -n") >>> print_(system(buildout + " -n"))
Unused options for buildout: 'foo'. Unused options for buildout: 'foo'.
>>> cat('cache', os.listdir(cache)[0]) >>> cat('cache', os.listdir(cache)[0])
[buildout] [buildout]
...@@ -434,7 +434,7 @@ already present in the extends cache will not be updated: ...@@ -434,7 +434,7 @@ already present in the extends cache will not be updated:
... [buildout] ... [buildout]
... parts = ... parts =
... """) ... """)
>>> print system(buildout + " -N") >>> print_(system(buildout + " -N"))
Unused options for buildout: 'foo'. Unused options for buildout: 'foo'.
>>> cat('cache', os.listdir(cache)[0]) >>> cat('cache', os.listdir(cache)[0])
[buildout] [buildout]
...@@ -463,7 +463,7 @@ used: ...@@ -463,7 +463,7 @@ used:
... newest = true ... newest = true
... extends = %sbaseA.cfg %sbaseB.cfg ... extends = %sbaseA.cfg %sbaseB.cfg
... """ % (server_url, server_url)) ... """ % (server_url, server_url))
>>> print system(buildout + " -n") >>> print_(system(buildout + " -n"))
Unused options for buildout: 'bar' 'foo'. Unused options for buildout: 'bar' 'foo'.
(XXX We patch download utility's API to produce readable output for the test; (XXX We patch download utility's API to produce readable output for the test;
...@@ -472,7 +472,7 @@ a better solution would utilise the logging already done by the utility.) ...@@ -472,7 +472,7 @@ a better solution would utilise the logging already done by the utility.)
>>> import zc.buildout >>> import zc.buildout
>>> old_download = zc.buildout.download.Download.download >>> old_download = zc.buildout.download.Download.download
>>> def wrapper_download(self, url, md5sum=None, path=None): >>> def wrapper_download(self, url, md5sum=None, path=None):
... print "The URL %s was downloaded." % url ... print_("The URL %s was downloaded." % url)
... return old_download(url, md5sum, path) ... return old_download(url, md5sum, path)
>>> zc.buildout.download.Download.download = wrapper_download >>> zc.buildout.download.Download.download = wrapper_download
...@@ -499,7 +499,7 @@ UserError is raised if that option is encountered now: ...@@ -499,7 +499,7 @@ UserError is raised if that option is encountered now:
... parts = ... parts =
... extended-by = foo.cfg ... extended-by = foo.cfg
... """) ... """)
>>> print system(buildout) >>> print_(system(buildout))
While: While:
Initializing. Initializing.
Error: No-longer supported "extended-by" option found in http://localhost/base.cfg. Error: No-longer supported "extended-by" option found in http://localhost/base.cfg.
......
...@@ -38,7 +38,8 @@ This document tests the 3rd option. ...@@ -38,7 +38,8 @@ This document tests the 3rd option.
>>> sample_buildout = tmpdir('sample') >>> sample_buildout = tmpdir('sample')
>>> cd(sample_buildout) >>> cd(sample_buildout)
>>> import sys >>> import sys
>>> print system("%s -S %s init demo" % (sys.executable, bootstrap_py)), >>> print_(system("%s -S %s init demo" % (sys.executable, bootstrap_py)),
... end='')
... # doctest: +ELLIPSIS ... # doctest: +ELLIPSIS
Downloading http://pypi.python.org/packages/source/d/distribute/... Downloading http://pypi.python.org/packages/source/d/distribute/...
Creating '/sample/buildout.cfg'. Creating '/sample/buildout.cfg'.
...@@ -78,10 +79,10 @@ The -S option is also used when invoking setup scripts. ...@@ -78,10 +79,10 @@ The -S option is also used when invoking setup scripts.
>>> write('proj', 'setup.py', """ >>> write('proj', 'setup.py', """
... from distutils.core import setup ... from distutils.core import setup
... import sys ... import sys
... print 'site:', 'site' in sys.modules ... print_('site:', 'site' in sys.modules)
... setup(name='hassite') ... setup(name='hassite')
... """) ... """)
>>> print system(join('bin', 'buildout')+' setup proj sdist') >>> print_(system(join('bin', 'buildout')+' setup proj sdist'))
... # doctest: +ELLIPSIS ... # doctest: +ELLIPSIS
Running setup script 'proj/setup.py'. Running setup script 'proj/setup.py'.
site: True site: True
...@@ -95,7 +96,7 @@ The -S option is also used when invoking setup scripts. ...@@ -95,7 +96,7 @@ The -S option is also used when invoking setup scripts.
... recipe = zc.recipe.egg ... recipe = zc.recipe.egg
... eggs = hassite ... eggs = hassite
... """ % join('proj', 'dist')) ... """ % join('proj', 'dist'))
>>> print system(join('bin', 'buildout')) >>> print_(system(join('bin', 'buildout')))
... # doctest: +ELLIPSIS ... # doctest: +ELLIPSIS
Uninstalling py. Uninstalling py.
Installing egg. Installing egg.
...@@ -110,7 +111,7 @@ The -S option is also used when invoking setup scripts. ...@@ -110,7 +111,7 @@ The -S option is also used when invoking setup scripts.
... parts = ... parts =
... develop = %s ... develop = %s
... """ % join('proj')) ... """ % join('proj'))
>>> print system(join('bin', 'buildout')) >>> print_(system(join('bin', 'buildout')))
... # doctest: +ELLIPSIS ... # doctest: +ELLIPSIS
Develop: '/sample/proj' Develop: '/sample/proj'
site: True site: True
......
...@@ -21,10 +21,12 @@ To see how this works, we'll create two versions of a recipe egg: ...@@ -21,10 +21,12 @@ To see how this works, we'll create two versions of a recipe egg:
>>> mkdir('recipe') >>> mkdir('recipe')
>>> write('recipe', 'recipe.py', >>> write('recipe', 'recipe.py',
... ''' ... '''
... import sys
... print_ = lambda *a: sys.stdout.write(' '.join(map(str, a))+'\n')
... class Recipe: ... class Recipe:
... def __init__(*a): pass ... def __init__(*a): pass
... def install(self): ... def install(self):
... print 'recipe v1' ... print_('recipe v1')
... return () ... return ()
... update = install ... update = install
... ''') ... ''')
...@@ -39,7 +41,7 @@ To see how this works, we'll create two versions of a recipe egg: ...@@ -39,7 +41,7 @@ To see how this works, we'll create two versions of a recipe egg:
>>> write('recipe', 'README', '') >>> write('recipe', 'README', '')
>>> print system(buildout+' setup recipe bdist_egg'), # doctest: +ELLIPSIS >>> print_(system(buildout+' setup recipe bdist_egg')) # doctest: +ELLIPSIS
Running setup script 'recipe/setup.py'. Running setup script 'recipe/setup.py'.
... ...
...@@ -47,10 +49,12 @@ To see how this works, we'll create two versions of a recipe egg: ...@@ -47,10 +49,12 @@ To see how this works, we'll create two versions of a recipe egg:
>>> write('recipe', 'recipe.py', >>> write('recipe', 'recipe.py',
... ''' ... '''
... import sys
... print_ = lambda *a: sys.stdout.write(' '.join(map(str, a))+'\n')
... class Recipe: ... class Recipe:
... def __init__(*a): pass ... def __init__(*a): pass
... def install(self): ... def install(self):
... print 'recipe v2' ... print_('recipe v2')
... return () ... return ()
... update = install ... update = install
... ''') ... ''')
...@@ -64,7 +68,7 @@ To see how this works, we'll create two versions of a recipe egg: ...@@ -64,7 +68,7 @@ To see how this works, we'll create two versions of a recipe egg:
... ''') ... ''')
>>> print system(buildout+' setup recipe bdist_egg'), # doctest: +ELLIPSIS >>> print_(system(buildout+' setup recipe bdist_egg')) # doctest: +ELLIPSIS
Running setup script 'recipe/setup.py'. Running setup script 'recipe/setup.py'.
... ...
...@@ -82,7 +86,7 @@ and we'll configure a buildout to use it: ...@@ -82,7 +86,7 @@ and we'll configure a buildout to use it:
If we run the buildout, it will use version 2: If we run the buildout, it will use version 2:
>>> print system(buildout), >>> print_(system(buildout), end='')
Getting distribution for 'spam'. Getting distribution for 'spam'.
Got spam 2. Got spam 2.
Installing foo. Installing foo.
...@@ -112,7 +116,7 @@ as in the versions option. ...@@ -112,7 +116,7 @@ as in the versions option.
Now, if we run the buildout, we'll use version 1 of the spam recipe: Now, if we run the buildout, we'll use version 1 of the spam recipe:
>>> print system(buildout), >>> print_(system(buildout), end='')
Getting distribution for 'spam==1'. Getting distribution for 'spam==1'.
Got spam 1. Got spam 1.
Uninstalling foo. Uninstalling foo.
...@@ -123,7 +127,7 @@ Running the buildout in verbose mode will help us get information ...@@ -123,7 +127,7 @@ Running the buildout in verbose mode will help us get information
about versions used. If we run the buildout in verbose mode without about versions used. If we run the buildout in verbose mode without
specifying a versions section: specifying a versions section:
>>> print system(buildout+' buildout:versions= -v'), # doctest: +ELLIPSIS >>> print_(system(buildout+' buildout:versions= -v'), end='')
Installing 'zc.buildout', 'distribute'. Installing 'zc.buildout', 'distribute'.
We have a develop egg: zc.buildout 1.0.0. We have a develop egg: zc.buildout 1.0.0.
We have the best distribution that satisfies 'distribute'. We have the best distribution that satisfies 'distribute'.
...@@ -145,7 +149,7 @@ that we can fix them in a versions section. ...@@ -145,7 +149,7 @@ that we can fix them in a versions section.
If we run the buildout with the versions section: If we run the buildout with the versions section:
>>> print system(buildout+' -v'), # doctest: +ELLIPSIS >>> print_(system(buildout+' -v'), end='')
Installing 'zc.buildout', 'distribute'. Installing 'zc.buildout', 'distribute'.
We have a develop egg: zc.buildout 1.0.0. We have a develop egg: zc.buildout 1.0.0.
We have the best distribution that satisfies 'distribute'. We have the best distribution that satisfies 'distribute'.
......
...@@ -42,7 +42,7 @@ def rmtree (path): ...@@ -42,7 +42,7 @@ def rmtree (path):
and make it unwriteable and make it unwriteable
>>> os.chmod (foo, 0400) >>> os.chmod (foo, 0o400)
rmtree should be able to remove it: rmtree should be able to remove it:
...@@ -54,7 +54,7 @@ def rmtree (path): ...@@ -54,7 +54,7 @@ def rmtree (path):
0 0
""" """
def retry_writeable (func, path, exc): def retry_writeable (func, path, exc):
os.chmod (path, 0600) os.chmod (path, 0o600)
func (path) func (path)
shutil.rmtree (path, onerror = retry_writeable) shutil.rmtree (path, onerror = retry_writeable)
...@@ -64,3 +64,4 @@ def test_suite(): ...@@ -64,3 +64,4 @@ def test_suite():
if "__main__" == __name__: if "__main__" == __name__:
doctest.testmod() doctest.testmod()
...@@ -17,7 +17,8 @@ commands, like bdist_egg even with packages that don't use setuptools. ...@@ -17,7 +17,8 @@ commands, like bdist_egg even with packages that don't use setuptools.
To illustrate this, we'll create a package in a sample buildout: To illustrate this, we'll create a package in a sample buildout:
>>> mkdir('hello') >>> mkdir('hello')
>>> write('hello', 'hello.py', 'print "Hello World!"') >>> write('hello', 'hello.py',
... 'import sys; sys.stdout.write("Hello World!\n")\n')
>>> write('hello', 'README', 'This is hello') >>> write('hello', 'README', 'This is hello')
>>> write('hello', 'setup.py', >>> write('hello', 'setup.py',
... """ ... """
...@@ -32,7 +33,7 @@ To illustrate this, we'll create a package in a sample buildout: ...@@ -32,7 +33,7 @@ To illustrate this, we'll create a package in a sample buildout:
We can use the buildout command to generate the hello egg: We can use the buildout command to generate the hello egg:
>>> print system(buildout +' setup hello -q bdist_egg'), >>> print_(system(buildout +' setup hello -q bdist_egg'), end='')
Running setup script 'hello/setup.py'. Running setup script 'hello/setup.py'.
zip_safe flag not set; analyzing archive contents... zip_safe flag not set; analyzing archive contents...
......
...@@ -28,14 +28,14 @@ We've created a super simple (stupid) setup script. Note that it ...@@ -28,14 +28,14 @@ We've created a super simple (stupid) setup script. Note that it
doesn't import setuptools. Let's try running it to create an egg. doesn't import setuptools. Let's try running it to create an egg.
We'll use the buildout script from our sample buildout: We'll use the buildout script from our sample buildout:
>>> print system(buildout+' setup'), >>> print_(system(buildout+' setup'), end='')
... # doctest: +NORMALIZE_WHITESPACE ... # doctest: +NORMALIZE_WHITESPACE
Error: The setup command requires the path to a setup script or Error: The setup command requires the path to a setup script or
directory containing a setup script, and its arguments. directory containing a setup script, and its arguments.
Oops, we forgot to give the name of the setup script: Oops, we forgot to give the name of the setup script:
>>> print system(buildout+' setup setup.py bdist_egg'), >>> print_(system(buildout+' setup setup.py bdist_egg'))
... # doctest: +ELLIPSIS ... # doctest: +ELLIPSIS
Running setup script 'setup.py'. Running setup script 'setup.py'.
... ...
...@@ -46,6 +46,6 @@ Oops, we forgot to give the name of the setup script: ...@@ -46,6 +46,6 @@ Oops, we forgot to give the name of the setup script:
Note that we can specify a directory name. This is often shorter and Note that we can specify a directory name. This is often shorter and
preferred by the lazy :) preferred by the lazy :)
>>> print system(buildout+' setup . bdist_egg'), # doctest: +ELLIPSIS >>> print_(system(buildout+' setup . bdist_egg')) # doctest: +ELLIPSIS
Running setup script './setup.py'. Running setup script './setup.py'.
... ...
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
"""Various test-support utility functions """Various test-support utility functions
""" """
import BaseHTTPServer import http.server
import errno import errno
import logging import logging
import os import os
...@@ -28,12 +28,14 @@ import sys ...@@ -28,12 +28,14 @@ import sys
import tempfile import tempfile
import threading import threading
import time import time
import urllib2 import urllib.request, urllib.error, urllib.parse
import zc.buildout.buildout import zc.buildout.buildout
import zc.buildout.easy_install import zc.buildout.easy_install
from zc.buildout.rmtree import rmtree from zc.buildout.rmtree import rmtree
print_ = zc.buildout.buildout.print_
fsync = getattr(os, 'fsync', lambda fileno: None) fsync = getattr(os, 'fsync', lambda fileno: None)
is_win32 = sys.platform == 'win32' is_win32 = sys.platform == 'win32'
...@@ -47,7 +49,7 @@ def cat(dir, *names): ...@@ -47,7 +49,7 @@ def cat(dir, *names):
and os.path.exists(path+'-script.py') and os.path.exists(path+'-script.py')
): ):
path = path+'-script.py' path = path+'-script.py'
print open(path).read(), print_(open(path).read(), end='')
def ls(dir, *subs): def ls(dir, *subs):
if subs: if subs:
...@@ -56,12 +58,12 @@ def ls(dir, *subs): ...@@ -56,12 +58,12 @@ def ls(dir, *subs):
names.sort() names.sort()
for name in names: for name in names:
if os.path.isdir(os.path.join(dir, name)): if os.path.isdir(os.path.join(dir, name)):
print 'd ', print_('d ', end=' ')
elif os.path.islink(os.path.join(dir, name)): elif os.path.islink(os.path.join(dir, name)):
print 'l ', print_('l ', end=' ')
else: else:
print '- ', print_('- ', end=' ')
print name print_(name)
def mkdir(*path): def mkdir(*path):
os.mkdir(os.path.join(*path)) os.mkdir(os.path.join(*path))
...@@ -96,15 +98,15 @@ def system(command, input=''): ...@@ -96,15 +98,15 @@ def system(command, input=''):
close_fds=MUST_CLOSE_FDS) close_fds=MUST_CLOSE_FDS)
i, o, e = (p.stdin, p.stdout, p.stderr) i, o, e = (p.stdin, p.stdout, p.stderr)
if input: if input:
i.write(input) i.write(input.encode())
i.close() i.close()
result = o.read() + e.read() result = o.read() + e.read()
o.close() o.close()
e.close() e.close()
return result return result.decode()
def get(url): def get(url):
return urllib2.urlopen(url).read() return urllib.request.urlopen(url).read().decode()
def _runsetup(setup, *args): def _runsetup(setup, *args):
if os.path.isdir(setup): if os.path.isdir(setup):
...@@ -254,6 +256,7 @@ def buildoutSetUp(test): ...@@ -254,6 +256,7 @@ def buildoutSetUp(test):
start_server = start_server, start_server = start_server,
buildout = os.path.join(sample, 'bin', 'buildout'), buildout = os.path.join(sample, 'bin', 'buildout'),
wait_until = wait_until, wait_until = wait_until,
print_ = print_,
)) ))
zc.buildout.easy_install.prefer_final(prefer_final) zc.buildout.easy_install.prefer_final(prefer_final)
...@@ -262,10 +265,10 @@ def buildoutTearDown(test): ...@@ -262,10 +265,10 @@ def buildoutTearDown(test):
for f in test.globs['__tear_downs']: for f in test.globs['__tear_downs']:
f() f()
class Server(BaseHTTPServer.HTTPServer): class Server(http.server.HTTPServer):
def __init__(self, tree, *args): def __init__(self, tree, *args):
BaseHTTPServer.HTTPServer.__init__(self, *args) http.server.HTTPServer.__init__(self, *args)
self.tree = os.path.abspath(tree) self.tree = os.path.abspath(tree)
__run = True __run = True
...@@ -276,14 +279,14 @@ class Server(BaseHTTPServer.HTTPServer): ...@@ -276,14 +279,14 @@ class Server(BaseHTTPServer.HTTPServer):
def handle_error(self, *_): def handle_error(self, *_):
self.__run = False self.__run = False
class Handler(BaseHTTPServer.BaseHTTPRequestHandler): class Handler(http.server.BaseHTTPRequestHandler):
Server.__log = False Server.__log = False
def __init__(self, request, address, server): def __init__(self, request, address, server):
self.__server = server self.__server = server
self.tree = server.tree self.tree = server.tree
BaseHTTPServer.BaseHTTPRequestHandler.__init__( http.server.BaseHTTPRequestHandler.__init__(
self, request, address, server) self, request, address, server)
def do_GET(self): def do_GET(self):
...@@ -308,7 +311,7 @@ class Handler(BaseHTTPServer.BaseHTTPRequestHandler): ...@@ -308,7 +311,7 @@ class Handler(BaseHTTPServer.BaseHTTPRequestHandler):
): ):
self.send_response(404, 'Not Found') self.send_response(404, 'Not Found')
#self.send_response(200) #self.send_response(200)
out = '<html><body>Not Found</body></html>' out = '<html><body>Not Found</body></html>'.encode()
#out = '\n'.join(self.tree, self.path, path) #out = '\n'.join(self.tree, self.path, path)
self.send_header('Content-Length', str(len(out))) self.send_header('Content-Length', str(len(out)))
self.send_header('Content-Type', 'text/html') self.send_header('Content-Type', 'text/html')
...@@ -326,7 +329,7 @@ class Handler(BaseHTTPServer.BaseHTTPRequestHandler): ...@@ -326,7 +329,7 @@ class Handler(BaseHTTPServer.BaseHTTPRequestHandler):
name += '/' name += '/'
out.append('<a href="%s">%s</a><br>\n' % (name, name)) out.append('<a href="%s">%s</a><br>\n' % (name, name))
out.append('</body></html>\n') out.append('</body></html>\n')
out = ''.join(out) out = ''.join(out).encode()
self.send_header('Content-Length', str(len(out))) self.send_header('Content-Length', str(len(out)))
self.send_header('Content-Type', 'text/html') self.send_header('Content-Type', 'text/html')
else: else:
...@@ -346,7 +349,7 @@ class Handler(BaseHTTPServer.BaseHTTPRequestHandler): ...@@ -346,7 +349,7 @@ class Handler(BaseHTTPServer.BaseHTTPRequestHandler):
def log_request(self, code): def log_request(self, code):
if self.__server.__log: if self.__server.__log:
print '%s %s %s' % (self.command, code, self.path) print_('%s %s %s' % (self.command, code, self.path))
def _run(tree, port): def _run(tree, port):
server_address = ('localhost', port) server_address = ('localhost', port)
...@@ -364,7 +367,7 @@ def get_port(): ...@@ -364,7 +367,7 @@ def get_port():
return port return port
finally: finally:
s.close() s.close()
raise RuntimeError, "Can't find port" raise RuntimeError("Can't find port")
def _start_server(tree, name=''): def _start_server(tree, name=''):
port = get_port() port = get_port()
...@@ -379,7 +382,7 @@ def start_server(tree): ...@@ -379,7 +382,7 @@ def start_server(tree):
def stop_server(url, thread=None): def stop_server(url, thread=None):
try: try:
urllib2.urlopen(url+'__stop__') urllib.request.urlopen(url+'__stop__')
except Exception: except Exception:
pass pass
if thread is not None: if thread is not None:
...@@ -395,7 +398,7 @@ def wait(port, up): ...@@ -395,7 +398,7 @@ def wait(port, up):
s.close() s.close()
if up: if up:
break break
except socket.error, e: except socket.error as e:
if e[0] not in (errno.ECONNREFUSED, errno.ECONNRESET): if e[0] not in (errno.ECONNREFUSED, errno.ECONNRESET):
raise raise
s.close() s.close()
...@@ -408,7 +411,7 @@ def wait(port, up): ...@@ -408,7 +411,7 @@ def wait(port, up):
raise SystemError("Couln't stop server") raise SystemError("Couln't stop server")
def install(project, destination): def install(project, destination):
if not isinstance(destination, basestring): if not isinstance(destination, str):
destination = os.path.join(destination.globs['sample_buildout'], destination = os.path.join(destination.globs['sample_buildout'],
'eggs') 'eggs')
...@@ -428,7 +431,7 @@ def install(project, destination): ...@@ -428,7 +431,7 @@ def install(project, destination):
).write(dist.location) ).write(dist.location)
def install_develop(project, destination): def install_develop(project, destination):
if not isinstance(destination, basestring): if not isinstance(destination, str):
destination = os.path.join(destination.globs['sample_buildout'], destination = os.path.join(destination.globs['sample_buildout'],
'develop-eggs') 'develop-eggs')
...@@ -462,3 +465,7 @@ normalize_egg_py = ( ...@@ -462,3 +465,7 @@ normalize_egg_py = (
re.compile('-py\d[.]\d(-\S+)?.egg'), re.compile('-py\d[.]\d(-\S+)?.egg'),
'-pyN.N.egg', '-pyN.N.egg',
) )
normalize_exception_type_for_python_2_and_3 = (
re.compile(r'^(\w+\.)*([A-Z][A-Za-z0-9]+Error: )'),
'\2')
from zc.buildout.buildout import print_
class Debug: class Debug:
...@@ -7,10 +8,10 @@ class Debug: ...@@ -7,10 +8,10 @@ class Debug:
self.options = options self.options = options
def install(self): def install(self):
items = self.options.items() items = list(self.options.items())
items.sort() items.sort()
for option, value in items: for option, value in items:
print " %s=%r" % (option, value) print_(" %s=%r" % (option, value))
return () return ()
update = install update = install
...@@ -11,7 +11,9 @@ ...@@ -11,7 +11,9 @@
# FOR A PARTICULAR PURPOSE. # FOR A PARTICULAR PURPOSE.
# #
############################################################################## ##############################################################################
from zc.buildout.buildout import print_
from zope.testing import renormalizing from zope.testing import renormalizing
import doctest import doctest
import os import os
import pkg_resources import pkg_resources
...@@ -47,7 +49,7 @@ We should be able to deal with setup scripts that aren't setuptools based. ...@@ -47,7 +49,7 @@ We should be able to deal with setup scripts that aren't setuptools based.
... parts = ... parts =
... ''') ... ''')
>>> print system(join('bin', 'buildout')), >>> print_(system(join('bin', 'buildout')), end=' ')
Develop: '/sample-buildout/foo' Develop: '/sample-buildout/foo'
>>> ls('develop-eggs') >>> ls('develop-eggs')
...@@ -74,7 +76,8 @@ We should be able to deal with setup scripts that aren't setuptools based. ...@@ -74,7 +76,8 @@ We should be able to deal with setup scripts that aren't setuptools based.
... parts = ... parts =
... ''') ... ''')
>>> print system(join('bin', 'buildout')+' -vv'), # doctest: +ELLIPSIS >>> print_(system(join('bin', 'buildout')+' -vv'), end=' ')
... # doctest: +ELLIPSIS
Installing... Installing...
Develop: '/sample-buildout/foo' Develop: '/sample-buildout/foo'
... ...
...@@ -85,7 +88,8 @@ We should be able to deal with setup scripts that aren't setuptools based. ...@@ -85,7 +88,8 @@ We should be able to deal with setup scripts that aren't setuptools based.
- foo.egg-link - foo.egg-link
- zc.recipe.egg.egg-link - zc.recipe.egg.egg-link
>>> print system(join('bin', 'buildout')+' -vvv'), # doctest: +ELLIPSIS >>> print_(system(join('bin', 'buildout')+' -vvv'), end=' ')
... # doctest: +ELLIPSIS
Installing... Installing...
Develop: '/sample-buildout/foo' Develop: '/sample-buildout/foo'
in: '/sample-buildout/foo' in: '/sample-buildout/foo'
...@@ -126,7 +130,8 @@ It is an error to create a variable-reference cycle: ...@@ -126,7 +130,8 @@ It is an error to create a variable-reference cycle:
... z = ${buildout:x} ... z = ${buildout:x}
... ''') ... ''')
>>> print system(os.path.join(sample_buildout, 'bin', 'buildout')), >>> print_(system(os.path.join(sample_buildout, 'bin', 'buildout')),
... end=' ')
... # doctest: +NORMALIZE_WHITESPACE +ELLIPSIS ... # doctest: +NORMALIZE_WHITESPACE +ELLIPSIS
While: While:
Initializing. Initializing.
...@@ -148,7 +153,8 @@ It is an error to use funny characters in variable refereces: ...@@ -148,7 +153,8 @@ It is an error to use funny characters in variable refereces:
... x = ${bui$ldout:y} ... x = ${bui$ldout:y}
... ''') ... ''')
>>> print system(os.path.join(sample_buildout, 'bin', 'buildout')), >>> print_(system(os.path.join(sample_buildout, 'bin', 'buildout')),
... end=' ')
While: While:
Initializing. Initializing.
Getting section buildout. Getting section buildout.
...@@ -165,7 +171,8 @@ It is an error to use funny characters in variable refereces: ...@@ -165,7 +171,8 @@ It is an error to use funny characters in variable refereces:
... x = ${buildout:y{z} ... x = ${buildout:y{z}
... ''') ... ''')
>>> print system(os.path.join(sample_buildout, 'bin', 'buildout')), >>> print_(system(os.path.join(sample_buildout, 'bin', 'buildout')),
... end=' ')
While: While:
Initializing. Initializing.
Getting section buildout. Getting section buildout.
...@@ -184,7 +191,8 @@ and too have too many or too few colons: ...@@ -184,7 +191,8 @@ and too have too many or too few colons:
... x = ${parts} ... x = ${parts}
... ''') ... ''')
>>> print system(os.path.join(sample_buildout, 'bin', 'buildout')), >>> print_(system(os.path.join(sample_buildout, 'bin', 'buildout')),
... end=' ')
While: While:
Initializing. Initializing.
Getting section buildout. Getting section buildout.
...@@ -201,7 +209,8 @@ and too have too many or too few colons: ...@@ -201,7 +209,8 @@ and too have too many or too few colons:
... x = ${buildout:y:z} ... x = ${buildout:y:z}
... ''') ... ''')
>>> print system(os.path.join(sample_buildout, 'bin', 'buildout')), >>> print_(system(os.path.join(sample_buildout, 'bin', 'buildout')),
... end=' ')
While: While:
Initializing. Initializing.
Getting section buildout. Getting section buildout.
...@@ -218,7 +227,8 @@ Al parts have to have a section: ...@@ -218,7 +227,8 @@ Al parts have to have a section:
... parts = x ... parts = x
... ''') ... ''')
>>> print system(os.path.join(sample_buildout, 'bin', 'buildout')), >>> print_(system(os.path.join(sample_buildout, 'bin', 'buildout')),
... end=' ')
While: While:
Installing. Installing.
Getting section x. Getting section x.
...@@ -236,7 +246,8 @@ and all parts have to have a specified recipe: ...@@ -236,7 +246,8 @@ and all parts have to have a specified recipe:
... foo = 1 ... foo = 1
... ''') ... ''')
>>> print system(os.path.join(sample_buildout, 'bin', 'buildout')), >>> print_(system(os.path.join(sample_buildout, 'bin', 'buildout')),
... end=' ')
While: While:
Installing. Installing.
Error: Missing option: x:recipe Error: Missing option: x:recipe
...@@ -285,7 +296,7 @@ Now, let's create a buildout that requires y and z: ...@@ -285,7 +296,7 @@ Now, let's create a buildout that requires y and z:
... samplez ... samplez
... ''' % globals()) ... ''' % globals())
>>> print system(buildout), >>> print_(system(buildout), end=' ')
Develop: '/sample-buildout/sampley' Develop: '/sample-buildout/sampley'
Develop: '/sample-buildout/samplez' Develop: '/sample-buildout/samplez'
Installing eggs. Installing eggs.
...@@ -318,7 +329,7 @@ if we hadn't required sampley ourselves: ...@@ -318,7 +329,7 @@ if we hadn't required sampley ourselves:
If we use the verbose switch, we can see where requirements are coming from: If we use the verbose switch, we can see where requirements are coming from:
>>> print system(buildout+' -v'), # doctest: +ELLIPSIS >>> print_(system(buildout+' -v'), end=' ') # doctest: +ELLIPSIS
Installing 'zc.buildout', 'distribute'. Installing 'zc.buildout', 'distribute'.
We have a develop egg: zc.buildout 1.0.0 We have a develop egg: zc.buildout 1.0.0
We have the best distribution that satisfies 'distribute'. We have the best distribution that satisfies 'distribute'.
...@@ -369,7 +380,7 @@ buildout will tell us who's asking for something that we can't find. ...@@ -369,7 +380,7 @@ buildout will tell us who's asking for something that we can't find.
... eggs = samplea ... eggs = samplea
... ''') ... ''')
>>> print system(buildout), >>> print_(system(buildout), end=' ')
Develop: '/sample-buildout/sampley' Develop: '/sample-buildout/sampley'
Develop: '/sample-buildout/samplea' Develop: '/sample-buildout/samplea'
Develop: '/sample-buildout/sampleb' Develop: '/sample-buildout/sampleb'
...@@ -446,14 +457,14 @@ the comparison with the saved value works correctly. ...@@ -446,14 +457,14 @@ the comparison with the saved value works correctly.
>>> os.chdir(sample_buildout) >>> os.chdir(sample_buildout)
>>> buildout = os.path.join(sample_buildout, 'bin', 'buildout') >>> buildout = os.path.join(sample_buildout, 'bin', 'buildout')
>>> print system(buildout), >>> print_(system(buildout), end=' ')
Develop: '/sample-buildout/recipes' Develop: '/sample-buildout/recipes'
Installing debug. Installing debug.
If we run the buildout again, we shoudn't get a message about If we run the buildout again, we shoudn't get a message about
uninstalling anything because the configuration hasn't changed. uninstalling anything because the configuration hasn't changed.
>>> print system(buildout), >>> print_(system(buildout), end=' ')
Develop: '/sample-buildout/recipes' Develop: '/sample-buildout/recipes'
Updating debug. Updating debug.
""" """
...@@ -507,7 +518,8 @@ def create_sections_on_command_line(): ...@@ -507,7 +518,8 @@ def create_sections_on_command_line():
... x = ${foo:bar} ... x = ${foo:bar}
... ''') ... ''')
>>> print system(buildout + ' foo:bar=1 -vv'), # doctest: +ELLIPSIS >>> print_(system(buildout + ' foo:bar=1 -vv'), end=' ')
... # doctest: +ELLIPSIS
Installing 'zc.buildout', 'distribute'. Installing 'zc.buildout', 'distribute'.
... ...
[foo] [foo]
...@@ -518,7 +530,7 @@ def create_sections_on_command_line(): ...@@ -518,7 +530,7 @@ def create_sections_on_command_line():
def test_help(): def test_help():
""" """
>>> print system(os.path.join(sample_buildout, 'bin', 'buildout')+' -h'), >>> print_(system(os.path.join(sample_buildout, 'bin', 'buildout')+' -h'))
... # doctest: +ELLIPSIS ... # doctest: +ELLIPSIS
Usage: buildout [options] [assignments] [command [command arguments]] Usage: buildout [options] [assignments] [command [command arguments]]
<BLANKLINE> <BLANKLINE>
...@@ -527,8 +539,8 @@ def test_help(): ...@@ -527,8 +539,8 @@ def test_help():
-h, --help -h, --help
... ...
>>> print system(os.path.join(sample_buildout, 'bin', 'buildout') >>> print_(system(os.path.join(sample_buildout, 'bin', 'buildout')
... +' --help'), ... +' --help'))
... # doctest: +ELLIPSIS ... # doctest: +ELLIPSIS
Usage: buildout [options] [assignments] [command [command arguments]] Usage: buildout [options] [assignments] [command [command arguments]]
<BLANKLINE> <BLANKLINE>
...@@ -554,8 +566,8 @@ bootstrapping. ...@@ -554,8 +566,8 @@ bootstrapping.
... ''') ... ''')
>>> os.chdir(d) >>> os.chdir(d)
>>> print system(os.path.join(sample_buildout, 'bin', 'buildout') >>> print_(system(os.path.join(sample_buildout, 'bin', 'buildout')
... + ' bootstrap'), ... + ' bootstrap'), end=' ')
Creating directory '/sample-bootstrap/bin'. Creating directory '/sample-bootstrap/bin'.
Creating directory '/sample-bootstrap/parts'. Creating directory '/sample-bootstrap/parts'.
Creating directory '/sample-bootstrap/eggs'. Creating directory '/sample-bootstrap/eggs'.
...@@ -581,15 +593,15 @@ def bug_92891_bootstrap_crashes_with_egg_recipe_in_buildout_section(): ...@@ -581,15 +593,15 @@ def bug_92891_bootstrap_crashes_with_egg_recipe_in_buildout_section():
... ''') ... ''')
>>> os.chdir(d) >>> os.chdir(d)
>>> print system(os.path.join(sample_buildout, 'bin', 'buildout') >>> print_(system(os.path.join(sample_buildout, 'bin', 'buildout')
... + ' bootstrap'), ... + ' bootstrap'), end=' ')
Creating directory '/sample-bootstrap/bin'. Creating directory '/sample-bootstrap/bin'.
Creating directory '/sample-bootstrap/parts'. Creating directory '/sample-bootstrap/parts'.
Creating directory '/sample-bootstrap/eggs'. Creating directory '/sample-bootstrap/eggs'.
Creating directory '/sample-bootstrap/develop-eggs'. Creating directory '/sample-bootstrap/develop-eggs'.
Generated script '/sample-bootstrap/bin/buildout'. Generated script '/sample-bootstrap/bin/buildout'.
>>> print system(os.path.join('bin', 'buildout')), >>> print_(system(os.path.join('bin', 'buildout')), end=' ')
Unused options for buildout: 'scripts' 'eggs'. Unused options for buildout: 'scripts' 'eggs'.
""" """
...@@ -613,7 +625,7 @@ Create a develop egg: ...@@ -613,7 +625,7 @@ Create a develop egg:
... parts = ... parts =
... """) ... """)
>>> print system(join('bin', 'buildout')), >>> print_(system(join('bin', 'buildout')), end=' ')
Develop: '/sample-buildout/foo' Develop: '/sample-buildout/foo'
>>> ls('develop-eggs') >>> ls('develop-eggs')
...@@ -635,7 +647,7 @@ Create another: ...@@ -635,7 +647,7 @@ Create another:
... parts = ... parts =
... """) ... """)
>>> print system(join('bin', 'buildout')), >>> print_(system(join('bin', 'buildout')), end=' ')
Develop: '/sample-buildout/foo' Develop: '/sample-buildout/foo'
Develop: '/sample-buildout/bar' Develop: '/sample-buildout/bar'
...@@ -652,7 +664,7 @@ Remove one: ...@@ -652,7 +664,7 @@ Remove one:
... develop = bar ... develop = bar
... parts = ... parts =
... """) ... """)
>>> print system(join('bin', 'buildout')), >>> print_(system(join('bin', 'buildout')), end=' ')
Develop: '/sample-buildout/bar' Develop: '/sample-buildout/bar'
It is gone It is gone
...@@ -668,7 +680,7 @@ Remove the other: ...@@ -668,7 +680,7 @@ Remove the other:
... [buildout] ... [buildout]
... parts = ... parts =
... """) ... """)
>>> print system(join('bin', 'buildout')), >>> print_(system(join('bin', 'buildout')), end=' ')
All gone All gone
...@@ -713,7 +725,7 @@ a devlop egg, we will also generate a warning. ...@@ -713,7 +725,7 @@ a devlop egg, we will also generate a warning.
... parts = ... parts =
... """) ... """)
>>> print system(join('bin', 'buildout')), >>> print_(system(join('bin', 'buildout')), end=' ')
Develop: '/sample-buildout/foo' Develop: '/sample-buildout/foo'
Now, if we generate a working set using the egg link, we will get a warning Now, if we generate a working set using the egg link, we will get a warning
...@@ -732,7 +744,7 @@ and we will get distribute included in the working set. ...@@ -732,7 +744,7 @@ and we will get distribute included in the working set.
... ])] ... ])]
['foox', 'distribute'] ['foox', 'distribute']
>>> print handler >>> print_(handler)
zc.buildout.easy_install WARNING zc.buildout.easy_install WARNING
Develop distribution: foox 0.0.0 Develop distribution: foox 0.0.0
uses namespace packages but the distribution does not require distribute. uses namespace packages but the distribution does not require distribute.
...@@ -764,7 +776,7 @@ We do not get a warning, but we do get distribute included in the working set: ...@@ -764,7 +776,7 @@ We do not get a warning, but we do get distribute included in the working set:
... ])] ... ])]
['foox', 'distribute'] ['foox', 'distribute']
>>> print handler, >>> print_(handler, end=' ')
We get the same behavior if the it is a depedency that uses a We get the same behavior if the it is a depedency that uses a
namespace package. namespace package.
...@@ -785,7 +797,7 @@ namespace package. ...@@ -785,7 +797,7 @@ namespace package.
... parts = ... parts =
... """) ... """)
>>> print system(join('bin', 'buildout')), >>> print_(system(join('bin', 'buildout')), end=' ')
Develop: '/sample-buildout/foo' Develop: '/sample-buildout/foo'
Develop: '/sample-buildout/bar' Develop: '/sample-buildout/bar'
...@@ -797,7 +809,7 @@ namespace package. ...@@ -797,7 +809,7 @@ namespace package.
... ])] ... ])]
['bar', 'foox', 'distribute'] ['bar', 'foox', 'distribute']
>>> print handler, >>> print_(handler, end=' ')
zc.buildout.easy_install WARNING zc.buildout.easy_install WARNING
Develop distribution: foox 0.0.0 Develop distribution: foox 0.0.0
uses namespace packages but the distribution does not require distribute. uses namespace packages but the distribution does not require distribute.
...@@ -854,7 +866,7 @@ existing setup.cfg: ...@@ -854,7 +866,7 @@ existing setup.cfg:
""" """
def uninstall_recipes_used_for_removal(): def uninstall_recipes_used_for_removal():
""" r"""
Uninstall recipes need to be called when a part is removed too: Uninstall recipes need to be called when a part is removed too:
>>> mkdir("recipes") >>> mkdir("recipes")
...@@ -869,13 +881,15 @@ Uninstall recipes need to be called when a part is removed too: ...@@ -869,13 +881,15 @@ Uninstall recipes need to be called when a part is removed too:
... ''') ... ''')
>>> write("recipes", "demo.py", >>> write("recipes", "demo.py",
... ''' ... r'''
... import sys
... class Install: ... class Install:
... def __init__(*args): pass ... def __init__(*args): pass
... def install(self): ... def install(self):
... print 'installing' ... sys.stdout.write('installing\n')
... return () ... return ()
... def uninstall(name, options): print 'uninstalling' ... def uninstall(name, options):
... sys.stdout.write('uninstalling\n')
... ''') ... ''')
>>> write('buildout.cfg', ''' >>> write('buildout.cfg', '''
...@@ -886,7 +900,7 @@ Uninstall recipes need to be called when a part is removed too: ...@@ -886,7 +900,7 @@ Uninstall recipes need to be called when a part is removed too:
... recipe = recipes:demo ... recipe = recipes:demo
... ''') ... ''')
>>> print system(join('bin', 'buildout')), >>> print_(system(join('bin', 'buildout')), end=' ')
Develop: '/sample-buildout/recipes' Develop: '/sample-buildout/recipes'
Installing demo. Installing demo.
installing installing
...@@ -901,7 +915,7 @@ Uninstall recipes need to be called when a part is removed too: ...@@ -901,7 +915,7 @@ Uninstall recipes need to be called when a part is removed too:
... x = 1 ... x = 1
... ''') ... ''')
>>> print system(join('bin', 'buildout')), >>> print_(system(join('bin', 'buildout')), end=' ')
Develop: '/sample-buildout/recipes' Develop: '/sample-buildout/recipes'
Uninstalling demo. Uninstalling demo.
Running uninstall recipe. Running uninstall recipe.
...@@ -916,7 +930,7 @@ Uninstall recipes need to be called when a part is removed too: ...@@ -916,7 +930,7 @@ Uninstall recipes need to be called when a part is removed too:
... parts = ... parts =
... ''') ... ''')
>>> print system(join('bin', 'buildout')), >>> print_(system(join('bin', 'buildout')), end=' ')
Develop: '/sample-buildout/recipes' Develop: '/sample-buildout/recipes'
Uninstalling demo. Uninstalling demo.
Running uninstall recipe. Running uninstall recipe.
...@@ -931,7 +945,7 @@ def extensions_installed_as_eggs_work_in_offline_mode(): ...@@ -931,7 +945,7 @@ def extensions_installed_as_eggs_work_in_offline_mode():
>>> write('demo', 'demo.py', >>> write('demo', 'demo.py',
... """ ... """
... def ext(buildout): ... def ext(buildout):
... print 'ext', list(buildout) ... print_('ext', list(buildout))
... """) ... """)
>>> write('demo', 'setup.py', >>> write('demo', 'setup.py',
...@@ -956,7 +970,7 @@ def extensions_installed_as_eggs_work_in_offline_mode(): ...@@ -956,7 +970,7 @@ def extensions_installed_as_eggs_work_in_offline_mode():
... offline = true ... offline = true
... """) ... """)
>>> print system(join(sample_buildout, 'bin', 'buildout')), >>> print_(system(join(sample_buildout, 'bin', 'buildout')), end=' ')
ext ['buildout'] ext ['buildout']
...@@ -994,20 +1008,20 @@ changes in .svn or CVS directories. ...@@ -994,20 +1008,20 @@ changes in .svn or CVS directories.
... ''') ... ''')
>>> print system(join(sample_buildout, 'bin', 'buildout')), >>> print_(system(join(sample_buildout, 'bin', 'buildout')), end=' ')
Develop: '/sample-buildout/recipe' Develop: '/sample-buildout/recipe'
Installing foo. Installing foo.
>>> mkdir('recipe', '.svn') >>> mkdir('recipe', '.svn')
>>> mkdir('recipe', 'CVS') >>> mkdir('recipe', 'CVS')
>>> print system(join(sample_buildout, 'bin', 'buildout')), >>> print_(system(join(sample_buildout, 'bin', 'buildout')), end=' ')
Develop: '/sample-buildout/recipe' Develop: '/sample-buildout/recipe'
Updating foo. Updating foo.
>>> write('recipe', '.svn', 'x', '1') >>> write('recipe', '.svn', 'x', '1')
>>> write('recipe', 'CVS', 'x', '1') >>> write('recipe', 'CVS', 'x', '1')
>>> print system(join(sample_buildout, 'bin', 'buildout')), >>> print_(system(join(sample_buildout, 'bin', 'buildout')), end=' ')
Develop: '/sample-buildout/recipe' Develop: '/sample-buildout/recipe'
Updating foo. Updating foo.
...@@ -1046,7 +1060,7 @@ because of the missing target file. ...@@ -1046,7 +1060,7 @@ because of the missing target file.
... ''') ... ''')
>>> print system(join(sample_buildout, 'bin', 'buildout')), >>> print_(system(join(sample_buildout, 'bin', 'buildout')), end=' ')
Develop: '/sample-buildout/recipe' Develop: '/sample-buildout/recipe'
Installing foo. Installing foo.
...@@ -1063,7 +1077,7 @@ because of the missing target file. ...@@ -1063,7 +1077,7 @@ because of the missing target file.
>>> remove('recipe', 'some-file') >>> remove('recipe', 'some-file')
>>> print system(join(sample_buildout, 'bin', 'buildout')), >>> print_(system(join(sample_buildout, 'bin', 'buildout')), end=' ')
Develop: '/sample-buildout/recipe' Develop: '/sample-buildout/recipe'
Updating foo. Updating foo.
...@@ -1071,7 +1085,7 @@ because of the missing target file. ...@@ -1071,7 +1085,7 @@ because of the missing target file.
def o_option_sets_offline(): def o_option_sets_offline():
""" """
>>> print system(join(sample_buildout, 'bin', 'buildout')+' -vvo'), >>> print_(system(join(sample_buildout, 'bin', 'buildout')+' -vvo'), end=' ')
... # doctest: +ELLIPSIS ... # doctest: +ELLIPSIS
<BLANKLINE> <BLANKLINE>
... ...
...@@ -1080,7 +1094,7 @@ def o_option_sets_offline(): ...@@ -1080,7 +1094,7 @@ def o_option_sets_offline():
""" """
def recipe_upgrade(): def recipe_upgrade():
""" r"""
The buildout will upgrade recipes in newest (and non-offline) mode. The buildout will upgrade recipes in newest (and non-offline) mode.
...@@ -1088,11 +1102,12 @@ Let's create a recipe egg ...@@ -1088,11 +1102,12 @@ Let's create a recipe egg
>>> mkdir('recipe') >>> mkdir('recipe')
>>> write('recipe', 'recipe.py', >>> write('recipe', 'recipe.py',
... ''' ... r'''
... import sys
... class Recipe: ... class Recipe:
... def __init__(*a): pass ... def __init__(*a): pass
... def install(self): ... def install(self):
... print 'recipe v1' ... sys.stdout.write('recipe v1\n')
... return () ... return ()
... update = install ... update = install
... ''') ... ''')
...@@ -1107,7 +1122,7 @@ Let's create a recipe egg ...@@ -1107,7 +1122,7 @@ Let's create a recipe egg
>>> write('recipe', 'README', '') >>> write('recipe', 'README', '')
>>> print system(buildout+' setup recipe bdist_egg'), # doctest: +ELLIPSIS >>> print_(system(buildout+' setup recipe bdist_egg')) # doctest: +ELLIPSIS
Running setup script 'recipe/setup.py'. Running setup script 'recipe/setup.py'.
... ...
...@@ -1125,7 +1140,7 @@ And update our buildout to use it. ...@@ -1125,7 +1140,7 @@ And update our buildout to use it.
... recipe = recipe ... recipe = recipe
... ''' % join('recipe', 'dist')) ... ''' % join('recipe', 'dist'))
>>> print system(buildout), >>> print_(system(buildout), end=' ')
Getting distribution for 'recipe'. Getting distribution for 'recipe'.
Got recipe 1. Got recipe 1.
Installing foo. Installing foo.
...@@ -1134,11 +1149,12 @@ And update our buildout to use it. ...@@ -1134,11 +1149,12 @@ And update our buildout to use it.
Now, if we update the recipe egg: Now, if we update the recipe egg:
>>> write('recipe', 'recipe.py', >>> write('recipe', 'recipe.py',
... ''' ... r'''
... import sys
... class Recipe: ... class Recipe:
... def __init__(*a): pass ... def __init__(*a): pass
... def install(self): ... def install(self):
... print 'recipe v2' ... sys.stdout.write('recipe v2\n')
... return () ... return ()
... update = install ... update = install
... ''') ... ''')
...@@ -1152,25 +1168,25 @@ Now, if we update the recipe egg: ...@@ -1152,25 +1168,25 @@ Now, if we update the recipe egg:
... ''') ... ''')
>>> print system(buildout+' setup recipe bdist_egg'), # doctest: +ELLIPSIS >>> print_(system(buildout+' setup recipe bdist_egg')) # doctest: +ELLIPSIS
Running setup script 'recipe/setup.py'. Running setup script 'recipe/setup.py'.
... ...
We won't get the update if we specify -N: We won't get the update if we specify -N:
>>> print system(buildout+' -N'), >>> print_(system(buildout+' -N'), end=' ')
Updating foo. Updating foo.
recipe v1 recipe v1
or if we use -o: or if we use -o:
>>> print system(buildout+' -o'), >>> print_(system(buildout+' -o'), end=' ')
Updating foo. Updating foo.
recipe v1 recipe v1
But we will if we use neither of these: But we will if we use neither of these:
>>> print system(buildout), >>> print_(system(buildout), end=' ')
Getting distribution for 'recipe'. Getting distribution for 'recipe'.
Got recipe 2. Got recipe 2.
Uninstalling foo. Uninstalling foo.
...@@ -1189,7 +1205,7 @@ We can also select a particular recipe version: ...@@ -1189,7 +1205,7 @@ We can also select a particular recipe version:
... recipe = recipe ==1 ... recipe = recipe ==1
... ''' % join('recipe', 'dist')) ... ''' % join('recipe', 'dist'))
>>> print system(buildout), >>> print_(system(buildout), end=' ')
Uninstalling foo. Uninstalling foo.
Installing foo. Installing foo.
recipe v1 recipe v1
...@@ -1238,11 +1254,11 @@ uninstall ...@@ -1238,11 +1254,11 @@ uninstall
... recipe = recipe ... recipe = recipe
... ''') ... ''')
>>> print system(buildout), >>> print_(system(buildout), end=' ')
Develop: '/sample-buildout/recipe' Develop: '/sample-buildout/recipe'
Installing foo. Installing foo.
>>> print system(buildout), >>> print_(system(buildout), end=' ')
Develop: '/sample-buildout/recipe' Develop: '/sample-buildout/recipe'
Updating foo. Updating foo.
...@@ -1274,7 +1290,7 @@ def log_when_there_are_not_local_distros(): ...@@ -1274,7 +1290,7 @@ def log_when_there_are_not_local_distros():
... ['demo==0.2'], dest, ... ['demo==0.2'], dest,
... links=[link_server], index=link_server+'index/') ... links=[link_server], index=link_server+'index/')
>>> print handler # doctest: +ELLIPSIS >>> print_(handler) # doctest: +ELLIPSIS
zc.buildout.easy_install DEBUG zc.buildout.easy_install DEBUG
Installing 'demo==0.2'. Installing 'demo==0.2'.
zc.buildout.easy_install DEBUG zc.buildout.easy_install DEBUG
...@@ -1320,7 +1336,7 @@ def internal_errors(): ...@@ -1320,7 +1336,7 @@ def internal_errors():
... recipe = recipes:mkdir ... recipe = recipes:mkdir
... ''') ... ''')
>>> print system(buildout), # doctest: +ELLIPSIS >>> print_(system(buildout), end=' ') # doctest: +ELLIPSIS
Develop: '/sample-buildout/recipes' Develop: '/sample-buildout/recipes'
While: While:
Installing. Installing.
...@@ -1372,7 +1388,7 @@ def whine_about_unused_options(): ...@@ -1372,7 +1388,7 @@ def whine_about_unused_options():
... z = 1 ... z = 1
... """) ... """)
>>> print system(buildout), >>> print_(system(buildout), end=' ')
Develop: '/sample-buildout/.' Develop: '/sample-buildout/.'
Unused options for buildout: 'a'. Unused options for buildout: 'a'.
Installing foo. Installing foo.
...@@ -1440,19 +1456,19 @@ Now let's look at 3 cases: ...@@ -1440,19 +1456,19 @@ Now let's look at 3 cases:
... recipe = recipes:clean ... recipe = recipes:clean
... ''') ... ''')
>>> print system(buildout), >>> print_(system(buildout), end=' ')
Develop: '/sample-buildout/recipes' Develop: '/sample-buildout/recipes'
Installing p1. Installing p1.
Installing p2. Installing p2.
Installing p3. Installing p3.
>>> print system(buildout), >>> print_(system(buildout), end=' ')
Develop: '/sample-buildout/recipes' Develop: '/sample-buildout/recipes'
Updating p1. Updating p1.
Updating p2. Updating p2.
Installing p3. Installing p3.
>>> print system(buildout+' buildout:parts='), >>> print_(system(buildout+' buildout:parts='), end=' ')
Develop: '/sample-buildout/recipes' Develop: '/sample-buildout/recipes'
Uninstalling p2. Uninstalling p2.
Uninstalling p1. Uninstalling p1.
...@@ -1478,20 +1494,20 @@ Now let's look at 3 cases: ...@@ -1478,20 +1494,20 @@ Now let's look at 3 cases:
... recipe = recipes:clean ... recipe = recipes:clean
... ''') ... ''')
>>> print system(buildout), >>> print_(system(buildout), end=' ')
Develop: '/sample-buildout/recipes' Develop: '/sample-buildout/recipes'
Installing p1. Installing p1.
Installing p2. Installing p2.
Installing p3. Installing p3.
Installing p4. Installing p4.
>>> print system(buildout), >>> print_(system(buildout), end=' ')
Develop: '/sample-buildout/recipes' Develop: '/sample-buildout/recipes'
Updating p1. Updating p1.
Updating p2. Updating p2.
Updating p3. Updating p3.
>>> print system(buildout+' buildout:parts='), >>> print_(system(buildout+' buildout:parts='), end=' ')
Develop: '/sample-buildout/recipes' Develop: '/sample-buildout/recipes'
Uninstalling p2. Uninstalling p2.
Uninstalling p1. Uninstalling p1.
...@@ -1519,7 +1535,7 @@ Now let's look at 3 cases: ...@@ -1519,7 +1535,7 @@ Now let's look at 3 cases:
... recipe = recipes:clean ... recipe = recipes:clean
... ''') ... ''')
>>> print system(buildout), >>> print_(system(buildout), end=' ')
Develop: '/sample-buildout/recipes' Develop: '/sample-buildout/recipes'
Installing p1. Installing p1.
Installing p2. Installing p2.
...@@ -1546,7 +1562,7 @@ Now let's look at 3 cases: ...@@ -1546,7 +1562,7 @@ Now let's look at 3 cases:
... x = 1 ... x = 1
... ''') ... ''')
>>> print system(buildout), >>> print_(system(buildout), end=' ')
Develop: '/sample-buildout/recipes' Develop: '/sample-buildout/recipes'
Uninstalling p4. Uninstalling p4.
Updating p1. Updating p1.
...@@ -1570,7 +1586,7 @@ Now let's look at 3 cases: ...@@ -1570,7 +1586,7 @@ Now let's look at 3 cases:
... recipe = recipes:clean ... recipe = recipes:clean
... ''') ... ''')
>>> print system(buildout), >>> print_(system(buildout), end=' ')
Develop: '/sample-buildout/recipes' Develop: '/sample-buildout/recipes'
Uninstalling p1. Uninstalling p1.
Installing p1. Installing p1.
...@@ -1581,7 +1597,7 @@ Now let's look at 3 cases: ...@@ -1581,7 +1597,7 @@ Now let's look at 3 cases:
""" """
def install_source_dist_with_bad_py(): def install_source_dist_with_bad_py():
""" r"""
>>> mkdir('badegg') >>> mkdir('badegg')
>>> mkdir('badegg', 'badegg') >>> mkdir('badegg', 'badegg')
...@@ -1603,7 +1619,7 @@ def install_source_dist_with_bad_py(): ...@@ -1603,7 +1619,7 @@ def install_source_dist_with_bad_py():
... zip_safe=False) ... zip_safe=False)
... ''') ... ''')
>>> print system(buildout+' setup badegg sdist'), # doctest: +ELLIPSIS >>> print_(system(buildout+' setup badegg sdist'), end=' ') # doctest: +ELLIPSIS
Running setup script 'badegg/setup.py'. Running setup script 'badegg/setup.py'.
... ...
...@@ -1625,7 +1641,7 @@ def install_source_dist_with_bad_py(): ...@@ -1625,7 +1641,7 @@ def install_source_dist_with_bad_py():
... scripts = buildout=bo ... scripts = buildout=bo
... ''' % globals()) ... ''' % globals())
>>> print system(buildout);print 'X' # doctest: +ELLIPSIS >>> print_(system(buildout));print_('X') # doctest: +ELLIPSIS
Installing eggs. Installing eggs.
Getting distribution for 'badegg'. Getting distribution for 'badegg'.
Got badegg 1. Got badegg 1.
...@@ -1687,7 +1703,7 @@ def bug_105081_Specific_egg_versions_are_ignored_when_newer_eggs_are_around(): ...@@ -1687,7 +1703,7 @@ def bug_105081_Specific_egg_versions_are_ignored_when_newer_eggs_are_around():
... eggs = demo ... eggs = demo
... ''' % globals()) ... ''' % globals())
>>> print system(buildout), >>> print_(system(buildout), end=' ')
Installing x. Installing x.
Getting distribution for 'demo'. Getting distribution for 'demo'.
Got demo 0.4c1. Got demo 0.4c1.
...@@ -1695,7 +1711,7 @@ def bug_105081_Specific_egg_versions_are_ignored_when_newer_eggs_are_around(): ...@@ -1695,7 +1711,7 @@ def bug_105081_Specific_egg_versions_are_ignored_when_newer_eggs_are_around():
Got demoneeded 1.2c1. Got demoneeded 1.2c1.
Generated script '/sample-buildout/bin/demo'. Generated script '/sample-buildout/bin/demo'.
>>> print system(join('bin', 'demo')), >>> print_(system(join('bin', 'demo')), end=' ')
4 2 4 2
>>> write('buildout.cfg', >>> write('buildout.cfg',
...@@ -1709,14 +1725,14 @@ def bug_105081_Specific_egg_versions_are_ignored_when_newer_eggs_are_around(): ...@@ -1709,14 +1725,14 @@ def bug_105081_Specific_egg_versions_are_ignored_when_newer_eggs_are_around():
... eggs = demo ==0.1 ... eggs = demo ==0.1
... ''' % globals()) ... ''' % globals())
>>> print system(buildout), >>> print_(system(buildout), end=' ')
Uninstalling x. Uninstalling x.
Installing x. Installing x.
Getting distribution for 'demo==0.1'. Getting distribution for 'demo==0.1'.
Got demo 0.1. Got demo 0.1.
Generated script '/sample-buildout/bin/demo'. Generated script '/sample-buildout/bin/demo'.
>>> print system(join('bin', 'demo')), >>> print_(system(join('bin', 'demo')), end=' ')
1 2 1 2
""" """
...@@ -1728,8 +1744,8 @@ if sys.version_info > (2, 4): ...@@ -1728,8 +1744,8 @@ if sys.version_info > (2, 4):
... p = subprocess.Popen(s, stdin=subprocess.PIPE, ... p = subprocess.Popen(s, stdin=subprocess.PIPE,
... stdout=subprocess.PIPE, stderr=subprocess.STDOUT) ... stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
... p.stdin.close() ... p.stdin.close()
... print p.stdout.read() ... print_(p.stdout.read().decode())
... print 'Exit:', bool(p.wait()) ... print_('Exit:', bool(p.wait()))
>>> call(buildout) >>> call(buildout)
<BLANKLINE> <BLANKLINE>
...@@ -1791,20 +1807,20 @@ if sys.version_info > (2, 4): ...@@ -1791,20 +1807,20 @@ if sys.version_info > (2, 4):
""" """
def bug_59270_recipes_always_start_in_buildout_dir(): def bug_59270_recipes_always_start_in_buildout_dir():
""" r"""
Recipes can rely on running from buildout directory Recipes can rely on running from buildout directory
>>> mkdir('bad_start') >>> mkdir('bad_start')
>>> write('bad_recipe.py', >>> write('bad_recipe.py',
... ''' ... r'''
... import os ... import os, sys
... class Bad: ... class Bad:
... def __init__(self, *_): ... def __init__(self, *_):
... print os.getcwd() ... print os.getcwd()
... def install(self): ... def install(self):
... print os.getcwd() ... sys.stdout.write(os.getcwd()+'\n')
... os.chdir('bad_start') ... os.chdir('bad_start')
... print os.getcwd() ... sys.stdout.write(os.getcwd()+'\n')
... return () ... return ()
... ''') ... ''')
...@@ -1827,8 +1843,8 @@ def bug_59270_recipes_always_start_in_buildout_dir(): ...@@ -1827,8 +1843,8 @@ def bug_59270_recipes_always_start_in_buildout_dir():
... ''') ... ''')
>>> os.chdir('bad_start') >>> os.chdir('bad_start')
>>> print system(join(sample_buildout, 'bin', 'buildout') >>> print_(system(join(sample_buildout, 'bin', 'buildout')
... +' -c '+join(sample_buildout, 'buildout.cfg')), ... +' -c '+join(sample_buildout, 'buildout.cfg')), end=' ')
Develop: '/sample-buildout/.' Develop: '/sample-buildout/.'
/sample-buildout /sample-buildout
/sample-buildout /sample-buildout
...@@ -1857,7 +1873,7 @@ def bug_61890_file_urls_dont_seem_to_work_in_find_dash_links(): ...@@ -1857,7 +1873,7 @@ def bug_61890_file_urls_dont_seem_to_work_in_find_dash_links():
>>> for dist in ws: >>> for dist in ws:
... print dist ... print_(dist)
demo 0.2 demo 0.2
demoneeded 1.1 demoneeded 1.1
...@@ -1870,7 +1886,7 @@ def bug_61890_file_urls_dont_seem_to_work_in_find_dash_links(): ...@@ -1870,7 +1886,7 @@ def bug_61890_file_urls_dont_seem_to_work_in_find_dash_links():
def bug_75607_buildout_should_not_run_if_it_creates_an_empty_buildout_cfg(): def bug_75607_buildout_should_not_run_if_it_creates_an_empty_buildout_cfg():
""" """
>>> remove('buildout.cfg') >>> remove('buildout.cfg')
>>> print system(buildout), >>> print_(system(buildout), end=' ')
While: While:
Initializing. Initializing.
Error: Couldn't open /sample-buildout/buildout.cfg Error: Couldn't open /sample-buildout/buildout.cfg
...@@ -1911,7 +1927,7 @@ def dealing_with_extremely_insane_dependencies(): ...@@ -1911,7 +1927,7 @@ def dealing_with_extremely_insane_dependencies():
... eggs = pack0 ... eggs = pack0
... ''') ... ''')
>>> print system(buildout), >>> print_(system(buildout), end=' ')
Develop: '/sample-buildout/pack0' Develop: '/sample-buildout/pack0'
Develop: '/sample-buildout/pack1' Develop: '/sample-buildout/pack1'
Develop: '/sample-buildout/pack2' Develop: '/sample-buildout/pack2'
...@@ -1927,7 +1943,7 @@ def dealing_with_extremely_insane_dependencies(): ...@@ -1927,7 +1943,7 @@ def dealing_with_extremely_insane_dependencies():
However, if we run in verbose mode, we can see why packages were included: However, if we run in verbose mode, we can see why packages were included:
>>> print system(buildout+' -v'), # doctest: +ELLIPSIS >>> print_(system(buildout+' -v'), end=' ') # doctest: +ELLIPSIS
Installing 'zc.buildout', 'distribute'. Installing 'zc.buildout', 'distribute'.
We have a develop egg: zc.buildout 1.0.0 We have a develop egg: zc.buildout 1.0.0
We have the best distribution that satisfies 'distribute'. We have the best distribution that satisfies 'distribute'.
...@@ -1992,7 +2008,7 @@ We'll create a wacky buildout extension that is just another name for http: ...@@ -1992,7 +2008,7 @@ We'll create a wacky buildout extension that is just another name for http:
... }, ... },
... ) ... )
... ''') ... ''')
>>> print system(buildout+' setup '+src+' bdist_egg'), >>> print_(system(buildout+' setup '+src+' bdist_egg'), end=' ')
... # doctest: +ELLIPSIS ... # doctest: +ELLIPSIS
Running setup ... Running setup ...
creating 'dist/wackyextension-1-... creating 'dist/wackyextension-1-...
...@@ -2016,7 +2032,7 @@ Now we'll create a buildout that uses this extension to load other packages: ...@@ -2016,7 +2032,7 @@ Now we'll create a buildout that uses this extension to load other packages:
When we run the buildout. it will load the extension from the dist When we run the buildout. it will load the extension from the dist
directory and then use the wacky extension to load the demo package directory and then use the wacky extension to load the demo package
>>> print system(buildout), >>> print_(system(buildout), end=' ')
Getting distribution for 'wackyextension'. Getting distribution for 'wackyextension'.
Got wackyextension 1. Got wackyextension 1.
Installing demo. Installing demo.
...@@ -2038,7 +2054,7 @@ need to make it to the download cache. ...@@ -2038,7 +2054,7 @@ need to make it to the download cache.
... setup(name='foo') ... setup(name='foo')
... ''') ... ''')
>>> print system(buildout+' setup test bdist_egg'), # doctest: +ELLIPSIS >>> print_(system(buildout+' setup test bdist_egg')) # doctest: +ELLIPSIS
Running setup script 'test/setup.py'. Running setup script 'test/setup.py'.
... ...
...@@ -2098,9 +2114,9 @@ def prefer_final_permutation(existing, available): ...@@ -2098,9 +2114,9 @@ def prefer_final_permutation(existing, available):
) )
if dist.extras: if dist.extras:
print 'downloaded', dist.version print_('downloaded', dist.version)
else: else:
print 'had', dist.version print_('had', dist.version)
sys.path_importer_cache.clear() sys.path_importer_cache.clear()
def prefer_final(): def prefer_final():
...@@ -2217,7 +2233,7 @@ The default is prefer-final = false: ...@@ -2217,7 +2233,7 @@ The default is prefer-final = false:
... eggs = demo ... eggs = demo
... ''' % globals()) ... ''' % globals())
>>> print system(buildout+' -v'), # doctest: +ELLIPSIS >>> print_(system(buildout+' -v'), end=' ') # doctest: +ELLIPSIS
Installing 'zc.buildout', 'distribute'. Installing 'zc.buildout', 'distribute'.
... ...
Picked: demo = 0.4c1 Picked: demo = 0.4c1
...@@ -2239,7 +2255,7 @@ We get the same behavior if we add prefer-final = false ...@@ -2239,7 +2255,7 @@ We get the same behavior if we add prefer-final = false
... eggs = demo ... eggs = demo
... ''' % globals()) ... ''' % globals())
>>> print system(buildout+' -v'), # doctest: +ELLIPSIS >>> print_(system(buildout+' -v'), end=' ') # doctest: +ELLIPSIS
Installing 'zc.buildout', 'distribute'. Installing 'zc.buildout', 'distribute'.
... ...
Picked: demo = 0.4c1 Picked: demo = 0.4c1
...@@ -2261,7 +2277,7 @@ distributions: ...@@ -2261,7 +2277,7 @@ distributions:
... eggs = demo ... eggs = demo
... ''' % globals()) ... ''' % globals())
>>> print system(buildout+' -v'), # doctest: +ELLIPSIS >>> print_(system(buildout+' -v'), end=' ') # doctest: +ELLIPSIS
Installing 'zc.buildout', 'distribute'. Installing 'zc.buildout', 'distribute'.
... ...
Picked: demo = 0.3 Picked: demo = 0.3
...@@ -2282,7 +2298,7 @@ We get an error if we specify anything but true or false: ...@@ -2282,7 +2298,7 @@ We get an error if we specify anything but true or false:
... eggs = demo ... eggs = demo
... ''' % globals()) ... ''' % globals())
>>> print system(buildout+' -v'), # doctest: +ELLIPSIS >>> print_(system(buildout+' -v'), end=' ') # doctest: +ELLIPSIS
While: While:
Initializing. Initializing.
Error: Invalid value for prefer-final option: no Error: Invalid value for prefer-final option: no
...@@ -2312,7 +2328,7 @@ Distribution setup scripts can import modules in the distribution directory: ...@@ -2312,7 +2328,7 @@ Distribution setup scripts can import modules in the distribution directory:
... parts = ... parts =
... ''') ... ''')
>>> print system(join('bin', 'buildout')), >>> print_(system(join('bin', 'buildout')), end=' ')
Develop: '/sample-buildout/foo' Develop: '/sample-buildout/foo'
>>> ls('develop-eggs') >>> ls('develop-eggs')
...@@ -2353,7 +2369,7 @@ honoring our version specification. ...@@ -2353,7 +2369,7 @@ honoring our version specification.
... ''' % pkg_resources.working_set.find( ... ''' % pkg_resources.working_set.find(
... pkg_resources.Requirement.parse('distribute')).version) ... pkg_resources.Requirement.parse('distribute')).version)
>>> print system(buildout), >>> print_(system(buildout), end=' ')
Installing foo. Installing foo.
Getting distribution for 'foo==1'. Getting distribution for 'foo==1'.
Got foo 1. Got foo 1.
...@@ -2378,13 +2394,13 @@ def pyc_and_pyo_files_have_correct_paths(): ...@@ -2378,13 +2394,13 @@ def pyc_and_pyo_files_have_correct_paths():
>>> _ = system(buildout) >>> _ = system(buildout)
>>> write('t.py', >>> write('t.py',
... ''' ... r'''
... import eggrecipedemo, eggrecipedemoneeded ... import eggrecipedemo, eggrecipedemoneeded, sys
... print eggrecipedemo.main.func_code.co_filename ... sys.stdout.write(eggrecipedemo.main.func_code.co_filename+'\n')
... print eggrecipedemoneeded.f.func_code.co_filename ... sys.stdout.write(eggrecipedemoneeded.f.func_code.co_filename+'\n')
... ''') ... ''')
>>> print system(join('bin', 'py')+ ' t.py'), >>> print_(system(join('bin', 'py')+ ' t.py'), end=' ')
/sample-buildout/eggs/demo-0.4c1-py2.4.egg/eggrecipedemo.py /sample-buildout/eggs/demo-0.4c1-py2.4.egg/eggrecipedemo.py
/sample-buildout/eggs/demoneeded-1.2c1-py2.4.egg/eggrecipedemoneeded.py /sample-buildout/eggs/demoneeded-1.2c1-py2.4.egg/eggrecipedemoneeded.py
...@@ -2407,7 +2423,7 @@ def dont_mess_with_standard_dirs_with_variable_refs(): ...@@ -2407,7 +2423,7 @@ def dont_mess_with_standard_dirs_with_variable_refs():
... eggs-directory = ${buildout:directory}/develop-eggs ... eggs-directory = ${buildout:directory}/develop-eggs
... parts = ... parts =
... ''' % globals()) ... ''' % globals())
>>> print system(buildout), >>> print_(system(buildout), end=' ')
""" """
...@@ -2438,7 +2454,7 @@ def expand_shell_patterns_in_develop_paths(): ...@@ -2438,7 +2454,7 @@ def expand_shell_patterns_in_develop_paths():
We can see that both eggs were found: We can see that both eggs were found:
>>> print system(buildout), >>> print_(system(buildout), end=' ')
Develop: '/sample-buildout/sampley' Develop: '/sample-buildout/sampley'
Develop: '/sample-buildout/samplez' Develop: '/sample-buildout/samplez'
Installing eggs. Installing eggs.
...@@ -2470,7 +2486,7 @@ def warn_users_when_expanding_shell_patterns_yields_no_results(): ...@@ -2470,7 +2486,7 @@ def warn_users_when_expanding_shell_patterns_yields_no_results():
We should get one of the eggs, and a warning for the pattern that We should get one of the eggs, and a warning for the pattern that
did not match anything. did not match anything.
>>> print system(buildout), >>> print_(system(buildout), end=' ')
Develop: '/sample-buildout/samplea' Develop: '/sample-buildout/samplea'
Couldn't develop '/sample-buildout/grumble*' (not found) Couldn't develop '/sample-buildout/grumble*' (not found)
Installing eggs. Installing eggs.
...@@ -2525,7 +2541,7 @@ def increment_buildout_options(): ...@@ -2525,7 +2541,7 @@ def increment_buildout_options():
... <= p1 ... <= p1
... ''') ... ''')
>>> print system(buildout), >>> print_(system(buildout), end=' ')
Installing p1. Installing p1.
foo='1\n2 b' foo='1\n2 b'
recipe='zc.buildout:debug' recipe='zc.buildout:debug'
...@@ -2565,7 +2581,7 @@ def increment_buildout_with_multiple_extended_files_421022(): ...@@ -2565,7 +2581,7 @@ def increment_buildout_with_multiple_extended_files_421022():
... x = ${buildout:bar-option} ${buildout:foo-option} ... x = ${buildout:bar-option} ${buildout:foo-option}
... ''') ... ''')
>>> print system(buildout), >>> print_(system(buildout), end=' ')
Installing p. Installing p.
recipe='zc.buildout:debug' recipe='zc.buildout:debug'
x='bar\nbaz foo\nham' x='bar\nbaz foo\nham'
...@@ -2592,7 +2608,7 @@ def increment_on_command_line(): ...@@ -2592,7 +2608,7 @@ def increment_on_command_line():
... <= p1 ... <= p1
... ''') ... ''')
>>> print system(buildout+' buildout:parts+=p2 p1:foo+=bar'), >>> print_(system(buildout+' buildout:parts+=p2 p1:foo+=bar'), end=' ')
Installing p1. Installing p1.
foo='1 a\nb\nbar' foo='1 a\nb\nbar'
recipe='zc.buildout:debug' recipe='zc.buildout:debug'
...@@ -2624,7 +2640,11 @@ def create_sample_eggs(test, executable=sys.executable): ...@@ -2624,7 +2640,11 @@ def create_sample_eggs(test, executable=sys.executable):
) )
zc.buildout.testing.sdist(tmp, dest) zc.buildout.testing.sdist(tmp, dest)
write(tmp, 'distutilsscript', '#!/usr/bin/python\nprint "distutils!"') write(
tmp, 'distutilsscript',
'#!/usr/bin/python\n'
'import sys; sys.stdout.write("distutils!\\n")\n'
)
write( write(
tmp, 'setup.py', tmp, 'setup.py',
"from setuptools import setup\n" "from setuptools import setup\n"
...@@ -2649,9 +2669,12 @@ def create_sample_eggs(test, executable=sys.executable): ...@@ -2649,9 +2669,12 @@ def create_sample_eggs(test, executable=sys.executable):
for i in (1, 2, 3, 4): for i in (1, 2, 3, 4):
write( write(
tmp, 'eggrecipedemo.py', tmp, 'eggrecipedemo.py',
'import eggrecipedemoneeded\n' 'import eggrecipedemoneeded, sys\n'
'def print_(*a):\n'
' sys.stdout.write(" ".join(map(str, a))+"\\n")\n'
'x=%s\n' 'x=%s\n'
'def main(): print x, eggrecipedemoneeded.y\n' 'def main():\n'
' print_(x, eggrecipedemoneeded.y)\n'
% i) % i)
c1 = i==4 and 'c1' or '' c1 = i==4 and 'c1' or ''
write( write(
...@@ -2679,7 +2702,7 @@ def create_sample_eggs(test, executable=sys.executable): ...@@ -2679,7 +2702,7 @@ def create_sample_eggs(test, executable=sys.executable):
finally: finally:
shutil.rmtree(tmp) shutil.rmtree(tmp)
extdemo_c = """ extdemo_c2 = """
#include <Python.h> #include <Python.h>
#include <extdemo.h> #include <extdemo.h>
...@@ -2698,12 +2721,43 @@ initextdemo(void) ...@@ -2698,12 +2721,43 @@ initextdemo(void)
} }
""" """
extdemo_setup_py = """ extdemo_c3 = """
import os #include <Python.h>
#include <extdemo.h>
static PyMethodDef methods[] = {{NULL}};
#define MOD_DEF(ob, name, doc, methods) \
static struct PyModuleDef moduledef = { \
PyModuleDef_HEAD_INIT, name, doc, -1, methods, }; \
ob = PyModule_Create(&moduledef);
#define MOD_INIT(name) PyMODINIT_FUNC PyInit_##name(void)
MOD_INIT(extdemo)
{
PyObject *m;
MOD_DEF(m, "extdemo", "", methods);
#ifdef TWO
PyModule_AddObject(m, "val", PyLong_FromLong(2));
#else
PyModule_AddObject(m, "val", PyLong_FromLong(EXTDEMO));
#endif
return m;
}
"""
extdemo_c = sys.version_info[0] < 3 and extdemo_c2 or extdemo_c3
extdemo_setup_py = r"""
import os, sys
from distutils.core import setup, Extension from distutils.core import setup, Extension
if os.environ.get('test-variable'): if os.environ.get('test-variable'):
print "Have environment test-variable:", os.environ['test-variable'] print("Have environment test-variable: %%s" %% os.environ['test-variable'])
setup(name = "extdemo", version = "%s", url="http://www.zope.org", setup(name = "extdemo", version = "%s", url="http://www.zope.org",
author="Demo", author_email="demo@demo.com", author="Demo", author_email="demo@demo.com",
...@@ -2712,7 +2766,6 @@ setup(name = "extdemo", version = "%s", url="http://www.zope.org", ...@@ -2712,7 +2766,6 @@ setup(name = "extdemo", version = "%s", url="http://www.zope.org",
""" """
def add_source_dist(test, version=1.4): def add_source_dist(test, version=1.4):
if 'extdemo' not in test.globs: if 'extdemo' not in test.globs:
test.globs['extdemo'] = test.globs['tmpdir']('extdemo') test.globs['extdemo'] = test.globs['tmpdir']('extdemo')
...@@ -2968,6 +3021,7 @@ def test_suite(): ...@@ -2968,6 +3021,7 @@ def test_suite():
zc.buildout.testing.normalize_endings, zc.buildout.testing.normalize_endings,
zc.buildout.testing.normalize_script, zc.buildout.testing.normalize_script,
zc.buildout.testing.normalize_egg_py, zc.buildout.testing.normalize_egg_py,
zc.buildout.testing.normalize_exception_type_for_python_2_and_3,
normalize_bang, normalize_bang,
normalize_S, normalize_S,
(re.compile('extdemo[.]pyd'), 'extdemo.so'), (re.compile('extdemo[.]pyd'), 'extdemo.so'),
...@@ -3076,3 +3130,4 @@ def test_suite(): ...@@ -3076,3 +3130,4 @@ def test_suite():
)) ))
return unittest.TestSuite(test_suite) return unittest.TestSuite(test_suite)
...@@ -34,6 +34,8 @@ zc.buildout used: ...@@ -34,6 +34,8 @@ zc.buildout used:
>>> write(sample_buildout, 'showversions', 'showversions.py', >>> write(sample_buildout, 'showversions', 'showversions.py',
... """ ... """
... import pkg_resources ... import pkg_resources
... import sys
... print_ = lambda *a: sys.stdout.write(' '.join(map(str, a))+'\n')
... ...
... class Recipe: ... class Recipe:
... ...
...@@ -43,7 +45,7 @@ zc.buildout used: ...@@ -43,7 +45,7 @@ zc.buildout used:
... def install(self): ... def install(self):
... for project in 'zc.buildout', 'distribute': ... for project in 'zc.buildout', 'distribute':
... req = pkg_resources.Requirement.parse(project) ... req = pkg_resources.Requirement.parse(project)
... print project, pkg_resources.working_set.find(req).version ... print_(project, pkg_resources.working_set.find(req).version)
... return () ... return ()
... update = install ... update = install
... """) ... """)
...@@ -63,7 +65,7 @@ zc.buildout used: ...@@ -63,7 +65,7 @@ zc.buildout used:
Now if we run the buildout, the buildout will upgrade itself to the Now if we run the buildout, the buildout will upgrade itself to the
new versions found in new releases: new versions found in new releases:
>>> print system(buildout), >>> print_(system(buildout), end='')
Getting distribution for 'distribute'. Getting distribution for 'distribute'.
Got distribute 99.99. Got distribute 99.99.
Upgraded: Upgraded:
...@@ -111,7 +113,7 @@ will install earlier versions of these packages: ...@@ -111,7 +113,7 @@ will install earlier versions of these packages:
Now we can see that we actually "upgrade" to an earlier version. Now we can see that we actually "upgrade" to an earlier version.
>>> print system(buildout), >>> print_(system(buildout), end='')
Upgraded: Upgraded:
distribute version 0.6; distribute version 0.6;
restarting. restarting.
...@@ -138,7 +140,7 @@ We won't upgrade in offline mode: ...@@ -138,7 +140,7 @@ We won't upgrade in offline mode:
... recipe = showversions ... recipe = showversions
... """ % dict(new_releases=new_releases)) ... """ % dict(new_releases=new_releases))
>>> print system(buildout+' -o'), >>> print_(system(buildout+' -o'), ed='')
Develop: '/sample-buildout/showversions' Develop: '/sample-buildout/showversions'
Updating show-versions. Updating show-versions.
zc.buildout 1.0.0 zc.buildout 1.0.0
...@@ -146,7 +148,7 @@ We won't upgrade in offline mode: ...@@ -146,7 +148,7 @@ We won't upgrade in offline mode:
Or in non-newest mode: Or in non-newest mode:
>>> print system(buildout+' -N'), >>> print_(system(buildout+' -N'), end='')
Develop: '/sample-buildout/showversions' Develop: '/sample-buildout/showversions'
Updating show-versions. Updating show-versions.
zc.buildout 1.0.0 zc.buildout 1.0.0
...@@ -166,7 +168,7 @@ directory: ...@@ -166,7 +168,7 @@ directory:
... """ % dict(new_releases=new_releases)) ... """ % dict(new_releases=new_releases))
>>> cd(sample_buildout2) >>> cd(sample_buildout2)
>>> print system(buildout), >>> print_(system(buildout), end='')
Creating directory '/sample_buildout2/bin'. Creating directory '/sample_buildout2/bin'.
Creating directory '/sample_buildout2/parts'. Creating directory '/sample_buildout2/parts'.
Creating directory '/sample_buildout2/eggs'. Creating directory '/sample_buildout2/eggs'.
......
...@@ -14,6 +14,8 @@ can't delete. ...@@ -14,6 +14,8 @@ can't delete.
>>> write('recipe', 'recipe.py', >>> write('recipe', 'recipe.py',
... ''' ... '''
... import os ... import os
... import sys
... print_ = lambda *a: sys.stdout.write(' '.join(map(str, a))+'\n')
... class Recipe: ... class Recipe:
... def __init__(self, buildout, name, options): ... def __init__(self, buildout, name, options):
... self.location = os.path.join( ... self.location = os.path.join(
...@@ -21,7 +23,7 @@ can't delete. ...@@ -21,7 +23,7 @@ can't delete.
... name) ... name)
... ...
... def install(self): ... def install(self):
... print "can't remove read only files" ... print_("can't remove read only files")
... if not os.path.exists (self.location): ... if not os.path.exists (self.location):
... os.makedirs (self.location) ... os.makedirs (self.location)
... ...
...@@ -43,7 +45,7 @@ can't delete. ...@@ -43,7 +45,7 @@ can't delete.
>>> write('recipe', 'README', '') >>> write('recipe', 'README', '')
>>> print system(buildout+' setup recipe bdist_egg'), # doctest: +ELLIPSIS >>> print_(system(buildout+' setup recipe bdist_egg')) # doctest: +ELLIPSIS
Running setup script 'recipe/setup.py'. Running setup script 'recipe/setup.py'.
... ...
...@@ -59,7 +61,7 @@ and we'll configure a buildout to use it: ...@@ -59,7 +61,7 @@ and we'll configure a buildout to use it:
... recipe = spam ... recipe = spam
... ''' % join('recipe', 'dist')) ... ''' % join('recipe', 'dist'))
>>> print system(buildout), >>> print_(system(buildout), end='')
Getting distribution for 'spam'. Getting distribution for 'spam'.
Got spam 1. Got spam 1.
Installing foo. Installing foo.
......
...@@ -61,7 +61,7 @@ class Custom(Base): ...@@ -61,7 +61,7 @@ class Custom(Base):
self.environment = buildout[environment_section] self.environment = buildout[environment_section]
else: else:
self.environment = {} self.environment = {}
environment_data = self.environment.items() environment_data = list(self.environment.items())
environment_data.sort() environment_data.sort()
options['_environment-data'] = repr(environment_data) options['_environment-data'] = repr(environment_data)
...@@ -98,7 +98,7 @@ class Custom(Base): ...@@ -98,7 +98,7 @@ class Custom(Base):
def _set_environment(self): def _set_environment(self):
self._saved_environment = {} self._saved_environment = {}
for key, value in self.environment.items(): for key, value in list(self.environment.items()):
if key in os.environ: if key in os.environ:
self._saved_environment[key] = os.environ[key] self._saved_environment[key] = os.environ[key]
# Interpolate value with variables from environment. Maybe there # Interpolate value with variables from environment. Maybe there
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment