Commit 5985f242 authored by Jason Madden's avatar Jason Madden Committed by Julien Muchembled

Fix most Deprecation and Resource warnings.

On Python 3, these made the build output very hard to read (e.g., https://travis-ci.org/buildout/buildout/jobs/394026829)

On Python 3.7, these could actually break the doctests.

Closing the files should get us closer to being able to pass the tests with PyPy.
parent 8a4fcd21
...@@ -51,4 +51,4 @@ clean: ...@@ -51,4 +51,4 @@ clean:
rm -rf $(BUILD_DIRS) $(PYTHON_BUILD_DIR) rm -rf $(BUILD_DIRS) $(PYTHON_BUILD_DIR)
test: test:
$(HERE)/bin/test -1 -v $(HERE)/bin/test -1 -vvv -c
...@@ -18,7 +18,8 @@ import os ...@@ -18,7 +18,8 @@ import os
from setuptools import setup from setuptools import setup
def read(*rnames): def read(*rnames):
return open(os.path.join(os.path.dirname(__file__), *rnames)).read() with open(os.path.join(os.path.dirname(__file__), *rnames)) as f:
return f.read()
doc_intro = """ doc_intro = """
......
...@@ -19,7 +19,9 @@ Make sure the bootstrap script actually works:: ...@@ -19,7 +19,9 @@ Make sure the bootstrap script actually works::
... [buildout] ... [buildout]
... parts = ... parts =
... ''') ... ''')
>>> write('bootstrap.py', open(bootstrap_py).read()) >>> with open(bootstrap_py) as f:
... bootstrap_py_contents = f.read()
>>> write('bootstrap.py', bootstrap_py_contents)
>>> 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
...@@ -52,7 +54,7 @@ By default it gets the latest version:: ...@@ -52,7 +54,7 @@ By default it gets the latest version::
>>> 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 >>> with open(buildout_script) as f: print_(f.read()) # doctest: +ELLIPSIS
#... #...
sys.path[0:0] = [ sys.path[0:0] = [
'/sample/eggs/zc.buildout-22.0.0...egg', '/sample/eggs/zc.buildout-22.0.0...egg',
...@@ -83,7 +85,7 @@ Now let's try with ``2.0.0``, which happens to exist:: ...@@ -83,7 +85,7 @@ Now let's try with ``2.0.0``, which happens to exist::
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 >>> with open(buildout_script) as f: print_(f.read()) # doctest: +ELLIPSIS
#... #...
sys.path[0:0] = [ sys.path[0:0] = [
'/sample/eggs/zc.buildout-2.0.0...egg', '/sample/eggs/zc.buildout-2.0.0...egg',
...@@ -103,7 +105,7 @@ Now let's try with ``31.0.0``, which happens to exist:: ...@@ -103,7 +105,7 @@ Now let's try with ``31.0.0``, which happens to exist::
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 >>> with open(buildout_script) as f: print_(f.read()) # doctest: +ELLIPSIS
#... #...
sys.path[0:0] = [ sys.path[0:0] = [
'/sample/eggs/zc.buildout-...egg', '/sample/eggs/zc.buildout-...egg',
...@@ -121,7 +123,7 @@ which happens to exist:: ...@@ -121,7 +123,7 @@ which happens to exist::
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 >>> with open(buildout_script) as f: print_(f.read()) # doctest: +ELLIPSIS
#... #...
sys.path[0:0] = [ sys.path[0:0] = [
'/sample/eggs/zc.buildout-2.0.0...egg', '/sample/eggs/zc.buildout-2.0.0...egg',
...@@ -153,7 +155,7 @@ specify the setuptools version, and to reuse the setuptools zipfile:: ...@@ -153,7 +155,7 @@ specify the setuptools version, and to reuse the setuptools zipfile::
>>> os.path.exists('setuptools-32.1.0.zip') >>> os.path.exists('setuptools-32.1.0.zip')
True True
>>> print_(open(buildout_script).read()) # doctest: +ELLIPSIS >>> with open(buildout_script) as f: print_(f.read()) # doctest: +ELLIPSIS
#... #...
sys.path[0:0] = [ sys.path[0:0] = [
'/sample/eggs/zc.buildout-2.0.0...egg', '/sample/eggs/zc.buildout-2.0.0...egg',
......
...@@ -20,7 +20,8 @@ Some people pass buildout settings to bootstrap. ...@@ -20,7 +20,8 @@ Some people pass buildout settings to bootstrap.
... [buildout] ... [buildout]
... parts = ... parts =
... ''') ... ''')
>>> write('bootstrap.py', open(bootstrap_py).read()) >>> with open(bootstrap_py) as f: bootstrap_py_contents = f.read()
>>> write('bootstrap.py', bootstrap_py_contents)
>>> 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 buildout:directory=' + top + ... ' bootstrap.py buildout:directory=' + top +
...@@ -43,7 +44,8 @@ They might do it with init, but no worries: ...@@ -43,7 +44,8 @@ They might do it with init, but no worries:
>>> os.chdir(top) >>> os.chdir(top)
>>> mkdir(top, 'buildout') >>> mkdir(top, 'buildout')
>>> os.chdir(top) >>> os.chdir(top)
>>> write('bootstrap.py', open(bootstrap_py).read()) >>> with open(bootstrap_py) as f: bootstrap_py_contents = f.read()
>>> write('bootstrap.py', bootstrap_py_contents)
>>> 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 buildout:directory=' + top + ... ' bootstrap.py buildout:directory=' + top +
......
...@@ -586,7 +586,8 @@ class Buildout(DictMixin): ...@@ -586,7 +586,8 @@ class Buildout(DictMixin):
if dist.precedence == pkg_resources.DEVELOP_DIST: if dist.precedence == pkg_resources.DEVELOP_DIST:
dest = os.path.join(options['develop-eggs-directory'], dest = os.path.join(options['develop-eggs-directory'],
name+'.egg-link') name+'.egg-link')
open(dest, 'w').write(dist.location) with open(dest, 'w') as f:
f.write(dist.location)
entries.append(dist.location) entries.append(dist.location)
else: else:
dest = os.path.join(options['eggs-directory'], dest = os.path.join(options['eggs-directory'],
...@@ -905,8 +906,8 @@ class Buildout(DictMixin): ...@@ -905,8 +906,8 @@ class Buildout(DictMixin):
setup = self._buildout_path(setup) setup = self._buildout_path(setup)
files = glob.glob(setup) files = glob.glob(setup)
if not files: if not files:
self._logger.warn("Couldn't develop %r (not found)", self._logger.warning("Couldn't develop %r (not found)",
setup) setup)
else: else:
files.sort() files.sort()
for setup in files: for setup in files:
...@@ -1138,8 +1139,8 @@ class Buildout(DictMixin): ...@@ -1138,8 +1139,8 @@ class Buildout(DictMixin):
if (realpath(os.path.abspath(sys.argv[0])) != should_run): if (realpath(os.path.abspath(sys.argv[0])) != should_run):
self._logger.debug("Running %r.", realpath(sys.argv[0])) self._logger.debug("Running %r.", realpath(sys.argv[0]))
self._logger.debug("Local buildout is %r.", should_run) self._logger.debug("Local buildout is %r.", should_run)
self._logger.warn("Not upgrading because not running a local " self._logger.warning("Not upgrading because not running a local "
"buildout command.") "buildout command.")
return return
self._logger.info("Upgraded:\n %s;\nrestarting.", self._logger.info("Upgraded:\n %s;\nrestarting.",
...@@ -1548,7 +1549,7 @@ class Options(DictMixin): ...@@ -1548,7 +1549,7 @@ class Options(DictMixin):
_template_split = re.compile('([$]{[^}]*})').split _template_split = re.compile('([$]{[^}]*})').split
_simple = re.compile('[-a-zA-Z0-9 ._]+$').match _simple = re.compile('[-a-zA-Z0-9 ._]+$').match
_valid = re.compile('\${[-a-zA-Z0-9 ._]*:[-a-zA-Z0-9 ._]+}$').match _valid = re.compile(r'\${[-a-zA-Z0-9 ._]*:[-a-zA-Z0-9 ._]+}$').match
def _sub(self, template, seen, last=True): def _sub(self, template, seen, last=True):
value = self._template_split(template) value = self._template_split(template)
subs = [] subs = []
...@@ -1652,7 +1653,7 @@ class Options(DictMixin): ...@@ -1652,7 +1653,7 @@ class Options(DictMixin):
elif os.path.isfile(p): elif os.path.isfile(p):
os.remove(p) os.remove(p)
else: else:
self.buildout._logger.warn("Couldn't clean up %r.", p) self.buildout._logger.warning("Couldn't clean up %r.", p)
raise raise
finally: finally:
self._created = None self._created = None
...@@ -2037,9 +2038,9 @@ def _check_for_unused_options_in_section(buildout, section): ...@@ -2037,9 +2038,9 @@ def _check_for_unused_options_in_section(buildout, section):
unused = [option for option in sorted(options._raw) unused = [option for option in sorted(options._raw)
if option not in options._data] if option not in options._data]
if unused: if unused:
buildout._logger.warn("Unused options for %s: %s." buildout._logger.warning("Unused options for %s: %s."
% (section, ' '.join(map(repr, unused))) % (section, ' '.join(map(repr, unused)))
) )
_usage = """\ _usage = """\
Usage: buildout [options] [assignments] [command [command arguments]] Usage: buildout [options] [assignments] [command [command arguments]]
......
...@@ -3342,3 +3342,7 @@ We see that our extension is loaded and executed:: ...@@ -3342,3 +3342,7 @@ We see that our extension is loaded and executed::
ext ['buildout', 'versions'] ext ['buildout', 'versions']
Develop: '/sample-bootstrapped/demo' Develop: '/sample-bootstrapped/demo'
unload ['buildout', 'versions'] unload ['buildout', 'versions']
..
>>> stop_server(server_url)
...@@ -178,7 +178,7 @@ def parse(fp, fpname, exp_globals=dict): ...@@ -178,7 +178,7 @@ def parse(fp, fpname, exp_globals=dict):
tail = tail.replace(';', '#') if tail else '' tail = tail.replace(';', '#') if tail else ''
# un-escape literal # and ; . Do not use a # un-escape literal # and ; . Do not use a
# string-escape decode # string-escape decode
expr = expression.replace(r'\x23','#').replace(r'x3b', ';') expr = expression.replace(r'\x23','#').replace(r'\x3b', ';')
# rebuild a valid Python expression wrapped in a list # rebuild a valid Python expression wrapped in a list
expr = head + expr + tail expr = head + expr + tail
# lazily populate context only expression # lazily populate context only expression
......
...@@ -33,7 +33,7 @@ First, an example that illustrates a well-formed configuration:: ...@@ -33,7 +33,7 @@ First, an example that illustrates a well-formed configuration::
b += 1 b += 1
[s3]; comment [s3]; comment
x = a b x = a b
.. -> text .. -> text
...@@ -91,9 +91,9 @@ otherwise empty section) is blank. For example:" ...@@ -91,9 +91,9 @@ otherwise empty section) is blank. For example:"
'versions': {}} 'versions': {}}
Sections headers can contain an optional arbitrary Python expression. Sections headers can contain an optional arbitrary Python expression.
When the expression evaluates to false the whole section is skipped. When the expression evaluates to false the whole section is skipped.
Several sections can have the same name with different expressions, enabling Several sections can have the same name with different expressions, enabling
conditional exclusion of sections:: conditional exclusion of sections::
[s1: 2 + 2 == 4] # this expression is true [therefore "this section" _will_ be NOT skipped [s1: 2 + 2 == 4] # this expression is true [therefore "this section" _will_ be NOT skipped
...@@ -105,7 +105,7 @@ conditional exclusion of sections:: ...@@ -105,7 +105,7 @@ conditional exclusion of sections::
[ s2 : 41 + 1 == 42 ] # a comment: this expression is [true], so this section will be kept [ s2 : 41 + 1 == 42 ] # a comment: this expression is [true], so this section will be kept
long = b long = b
[s3:2 in map(lambda i:i*2, [i for i in range(10)])] ;# Complex expressions are [possible!];, though they should not be (abused:) [s3:2 in map(lambda i:i*2, [i for i in range(10)])] ;# Complex expressions are [possible!];, though they should not be (abused:)
# this section will not be skipped # this section will not be skipped
long = c long = c
...@@ -120,11 +120,11 @@ conditional exclusion of sections:: ...@@ -120,11 +120,11 @@ conditional exclusion of sections::
Title line optional trailing comments are separated by a hash '#' or semicolon Title line optional trailing comments are separated by a hash '#' or semicolon
';' character. The expression is an arbitrary expression with one restriction: ';' character. The expression is an arbitrary expression with one restriction:
it cannot contain a literal hash '#' or semicolon ';' character: these need to be it cannot contain a literal hash '#' or semicolon ';' character: these need to be
string-escaped. string-escaped.
The comment can contain arbitrary characters, including brackets that are also The comment can contain arbitrary characters, including brackets that are also
used to mark the end of a section header and may be ambiguous to recognize in used to mark the end of a section header and may be ambiguous to recognize in
some cases. For example, valid sections lines include:: some cases. For example, valid sections lines include::
[ a ] [ a ]
...@@ -177,7 +177,7 @@ some cases. For example, valid sections lines include:: ...@@ -177,7 +177,7 @@ some cases. For example, valid sections lines include::
A title line optional trailing comment be separated by a hash or semicolon A title line optional trailing comment be separated by a hash or semicolon
character. The following are valid semicolon-separated comments:: character. The following are valid semicolon-separated comments::
[ a ] ;semicolon comment are supported for lines without expressions ] [ a ] ;semicolon comment are supported for lines without expressions ]
...@@ -241,10 +241,10 @@ The following sections with hash comment separators are valid too:: ...@@ -241,10 +241,10 @@ The following sections with hash comment separators are valid too::
'e': {'e': '1'}} 'e': {'e': '1'}}
However, explicit semicolon and hash characters are invalid in expressions and However, explicit semicolon and hash characters are invalid in expressions and
must be escaped or this triggers an error. In the rare case where a hash '#' or must be escaped or this triggers an error. In the rare case where a hash '#' or
semicolon ';' would be needed in an expression literal, you can use the semicolon ';' would be needed in an expression literal, you can use the
string-escaped representation of these characters: use '\x23' for hash '#' and string-escaped representation of these characters: use '\x23' for hash '#' and
'\x3b' for semicolon ';' to avoid evaluation errors. '\x3b' for semicolon ';' to avoid evaluation errors.
These expressions are valid and use escaped hash and semicolons in literals:: These expressions are valid and use escaped hash and semicolons in literals::
...@@ -278,11 +278,11 @@ And using unescaped semicolon and hash characters in expressions triggers an err ...@@ -278,11 +278,11 @@ And using unescaped semicolon and hash characters in expressions triggers an err
... except zc.buildout.configparser.MissingSectionHeaderError: pass # success ... except zc.buildout.configparser.MissingSectionHeaderError: pass # success
One of the typical usage of expression is to have buildout parts that are One of the typical usage of expression is to have buildout parts that are
operating system or platform-specific. The configparser.parse function has an operating system or platform-specific. The configparser.parse function has an
optional exp_globals argument. This is a callable returning a mapping of optional exp_globals argument. This is a callable returning a mapping of
objects made available to the evaluation context of the expression. Here we add objects made available to the evaluation context of the expression. Here we add
the platform and sys modules to the evaluation context, so we can access the platform and sys modules to the evaluation context, so we can access
platform and sys modules functions and objects in our expressions :: platform and sys modules functions and objects in our expressions ::
[s1: str(platform.python_version_tuple()[0]) in ('2', '3',)] # this expression is true, the major versions of python are either 2 or 3 [s1: str(platform.python_version_tuple()[0]) in ('2', '3',)] # this expression is true, the major versions of python are either 2 or 3
...@@ -306,8 +306,8 @@ platform and sys modules functions and objects in our expressions :: ...@@ -306,8 +306,8 @@ platform and sys modules functions and objects in our expressions ::
{'s1': {'a': '1'}, 's2': {'long': 'b'}} {'s1': {'a': '1'}, 's2': {'long': 'b'}}
Some limited (but hopefully sane and sufficient) default modules and Some limited (but hopefully sane and sufficient) default modules and
pre-computed common expressions available to an expression when the parser in pre-computed common expressions available to an expression when the parser in
called by buildout:: called by buildout::
...@@ -316,20 +316,20 @@ called by buildout:: ...@@ -316,20 +316,20 @@ called by buildout::
a = 1 a = 1
# major and minor python versions, yes even python 3.5 and 3.6 are there , prospectively # major and minor python versions, yes even python 3.5 and 3.6 are there , prospectively
# comment: this expression "is true" and not that long expression cannot span several lines # comment: this expression "is true" and not that long expression cannot span several lines
[s2: any([python2, python3, python24 , python25 , python26 , python27 , python30 , python31 , python32 , python33 , python34 , python35 , python36]) ] [s2: any([python2, python3, python24 , python25 , python26 , python27 , python30 , python31 , python32 , python33 , python34 , python35 , python36]) ]
b = 1 b = 1
# common python interpreter types # common python interpreter types
[s3:cpython or pypy or jython or ironpython] # a comment: this expression is likely always true, so this section will be kept [s3:cpython or pypy or jython or ironpython] # a comment: this expression is likely always true, so this section will be kept
c = 1 c = 1
# common operating systems # common operating systems
[s4:linux or windows or cygwin or macosx or solaris or posix or True] [s4:linux or windows or cygwin or macosx or solaris or posix or True]
d = 1 d = 1
# common bitness and endianness # common bitness and endianness
[s5:bits32 or bits64 or little_endian or big_endian] [s5:bits32 or bits64 or little_endian or big_endian]
e = 1 e = 1
.. -> text .. -> text
......
...@@ -23,10 +23,20 @@ try: ...@@ -23,10 +23,20 @@ try:
from urllib.request import FancyURLopener, URLopener, urlretrieve from urllib.request import FancyURLopener, URLopener, urlretrieve
from urllib.parse import urlparse from urllib.parse import urlparse
from urllib import request from urllib import request
import warnings
class PatchedURLopener(FancyURLopener): class PatchedURLopener(FancyURLopener):
http_error_default = URLopener.http_error_default http_error_default = URLopener.http_error_default
def __init__(self, *args, **kwargs):
with warnings.catch_warnings():
warnings.simplefilter('ignore')
# This creates a DeprecationWarning on 3.6:
# PatchedURLopener style of invoking requests is deprecated.
# Use newer urlopen functions/methods.
# Said warning breaks our doctests.
super(PatchedURLopener, self).__init__(*args, **kwargs)
request._urlopener = PatchedURLopener() # Ook! Monkey patch! request._urlopener = PatchedURLopener() # Ook! Monkey patch!
except ImportError: except ImportError:
......
...@@ -70,7 +70,7 @@ default_index_url = os.environ.get( ...@@ -70,7 +70,7 @@ default_index_url = os.environ.get(
logger = logging.getLogger('zc.buildout.easy_install') logger = logging.getLogger('zc.buildout.easy_install')
url_match = re.compile('[a-z0-9+.-]+://').match url_match = re.compile('[a-z0-9+.-]+://').match
is_source_encoding_line = re.compile('coding[:=]\s*([-\w.]+)').search is_source_encoding_line = re.compile(r'coding[:=]\s*([-\w.]+)').search
# Source encoding regex from http://www.python.org/dev/peps/pep-0263/ # Source encoding regex from http://www.python.org/dev/peps/pep-0263/
is_win32 = sys.platform == 'win32' is_win32 = sys.platform == 'win32'
......
...@@ -397,7 +397,7 @@ at the end. ...@@ -397,7 +397,7 @@ at the end.
The versions file now contains the extra pin: The versions file now contains the extra pin:
>>> print_(open('my_versions.cfg').read()) # doctest: +ELLIPSIS >>> with open('my_versions.cfg') as f: print_(f.read()) # doctest: +ELLIPSIS
<BLANKLINE> <BLANKLINE>
... ...
# Added by buildout at YYYY-MM-DD hh:mm:ss.dddddd # Added by buildout at YYYY-MM-DD hh:mm:ss.dddddd
...@@ -437,7 +437,7 @@ printing them to the console): ...@@ -437,7 +437,7 @@ printing them to the console):
The versions file contains the extra pin: The versions file contains the extra pin:
>>> print_(open('my_versions.cfg').read()) # doctest: +ELLIPSIS >>> with open('my_versions.cfg') as f: print_(f.read()) # doctest: +ELLIPSIS
<BLANKLINE> <BLANKLINE>
[versions] [versions]
... ...
......
...@@ -40,7 +40,7 @@ def rmtree (path): ...@@ -40,7 +40,7 @@ def rmtree (path):
Now create a file ... Now create a file ...
>>> foo = os.path.join (d, 'foo') >>> foo = os.path.join (d, 'foo')
>>> _ = open (foo, 'w').write ('huhu') >>> with open (foo, 'w') as f: _ = f.write ('huhu')
>>> bar = os.path.join (d, 'bar') >>> bar = os.path.join (d, 'bar')
>>> os.symlink(bar, bar) >>> os.symlink(bar, bar)
...@@ -107,4 +107,3 @@ def test_suite(): ...@@ -107,4 +107,3 @@ def test_suite():
if "__main__" == __name__: if "__main__" == __name__:
doctest.testmod() doctest.testmod()
...@@ -112,6 +112,19 @@ def system(command, input='', with_exit_code=False): ...@@ -112,6 +112,19 @@ def system(command, input='', with_exit_code=False):
# https://github.com/buildout/buildout/pull/311 # https://github.com/buildout/buildout/pull/311
# http://bugs.python.org/issue19884 # http://bugs.python.org/issue19884
env = dict(os.environ, TERM='dumb') env = dict(os.environ, TERM='dumb')
# Beginning in Python 3.4, 'U' mode to open() is deprecated.
# Python 3.7 changes the way deprecations are shown for main
# modules, and introduces $PYTHONDEVMODE which turns on warnigs in
# more places. If that's done, this leads many of our doctests to
# break; some code path through executing setup.py does this, but
# it's not in our code. Unfortunately, normalizing this printed
# line away doesn't work, it just produces a blank line. We resort
# to turning that warning off.
warnings = env.get('PYTHONWARNINGS', '')
env['PYTHONWARNINGS'] = "ignore:'U' mode is deprecated:DeprecationWarning::," + warnings
p = subprocess.Popen(command, p = subprocess.Popen(command,
shell=True, shell=True,
stdin=subprocess.PIPE, stdin=subprocess.PIPE,
...@@ -131,6 +144,7 @@ def system(command, input='', with_exit_code=False): ...@@ -131,6 +144,7 @@ def system(command, input='', with_exit_code=False):
# Use the with_exit_code=True parameter when you want to test the exit # Use the with_exit_code=True parameter when you want to test the exit
# code of the command you're running. # code of the command you're running.
output += 'EXIT CODE: %s' % p.wait() output += 'EXIT CODE: %s' % p.wait()
p.wait()
return output return output
def get(url): def get(url):
...@@ -293,6 +307,7 @@ def buildoutSetUp(test): ...@@ -293,6 +307,7 @@ def buildoutSetUp(test):
sdist = sdist, sdist = sdist,
bdist_egg = bdist_egg, bdist_egg = bdist_egg,
start_server = start_server, start_server = start_server,
stop_server = stop_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_, print_ = print_,
...@@ -330,6 +345,7 @@ class Handler(BaseHTTPRequestHandler): ...@@ -330,6 +345,7 @@ class Handler(BaseHTTPRequestHandler):
def do_GET(self): def do_GET(self):
if '__stop__' in self.path: if '__stop__' in self.path:
self.__server.server_close()
raise SystemExit raise SystemExit
def k(): def k():
...@@ -401,6 +417,7 @@ def _run(tree, port): ...@@ -401,6 +417,7 @@ def _run(tree, port):
server_address = ('localhost', port) server_address = ('localhost', port)
httpd = Server(tree, server_address, Handler) httpd = Server(tree, server_address, Handler)
httpd.serve_forever() httpd.serve_forever()
httpd.server_close()
def get_port(): def get_port():
for i in range(10): for i in range(10):
...@@ -513,10 +530,10 @@ if sys.version_info > (2, ): ...@@ -513,10 +530,10 @@ if sys.version_info > (2, ):
re.compile('(\n?)d __pycache__\n'), '\\1') re.compile('(\n?)d __pycache__\n'), '\\1')
else: else:
normalize___pycache__ = ( normalize___pycache__ = (
re.compile('(\n?)- \S+\.pyc\n'), '\\1') re.compile(r'(\n?)- \S+\.pyc\n'), '\\1')
normalize_egg_py = ( normalize_egg_py = (
re.compile('-py\d[.]\d(-\S+)?.egg'), re.compile(r'-py\d[.]\d(-\S+)?.egg'),
'-pyN.N.egg', '-pyN.N.egg',
) )
......
...@@ -275,9 +275,10 @@ setup(name=%r, version=%r, ...@@ -275,9 +275,10 @@ setup(name=%r, version=%r,
def make_dist_that_requires(dest, name, requires=[], version=1, egg=''): def make_dist_that_requires(dest, name, requires=[], version=1, egg=''):
os.mkdir(os.path.join(dest, name)) os.mkdir(os.path.join(dest, name))
open(os.path.join(dest, name, 'setup.py'), 'w').write( with open(os.path.join(dest, name, 'setup.py'), 'w') as f:
make_dist_that_requires_setup_py_template f.write(
% (name, version, requires) make_dist_that_requires_setup_py_template
% (name, version, requires)
) )
def show_who_requires_when_there_is_a_conflict(): def show_who_requires_when_there_is_a_conflict():
...@@ -511,7 +512,7 @@ the comparison with the saved value works correctly. ...@@ -511,7 +512,7 @@ the comparison with the saved value works correctly.
... options['format'] = '%3d' ... options['format'] = '%3d'
... ...
... def install(self): ... def install(self):
... open('t', 'w').write('t') ... with open('t', 'w') as f: f.write('t')
... return 't' ... return 't'
... ...
... update = install ... update = install
...@@ -1850,6 +1851,7 @@ if sys.version_info > (2, 4): ...@@ -1850,6 +1851,7 @@ if sys.version_info > (2, 4):
... p.stdin.close() ... p.stdin.close()
... print_(p.stdout.read().decode()) ... print_(p.stdout.read().decode())
... print_('Exit:', bool(p.wait())) ... print_('Exit:', bool(p.wait()))
... p.stdout.close()
>>> call(buildout) >>> call(buildout)
<BLANKLINE> <BLANKLINE>
...@@ -2259,11 +2261,12 @@ def create_egg(name, version, dest, install_requires=None, ...@@ -2259,11 +2261,12 @@ def create_egg(name, version, dest, install_requires=None,
else: else:
requires = '' requires = ''
try: try:
open(os.path.join(d, 'setup.py'), 'w').write( with open(os.path.join(d, 'setup.py'), 'w') as f:
'from setuptools import setup\n' f.write(
'setup(name=%r, version=%r, extras_require=%r, zip_safe=True,\n' 'from setuptools import setup\n'
' %s %s py_modules=["setup"]\n)' 'setup(name=%r, version=%r, extras_require=%r, zip_safe=True,\n'
% (name, str(version), extras, requires, links) ' %s %s py_modules=["setup"]\n)'
% (name, str(version), extras, requires, links)
) )
zc.buildout.testing.bdist_egg(d, sys.executable, os.path.abspath(dest)) zc.buildout.testing.bdist_egg(d, sys.executable, os.path.abspath(dest))
finally: finally:
...@@ -2709,7 +2712,8 @@ def make_sure_versions_dont_cancel_extras(): ...@@ -2709,7 +2712,8 @@ def make_sure_versions_dont_cancel_extras():
""" """
There was a bug that caused extras in requirements to be lost. There was a bug that caused extras in requirements to be lost.
>>> _ = open('setup.py', 'w').write(''' >>> with open('setup.py', 'w') as f:
... _ = f.write('''
... from setuptools import setup ... from setuptools import setup
... setup(name='extraversiondemo', version='1.0', ... setup(name='extraversiondemo', version='1.0',
... url='x', author='x', author_email='x', ... url='x', author='x', author_email='x',
...@@ -3449,7 +3453,7 @@ def buildout_txt_setup(test): ...@@ -3449,7 +3453,7 @@ def buildout_txt_setup(test):
os.path.join(eggs, 'zc.recipe.egg'), os.path.join(eggs, 'zc.recipe.egg'),
) )
egg_parse = re.compile('([0-9a-zA-Z_.]+)-([0-9a-zA-Z_.+]+)-py(\d[.]\d).egg$' egg_parse = re.compile(r'([0-9a-zA-Z_.]+)-([0-9a-zA-Z_.+]+)-py(\d[.]\d).egg$'
).match ).match
def makeNewRelease(project, ws, dest, version='99.99'): def makeNewRelease(project, ws, dest, version='99.99'):
dist = ws.find(pkg_resources.Requirement.parse(project)) dist = ws.find(pkg_resources.Requirement.parse(project))
...@@ -3471,9 +3475,11 @@ def makeNewRelease(project, ws, dest, version='99.99'): ...@@ -3471,9 +3475,11 @@ def makeNewRelease(project, ws, dest, version='99.99'):
else: else:
shutil.copytree(dist.location, dest) shutil.copytree(dist.location, dest)
info_path = os.path.join(dest, 'EGG-INFO', 'PKG-INFO') info_path = os.path.join(dest, 'EGG-INFO', 'PKG-INFO')
info = open(info_path).read().replace("Version: %s" % oldver, with open(info_path) as f:
"Version: %s" % version) info = f.read().replace("Version: %s" % oldver,
open(info_path, 'w').write(info) "Version: %s" % version)
with open(info_path, 'w') as f:
f.write(info)
def getWorkingSetWithBuildoutEgg(test): def getWorkingSetWithBuildoutEgg(test):
sample_buildout = test.globs['sample_buildout'] sample_buildout = test.globs['sample_buildout']
...@@ -3545,7 +3551,9 @@ normalize_S = ( ...@@ -3545,7 +3551,9 @@ normalize_S = (
'#!/usr/local/bin/python2.7', '#!/usr/local/bin/python2.7',
) )
def test_suite(): def test_suite():
test_suite = [ test_suite = [
manuel.testing.TestSuite( manuel.testing.TestSuite(
manuel.doctest.Manuel() + manuel.capture.Manuel(), manuel.doctest.Manuel() + manuel.capture.Manuel(),
...@@ -3561,17 +3569,17 @@ def test_suite(): ...@@ -3561,17 +3569,17 @@ def test_suite():
zc.buildout.testing.not_found, zc.buildout.testing.not_found,
zc.buildout.testing.adding_find_link, zc.buildout.testing.adding_find_link,
# (re.compile(r"Installing 'zc.buildout >=\S+"), ''), # (re.compile(r"Installing 'zc.buildout >=\S+"), ''),
(re.compile('__buildout_signature__ = recipes-\S+'), (re.compile(r'__buildout_signature__ = recipes-\S+'),
'__buildout_signature__ = recipes-SSSSSSSSSSS'), '__buildout_signature__ = recipes-SSSSSSSSSSS'),
(re.compile('executable = [\S ]+python\S*', re.I), (re.compile(r'executable = [\S ]+python\S*', re.I),
'executable = python'), 'executable = python'),
(re.compile('[-d] (setuptools|setuptools)-\S+[.]egg'), (re.compile(r'[-d] (setuptools|setuptools)-\S+[.]egg'),
'setuptools.egg'), 'setuptools.egg'),
(re.compile('zc.buildout(-\S+)?[.]egg(-link)?'), (re.compile(r'zc.buildout(-\S+)?[.]egg(-link)?'),
'zc.buildout.egg'), 'zc.buildout.egg'),
(re.compile('creating \S*setup.cfg'), 'creating setup.cfg'), (re.compile(r'creating \S*setup.cfg'), 'creating setup.cfg'),
(re.compile('hello\%ssetup' % os.path.sep), 'hello/setup'), (re.compile(r'hello\%ssetup' % os.path.sep), 'hello/setup'),
(re.compile('Picked: (\S+) = \S+'), (re.compile(r'Picked: (\S+) = \S+'),
'Picked: \\1 = V.V'), 'Picked: \\1 = V.V'),
(re.compile(r'We have a develop egg: zc.buildout (\S+)'), (re.compile(r'We have a develop egg: zc.buildout (\S+)'),
'We have a develop egg: zc.buildout X.X.'), 'We have a develop egg: zc.buildout X.X.'),
...@@ -3582,7 +3590,7 @@ def test_suite(): ...@@ -3582,7 +3590,7 @@ def test_suite():
'[Errno 17] File exists: ' '[Errno 17] File exists: '
), ),
(re.compile('setuptools'), 'setuptools'), (re.compile('setuptools'), 'setuptools'),
(re.compile('Got zc.recipe.egg \S+'), 'Got zc.recipe.egg'), (re.compile(r'Got zc.recipe.egg \S+'), 'Got zc.recipe.egg'),
(re.compile(r'zc\.(buildout|recipe\.egg)\s*= >=\S+'), (re.compile(r'zc\.(buildout|recipe\.egg)\s*= >=\S+'),
'zc.\1 = >=1.99'), 'zc.\1 = >=1.99'),
]) ])
...@@ -3606,20 +3614,20 @@ def test_suite(): ...@@ -3606,20 +3614,20 @@ def test_suite():
# (re.compile(r"Installing 'zc.buildout >=\S+"), ''), # (re.compile(r"Installing 'zc.buildout >=\S+"), ''),
# (re.compile(r"Getting distribution for 'zc.buildout >=\S+"), # (re.compile(r"Getting distribution for 'zc.buildout >=\S+"),
# ''), # ''),
(re.compile('__buildout_signature__ = recipes-\S+'), (re.compile(r'__buildout_signature__ = recipes-\S+'),
'__buildout_signature__ = recipes-SSSSSSSSSSS'), '__buildout_signature__ = recipes-SSSSSSSSSSS'),
(re.compile('[-d] setuptools-\S+[.]egg'), 'setuptools.egg'), (re.compile(r'[-d] setuptools-\S+[.]egg'), 'setuptools.egg'),
(re.compile('zc.buildout(-\S+)?[.]egg(-link)?'), (re.compile(r'zc.buildout(-\S+)?[.]egg(-link)?'),
'zc.buildout.egg'), 'zc.buildout.egg'),
(re.compile('creating \S*setup.cfg'), 'creating setup.cfg'), (re.compile(r'creating \S*setup.cfg'), 'creating setup.cfg'),
(re.compile('hello\%ssetup' % os.path.sep), 'hello/setup'), (re.compile(r'hello\%ssetup' % os.path.sep), 'hello/setup'),
(re.compile('Picked: (\S+) = \S+'), (re.compile(r'Picked: (\S+) = \S+'),
'Picked: \\1 = V.V'), 'Picked: \\1 = V.V'),
(re.compile(r'We have a develop egg: zc.buildout (\S+)'), (re.compile(r'We have a develop egg: zc.buildout (\S+)'),
'We have a develop egg: zc.buildout X.X.'), 'We have a develop egg: zc.buildout X.X.'),
(re.compile(r'\\[\\]?'), '/'), (re.compile(r'\\[\\]?'), '/'),
(re.compile('WindowsError'), 'OSError'), (re.compile(r'WindowsError'), 'OSError'),
(re.compile('setuptools = \S+'), 'setuptools = 0.7.99'), (re.compile(r'setuptools = \S+'), 'setuptools = 0.7.99'),
(re.compile(r'\[Error 17\] Cannot create a file ' (re.compile(r'\[Error 17\] Cannot create a file '
r'when that file already exists: '), r'when that file already exists: '),
'[Errno 17] File exists: ' '[Errno 17] File exists: '
...@@ -3655,7 +3663,7 @@ def test_suite(): ...@@ -3655,7 +3663,7 @@ def test_suite():
optionflags=doctest.NORMALIZE_WHITESPACE | doctest.ELLIPSIS, optionflags=doctest.NORMALIZE_WHITESPACE | doctest.ELLIPSIS,
checker=renormalizing.RENormalizing([ checker=renormalizing.RENormalizing([
(re.compile(r'(zc.buildout|setuptools)-\d+[.]\d+\S*' (re.compile(r'(zc.buildout|setuptools)-\d+[.]\d+\S*'
'-py\d.\d.egg'), r'-py\d.\d.egg'),
'\\1.egg'), '\\1.egg'),
zc.buildout.testing.normalize_path, zc.buildout.testing.normalize_path,
zc.buildout.testing.normalize_endings, zc.buildout.testing.normalize_endings,
...@@ -3694,7 +3702,7 @@ def test_suite(): ...@@ -3694,7 +3702,7 @@ def test_suite():
zc.buildout.testing.not_found, zc.buildout.testing.not_found,
normalize_bang, normalize_bang,
normalize_S, normalize_S,
(re.compile('[-d] setuptools-\S+[.]egg'), 'setuptools.egg'), (re.compile(r'[-d] setuptools-\S+[.]egg'), 'setuptools.egg'),
(re.compile(r'\\[\\]?'), '/'), (re.compile(r'\\[\\]?'), '/'),
(re.compile('(\n?)- ([a-zA-Z_.-]+)\n- \\2.exe\n'), (re.compile('(\n?)- ([a-zA-Z_.-]+)\n- \\2.exe\n'),
'\\1- \\2\n'), '\\1- \\2\n'),
...@@ -3739,18 +3747,18 @@ def test_suite(): ...@@ -3739,18 +3747,18 @@ def test_suite():
zc.buildout.testing.adding_find_link, zc.buildout.testing.adding_find_link,
normalize_bang, normalize_bang,
(re.compile(r'^(\w+\.)*(Missing\w+: )'), '\2'), (re.compile(r'^(\w+\.)*(Missing\w+: )'), '\2'),
(re.compile("buildout: Running \S*setup.py"), (re.compile(r"buildout: Running \S*setup.py"),
'buildout: Running setup.py'), 'buildout: Running setup.py'),
(re.compile('setuptools-\S+-'), (re.compile(r'setuptools-\S+-'),
'setuptools.egg'), 'setuptools.egg'),
(re.compile('zc.buildout-\S+-'), (re.compile(r'zc.buildout-\S+-'),
'zc.buildout.egg'), 'zc.buildout.egg'),
(re.compile('setuptools = \S+'), 'setuptools = 0.7.99'), (re.compile(r'setuptools = \S+'), 'setuptools = 0.7.99'),
(re.compile('File "\S+one.py"'), (re.compile(r'File "\S+one.py"'),
'File "one.py"'), 'File "one.py"'),
(re.compile(r'We have a develop egg: (\S+) (\S+)'), (re.compile(r'We have a develop egg: (\S+) (\S+)'),
r'We have a develop egg: \1 V'), r'We have a develop egg: \1 V'),
(re.compile('Picked: setuptools = \S+'), (re.compile(r'Picked: setuptools = \S+'),
'Picked: setuptools = V'), 'Picked: setuptools = V'),
(re.compile('[-d] setuptools'), '- setuptools'), (re.compile('[-d] setuptools'), '- setuptools'),
(re.compile(r'\\[\\]?'), '/'), (re.compile(r'\\[\\]?'), '/'),
...@@ -3784,14 +3792,14 @@ def test_suite(): ...@@ -3784,14 +3792,14 @@ def test_suite():
zc.buildout.testing.normalize_egg_py, zc.buildout.testing.normalize_egg_py,
zc.buildout.testing.not_found, zc.buildout.testing.not_found,
zc.buildout.testing.adding_find_link, zc.buildout.testing.adding_find_link,
(re.compile('__buildout_signature__ = recipes-\S+'), (re.compile(r'__buildout_signature__ = recipes-\S+'),
'__buildout_signature__ = recipes-SSSSSSSSSSS'), '__buildout_signature__ = recipes-SSSSSSSSSSS'),
(re.compile('[-d] setuptools-\S+[.]egg'), 'setuptools.egg'), (re.compile(r'[-d] setuptools-\S+[.]egg'), 'setuptools.egg'),
(re.compile('zc.buildout(-\S+)?[.]egg(-link)?'), (re.compile(r'zc.buildout(-\S+)?[.]egg(-link)?'),
'zc.buildout.egg'), 'zc.buildout.egg'),
(re.compile('creating \S*setup.cfg'), 'creating setup.cfg'), (re.compile(r'creating \S*setup.cfg'), 'creating setup.cfg'),
(re.compile('hello\%ssetup' % os.path.sep), 'hello/setup'), (re.compile(r'hello\%ssetup' % os.path.sep), 'hello/setup'),
(re.compile('Picked: (\S+) = \S+'), (re.compile(r'Picked: (\S+) = \S+'),
'Picked: \\1 = V.V'), 'Picked: \\1 = V.V'),
(re.compile(r'We have a develop egg: zc.buildout (\S+)'), (re.compile(r'We have a develop egg: zc.buildout (\S+)'),
'We have a develop egg: zc.buildout X.X.'), 'We have a develop egg: zc.buildout X.X.'),
......
...@@ -28,7 +28,7 @@ can't delete. ...@@ -28,7 +28,7 @@ can't delete.
... os.makedirs (self.location) ... os.makedirs (self.location)
... ...
... name = os.path.join (self.location, 'readonly.txt') ... name = os.path.join (self.location, 'readonly.txt')
... open (name, 'w').write ('this is a read only file') ... with open (name, 'w') as f: f.write ('this is a read only file')
... os.chmod(name, 256) ... os.chmod(name, 256)
... return () ... return ()
... ...
......
...@@ -7,7 +7,7 @@ commands = ...@@ -7,7 +7,7 @@ commands =
# buildout's dev.py wants python to not have setuptools # buildout's dev.py wants python to not have setuptools
pip uninstall -y zc.buildout setuptools pip pip uninstall -y zc.buildout setuptools pip
python dev.py python dev.py
{toxinidir}/bin/test -1 -v -c {toxinidir}/bin/test -1 -vvv -c
# since we're removing setuptools we can't possibly reuse the virtualenv # since we're removing setuptools we can't possibly reuse the virtualenv
recreate = true recreate = true
# if the user has ccache installed, PATH may contain /usr/lib/ccache that has a # if the user has ccache installed, PATH may contain /usr/lib/ccache that has a
......
...@@ -20,7 +20,8 @@ import os ...@@ -20,7 +20,8 @@ import os
from setuptools import setup, find_packages from setuptools import setup, find_packages
def read(*rnames): def read(*rnames):
return open(os.path.join(os.path.dirname(__file__), *rnames)).read() with open(os.path.join(os.path.dirname(__file__), *rnames)) as f:
return f.read()
name = "zc.recipe.egg" name = "zc.recipe.egg"
setup( setup(
......
...@@ -154,7 +154,7 @@ class Scripts(Eggs): ...@@ -154,7 +154,7 @@ class Scripts(Eggs):
assert relative_paths == 'false' assert relative_paths == 'false'
parse_entry_point = re.compile( parse_entry_point = re.compile(
'([^=]+)=(\w+(?:[.]\w+)*):(\w+(?:[.]\w+)*)$' r'([^=]+)=(\w+(?:[.]\w+)*):(\w+(?:[.]\w+)*)$'
).match ).match
def install(self): def install(self):
reqs, ws = self.working_set() reqs, ws = self.working_set()
......
...@@ -50,9 +50,9 @@ def test_suite(): ...@@ -50,9 +50,9 @@ def test_suite():
zc.buildout.tests.normalize_bang, zc.buildout.tests.normalize_bang,
zc.buildout.tests.normalize_S, zc.buildout.tests.normalize_S,
zc.buildout.testing.not_found, zc.buildout.testing.not_found,
(re.compile('[d-] zc.buildout(-\S+)?[.]egg(-link)?'), (re.compile(r'[d-] zc.buildout(-\S+)?[.]egg(-link)?'),
'zc.buildout.egg'), 'zc.buildout.egg'),
(re.compile('[d-] setuptools-[^-]+-'), 'setuptools-X-'), (re.compile(r'[d-] setuptools-[^-]+-'), 'setuptools-X-'),
(re.compile(r'eggs\\\\demo'), 'eggs/demo'), (re.compile(r'eggs\\\\demo'), 'eggs/demo'),
(re.compile(r'[a-zA-Z]:\\\\foo\\\\bar'), '/foo/bar'), (re.compile(r'[a-zA-Z]:\\\\foo\\\\bar'), '/foo/bar'),
]) ])
...@@ -66,15 +66,15 @@ def test_suite(): ...@@ -66,15 +66,15 @@ def test_suite():
zc.buildout.testing.normalize_endings, zc.buildout.testing.normalize_endings,
zc.buildout.testing.not_found, zc.buildout.testing.not_found,
(re.compile('__buildout_signature__ = ' (re.compile('__buildout_signature__ = '
'sample-\S+\s+' r'sample-\S+\s+'
'zc.recipe.egg-\S+\s+' r'zc.recipe.egg-\S+\s+'
'setuptools-\S+\s+' r'setuptools-\S+\s+'
'zc.buildout-\S+\s*' r'zc.buildout-\S+\s*'
), ),
'__buildout_signature__ = sample- zc.recipe.egg-'), '__buildout_signature__ = sample- zc.recipe.egg-'),
(re.compile('find-links = http://localhost:\d+/'), (re.compile(r'find-links = http://localhost:\d+/'),
'find-links = http://localhost:8080/'), 'find-links = http://localhost:8080/'),
(re.compile('index = http://localhost:\d+/index'), (re.compile(r'index = http://localhost:\d+/index'),
'index = http://localhost:8080/index'), 'index = http://localhost:8080/index'),
]) ])
), ),
...@@ -87,7 +87,7 @@ def test_suite(): ...@@ -87,7 +87,7 @@ def test_suite():
zc.buildout.testing.normalize_endings, zc.buildout.testing.normalize_endings,
zc.buildout.testing.not_found, zc.buildout.testing.not_found,
(re.compile("(d ((ext)?demo(needed)?|other)" (re.compile("(d ((ext)?demo(needed)?|other)"
"-\d[.]\d-py)\d[.]\d(-\S+)?[.]egg"), r"-\d[.]\d-py)\d[.]\d(-\S+)?[.]egg"),
'\\1V.V.egg'), '\\1V.V.egg'),
(re.compile('extdemo.c\n.+\\\\extdemo.exp\n'), ''), (re.compile('extdemo.c\n.+\\\\extdemo.exp\n'), ''),
(re.compile( (re.compile(
......
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