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
......
This diff is collapsed.
This diff is collapsed.
##############################################################################
#
# 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'))
""" """
......
This diff is collapsed.
...@@ -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
This diff is collapsed.
...@@ -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