Skip to content

Commit

Permalink
Merge pull request #459 from NextThought/fix-warnings
Browse files Browse the repository at this point in the history
Fix most Deprecation and Resource warnings.
  • Loading branch information
reinout committed Jul 3, 2018
2 parents c6e878a + f158937 commit c8f0236
Show file tree
Hide file tree
Showing 20 changed files with 147 additions and 117 deletions.
2 changes: 1 addition & 1 deletion Makefile
Expand Up @@ -51,4 +51,4 @@ clean:
rm -rf $(BUILD_DIRS) $(PYTHON_BUILD_DIR)

test:
$(HERE)/bin/test -1 -vvv
$(HERE)/bin/test -1 -vvv -c
5 changes: 4 additions & 1 deletion doc/topics/bootstrapping.rst
Expand Up @@ -97,6 +97,8 @@ And then run it:
>>> eqs(os.listdir("."), 'bootstrap-buildout.py',
... 'buildout.cfg', 'eggs', 'bin', 'develop-eggs', 'parts')
>>> os.chdir('..')
>>> p.stdout.close()
>>> p.stderr.close()
It will download the software needed to run Buildout and install it in
the current directory.
Expand Down Expand Up @@ -167,6 +169,8 @@ This can be used with the bootstrapping script as well:
... print(p.stderr.read())
>>> eqs(os.listdir("."), 'bootstrap-buildout.py',
... 'buildout.cfg', 'eggs', 'bin', 'develop-eggs', 'parts')
>>> p.stdout.close()
>>> p.stderr.close()
This creates an empty Buildout configuration:

Expand Down Expand Up @@ -220,4 +224,3 @@ command above would generate a buildout configuration file:
This can provide an easy way to experiment with a package without
adding it to your Python environment or creating a virtualenv.

3 changes: 2 additions & 1 deletion setup.py
Expand Up @@ -18,7 +18,8 @@
from setuptools import setup

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()

long_description= read('README.rst') + '\n' + read('CHANGES.rst')

Expand Down
14 changes: 8 additions & 6 deletions src/zc/buildout/bootstrap.txt
Expand Up @@ -19,7 +19,9 @@ Make sure the bootstrap script actually works::
... [buildout]
... 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(
... zc.buildout.easy_install._safe_arg(sys.executable)+' '+
... 'bootstrap.py')); print_('X') # doctest: +ELLIPSIS
Expand Down Expand Up @@ -52,7 +54,7 @@ By default it gets the latest version::
>>> buildout_script = join(sample_buildout, 'bin', 'buildout')
>>> if sys.platform.startswith('win'):
... 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] = [
'/sample/eggs/zc.buildout-22.0.0...egg',
Expand Down Expand Up @@ -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::

>>> print_(open(buildout_script).read()) # doctest: +ELLIPSIS
>>> with open(buildout_script) as f: print_(f.read()) # doctest: +ELLIPSIS
#...
sys.path[0:0] = [
'/sample/eggs/zc.buildout-2.0.0...egg',
Expand All @@ -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::

>>> print_(open(buildout_script).read()) # doctest: +ELLIPSIS
>>> with open(buildout_script) as f: print_(f.read()) # doctest: +ELLIPSIS
#...
sys.path[0:0] = [
'/sample/eggs/zc.buildout-...egg',
Expand All @@ -121,7 +123,7 @@ which happens to exist::

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] = [
'/sample/eggs/zc.buildout-2.0.0...egg',
Expand Down Expand Up @@ -153,7 +155,7 @@ specify the setuptools version, and to reuse the setuptools zipfile::
>>> os.path.exists('setuptools-32.1.0.zip')
True

>>> print_(open(buildout_script).read()) # doctest: +ELLIPSIS
>>> with open(buildout_script) as f: print_(f.read()) # doctest: +ELLIPSIS
#...
sys.path[0:0] = [
'/sample/eggs/zc.buildout-2.0.0...egg',
Expand Down
6 changes: 4 additions & 2 deletions src/zc/buildout/bootstrap_cl_settings.test
Expand Up @@ -20,7 +20,8 @@ Some people pass buildout settings to bootstrap.
... [buildout]
... 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(
... zc.buildout.easy_install._safe_arg(sys.executable) +
... ' bootstrap.py buildout:directory=' + top +
Expand All @@ -43,7 +44,8 @@ They might do it with init, but no worries:
>>> os.chdir(top)
>>> mkdir(top, 'buildout')
>>> 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(
... zc.buildout.easy_install._safe_arg(sys.executable) +
... ' bootstrap.py buildout:directory=' + top +
Expand Down
18 changes: 9 additions & 9 deletions src/zc/buildout/buildout.py
Expand Up @@ -893,8 +893,8 @@ def _develop(self):
setup = self._buildout_path(setup)
files = glob.glob(setup)
if not files:
self._logger.warn("Couldn't develop %r (not found)",
setup)
self._logger.warning("Couldn't develop %r (not found)",
setup)
else:
files.sort()
for setup in files:
Expand Down Expand Up @@ -1108,8 +1108,8 @@ def _maybe_upgrade(self):
if (realpath(os.path.abspath(sys.argv[0])) != should_run):
self._logger.debug("Running %r.", realpath(sys.argv[0]))
self._logger.debug("Local buildout is %r.", should_run)
self._logger.warn("Not upgrading because not running a local "
"buildout command.")
self._logger.warning("Not upgrading because not running a local "
"buildout command.")
return

self._logger.info("Upgraded:\n %s;\nrestarting.",
Expand Down Expand Up @@ -1464,7 +1464,7 @@ def get(self, option, default=None, seen=None):

_template_split = re.compile('([$]{[^}]*})').split
_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):
value = self._template_split(template)
subs = []
Expand Down Expand Up @@ -1563,7 +1563,7 @@ def _call(self, f):
elif os.path.isfile(p):
os.remove(p)
else:
self.buildout._logger.warn("Couldn't clean up %r.", p)
self.buildout._logger.warning("Couldn't clean up %r.", p)
raise
finally:
self._created = None
Expand Down Expand Up @@ -1921,9 +1921,9 @@ def _check_for_unused_options_in_section(buildout, section):
unused = [option for option in sorted(options._raw)
if option not in options._data]
if unused:
buildout._logger.warn("Unused options for %s: %s."
% (section, ' '.join(map(repr, unused)))
)
buildout._logger.warning("Unused options for %s: %s."
% (section, ' '.join(map(repr, unused)))
)

_usage = """\
Usage: buildout [options] [assignments] [command [command arguments]]
Expand Down
4 changes: 4 additions & 0 deletions src/zc/buildout/buildout.txt
Expand Up @@ -3355,3 +3355,7 @@ We see that our extension is loaded and executed::
ext ['buildout', 'versions']
Develop: '/sample-bootstrapped/demo'
unload ['buildout', 'versions']

..

>>> stop_server(server_url)
2 changes: 1 addition & 1 deletion src/zc/buildout/configparser.py
Expand Up @@ -178,7 +178,7 @@ def parse(fp, fpname, exp_globals=dict):
tail = tail.replace(';', '#') if tail else ''
# un-escape literal # and ; . Do not use a
# 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
expr = head + expr + tail
# lazily populate context only expression
Expand Down
48 changes: 24 additions & 24 deletions src/zc/buildout/configparser.test
Expand Up @@ -33,7 +33,7 @@ First, an example that illustrates a well-formed configuration::
b += 1

[s3]; comment
x = a b
x = a b

.. -> text

Expand Down Expand Up @@ -92,9 +92,9 @@ otherwise empty section) is blank. For example:"
'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.
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::

[s1: 2 + 2 == 4] # this expression is true [therefore "this section" _will_ be NOT skipped
Expand All @@ -106,7 +106,7 @@ conditional exclusion of sections::
[ s2 : 41 + 1 == 42 ] # a comment: this expression is [true], so this section will be kept
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
long = c

Expand All @@ -117,11 +117,11 @@ conditional exclusion of sections::


Title line optional trailing comments are separated by a hash '#' or semicolon
';' character. The expression is an arbitrary expression with one restriction:
it cannot contain a literal hash '#' or semicolon ';' character: these need to be
';' character. The expression is an arbitrary expression with one restriction:
it cannot contain a literal hash '#' or semicolon ';' character: these need to be
string-escaped.
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
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
some cases. For example, valid sections lines include::

[ a ]
Expand Down Expand Up @@ -170,7 +170,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::

[ a ] ;semicolon comment are supported for lines without expressions ]
Expand Down Expand Up @@ -226,10 +226,10 @@ The following sections with hash comment separators are valid too::
'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
semicolon ';' would be needed in an expression literal, you can use the
string-escaped representation of these characters: use '\x23' for hash '#' and
semicolon ';' would be needed in an expression literal, you can use the
string-escaped representation of these characters: use '\x23' for hash '#' and
'\x3b' for semicolon ';' to avoid evaluation errors.
These expressions are valid and use escaped hash and semicolons in literals::

Expand All @@ -256,11 +256,11 @@ And using unescaped semicolon and hash characters in expressions triggers an err
... except zc.buildout.configparser.MissingSectionHeaderError: pass # success


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
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
the platform and sys modules to the evaluation context, so we can access
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
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
the platform and sys modules to the evaluation context, so we can access
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
Expand All @@ -280,8 +280,8 @@ platform and sys modules functions and objects in our expressions ::
{'s1': {'a': '1'}, 's2': {'long': 'b'}}


Some limited (but hopefully sane and sufficient) default modules and
pre-computed common expressions available to an expression when the parser in
Some limited (but hopefully sane and sufficient) default modules and
pre-computed common expressions available to an expression when the parser in
called by buildout::


Expand All @@ -290,20 +290,20 @@ called by buildout::
a = 1

# 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
[s2: any([python2, python3, python24 , python25 , python26 , python27 , python30 , python31 , python32 , python33 , python34 , python35 , python36]) ]
# 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]) ]
b = 1

# 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
c = 1
c = 1

# 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

# 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

.. -> text
Expand Down
9 changes: 1 addition & 8 deletions src/zc/buildout/download.py
Expand Up @@ -20,15 +20,8 @@

try:
# Python 3
from urllib.request import FancyURLopener, URLopener, urlretrieve
from urllib.request import urlretrieve
from urllib.parse import urlparse
from urllib import request

class PatchedURLopener(FancyURLopener):
http_error_default = URLopener.http_error_default

request._urlopener = PatchedURLopener() # Ook! Monkey patch!

except ImportError:
# Python 2
import base64
Expand Down
2 changes: 1 addition & 1 deletion src/zc/buildout/easy_install.py
Expand Up @@ -637,7 +637,7 @@ def _maybe_add_setuptools(self, ws, dist):
if dist_needs_pkg_resources(dist):
# We have a namespace package but no requirement for setuptools
if dist.precedence == pkg_resources.DEVELOP_DIST:
logger.warn(
logger.warning(
"Develop distribution: %s\n"
"uses namespace packages but the distribution "
"does not require setuptools.",
Expand Down
4 changes: 2 additions & 2 deletions src/zc/buildout/repeatable.txt
Expand Up @@ -397,7 +397,7 @@ at the end.

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>
...
# Added by buildout at YYYY-MM-DD hh:mm:ss.dddddd
Expand Down Expand Up @@ -437,7 +437,7 @@ printing them to the console):

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>
[versions]
...
Expand Down
3 changes: 1 addition & 2 deletions src/zc/buildout/rmtree.py
Expand Up @@ -40,7 +40,7 @@ def rmtree (path):
Now create a file ...
>>> foo = os.path.join (d, 'foo')
>>> _ = open (foo, 'w').write ('huhu')
>>> with open (foo, 'w') as f: _ = f.write ('huhu')
and make it unwriteable
Expand Down Expand Up @@ -75,4 +75,3 @@ def test_suite():

if "__main__" == __name__:
doctest.testmod()

0 comments on commit c8f0236

Please sign in to comment.