aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--CHANGES.txt4
-rw-r--r--distribute_setup.py9
-rw-r--r--pkg_resources.py61
-rwxr-xr-xsetuptools/command/develop.py4
-rwxr-xr-xsetuptools/command/easy_install.py2
-rwxr-xr-xsetuptools/command/upload.py5
-rw-r--r--setuptools/command/upload_docs.py4
-rw-r--r--setuptools/tests/doctest.py8
-rw-r--r--setuptools/tests/test_develop.py8
-rw-r--r--setuptools/tests/win_script_wrapper.txt28
10 files changed, 82 insertions, 51 deletions
diff --git a/CHANGES.txt b/CHANGES.txt
index 7c605c7e..ebc2bdcc 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -10,6 +10,10 @@ CHANGES
* Fix 1 failure with Jython 2.5 and 2.7.
* Disable workaround for Jython scripts on Linux systems.
* Issue #336: `setup.py` no longer masks failure exit code when tests fail.
+* Fix issue in pkg_resources where try/except around a platform-dependent
+ import would trigger hook load failures on Mercurial. See pull request 32
+ for details.
+* Issue #341: Fix a ResourceWarning.
------
0.6.32
diff --git a/distribute_setup.py b/distribute_setup.py
index f7954e84..23503c64 100644
--- a/distribute_setup.py
+++ b/distribute_setup.py
@@ -239,7 +239,9 @@ def _no_sandbox(function):
def _patch_file(path, content):
"""Will backup the file then patch it"""
- existing_content = open(path).read()
+ f = open(path)
+ existing_content = f.read()
+ f.close()
if existing_content == content:
# already patched
log.warn('Already patched.')
@@ -257,7 +259,10 @@ _patch_file = _no_sandbox(_patch_file)
def _same_content(path, content):
- return open(path).read() == content
+ f = open(path)
+ existing_content = f.read()
+ f.close()
+ return existing_content == content
def _rename_path(path):
diff --git a/pkg_resources.py b/pkg_resources.py
index a5a10eb4..cb8d3dcf 100644
--- a/pkg_resources.py
+++ b/pkg_resources.py
@@ -33,6 +33,12 @@ except ImportError:
from os import open as os_open
from os.path import isdir, split
+# Avoid try/except due to potential problems with delayed import mechanisms.
+if sys.version_info >= (3, 3) and sys.implementation.name == "cpython":
+ import importlib._bootstrap as importlib_bootstrap
+else:
+ importlib_bootstrap = None
+
# This marker is used to simplify the process that checks is the
# setuptools package was installed by the Setuptools project
# or by the Distribute project, in case Setuptools creates
@@ -1325,13 +1331,8 @@ class DefaultProvider(EggProvider):
register_loader_type(type(None), DefaultProvider)
-try:
- # CPython >=3.3
- import _frozen_importlib
-except ImportError:
- pass
-else:
- register_loader_type(_frozen_importlib.SourceFileLoader, DefaultProvider)
+if importlib_bootstrap is not None:
+ register_loader_type(importlib_bootstrap.SourceFileLoader, DefaultProvider)
class EmptyProvider(NullProvider):
@@ -1760,20 +1761,19 @@ def find_on_path(importer, path_item, only=False):
for dist in find_distributions(os.path.join(path_item, entry)):
yield dist
elif not only and lower.endswith('.egg-link'):
- for line in open(os.path.join(path_item, entry)):
- if not line.strip(): continue
- for item in find_distributions(os.path.join(path_item,line.rstrip())):
- yield item
- break
+ entry_file = open(os.path.join(path_item, entry))
+ try:
+ for line in entry_file:
+ if not line.strip(): continue
+ for item in find_distributions(os.path.join(path_item,line.rstrip())):
+ yield item
+ break
+ finally:
+ entry_file.close()
register_finder(ImpWrapper,find_on_path)
-try:
- # CPython >=3.3
- import _frozen_importlib
-except ImportError:
- pass
-else:
- register_finder(_frozen_importlib.FileFinder, find_on_path)
+if importlib_bootstrap is not None:
+ register_finder(importlib_bootstrap.FileFinder, find_on_path)
_declare_state('dict', _namespace_handlers={})
_declare_state('dict', _namespace_packages={})
@@ -1874,13 +1874,8 @@ def file_ns_handler(importer, path_item, packageName, module):
register_namespace_handler(ImpWrapper,file_ns_handler)
register_namespace_handler(zipimport.zipimporter,file_ns_handler)
-try:
- # CPython >=3.3
- import _frozen_importlib
-except ImportError:
- pass
-else:
- register_namespace_handler(_frozen_importlib.FileFinder, file_ns_handler)
+if importlib_bootstrap is not None:
+ register_namespace_handler(importlib_bootstrap.FileFinder, file_ns_handler)
def null_ns_handler(importer, path_item, packageName, module):
@@ -2120,7 +2115,7 @@ def _remove_md5_fragment(location):
class Distribution(object):
"""Wrap an actual or potential sys.path entry w/metadata"""
PKG_INFO = 'PKG-INFO'
-
+
def __init__(self,
location=None, metadata=None, project_name=None, version=None,
py_version=PY_MAJOR, platform=None, precedence = EGG_DIST
@@ -2459,7 +2454,7 @@ class DistInfoDistribution(Distribution):
from email.parser import Parser
self._pkg_info = Parser().parsestr(self.get_metadata(self.PKG_INFO))
return self._pkg_info
-
+
@property
def _dep_map(self):
try:
@@ -2470,7 +2465,7 @@ class DistInfoDistribution(Distribution):
def _preparse_requirement(self, requires_dist):
"""Convert 'Foobar (1); baz' to ('Foobar ==1', 'baz')
- Split environment marker, add == prefix to version specifiers as
+ Split environment marker, add == prefix to version specifiers as
necessary, and remove parenthesis.
"""
parts = requires_dist.split(';', 1) + ['']
@@ -2479,7 +2474,7 @@ class DistInfoDistribution(Distribution):
distvers = re.sub(self.EQEQ, r"\1==\2\3", distvers)
distvers = distvers.replace('(', '').replace(')', '')
return (distvers, mark)
-
+
def _compute_dependencies(self):
"""Recompute this distribution's dependencies."""
from _markerlib import compile as compile_marker
@@ -2492,7 +2487,7 @@ class DistInfoDistribution(Distribution):
parsed = parse_requirements(distvers).next()
parsed.marker_fn = compile_marker(mark)
reqs.append(parsed)
-
+
def reqs_for_extra(extra):
for req in reqs:
if req.marker_fn(override={'extra':extra}):
@@ -2500,13 +2495,13 @@ class DistInfoDistribution(Distribution):
common = frozenset(reqs_for_extra(None))
dm[None].extend(common)
-
+
for extra in self._parsed_pkg_info.get_all('Provides-Extra') or []:
extra = safe_extra(extra.strip())
dm[extra] = list(frozenset(reqs_for_extra(extra)) - common)
return dm
-
+
_distributionImpl = {'.egg': Distribution,
'.egg-info': Distribution,
diff --git a/setuptools/command/develop.py b/setuptools/command/develop.py
index 709e349c..1d500040 100755
--- a/setuptools/command/develop.py
+++ b/setuptools/command/develop.py
@@ -132,7 +132,9 @@ class develop(easy_install):
def uninstall_link(self):
if os.path.exists(self.egg_link):
log.info("Removing %s (link to %s)", self.egg_link, self.egg_base)
- contents = [line.rstrip() for line in open(self.egg_link)]
+ egg_link_file = open(self.egg_link)
+ contents = [line.rstrip() for line in egg_link_file]
+ egg_link_file.close()
if contents not in ([self.egg_path], [self.egg_path, self.setup_path]):
log.warn("Link points to %s: uninstall aborted", contents)
return
diff --git a/setuptools/command/easy_install.py b/setuptools/command/easy_install.py
index cb911173..0d72f758 100755
--- a/setuptools/command/easy_install.py
+++ b/setuptools/command/easy_install.py
@@ -491,7 +491,7 @@ Please make the appropriate changes for your system and try again.
self.cant_write_to_target()
else:
try:
- f.write("import os;open(%r,'w').write('OK')\n" % (ok_file,))
+ f.write("import os; f = open(%r, 'w'); f.write('OK'); f.close()\n" % (ok_file,))
f.close(); f=None
executable = sys.executable
if os.name=='nt':
diff --git a/setuptools/command/upload.py b/setuptools/command/upload.py
index 9f9366b5..21b9615c 100755
--- a/setuptools/command/upload.py
+++ b/setuptools/command/upload.py
@@ -109,8 +109,9 @@ class upload(Command):
data['comment'] = comment
if self.sign:
- data['gpg_signature'] = (os.path.basename(filename) + ".asc",
- open(filename+".asc").read())
+ asc_file = open(filename + ".asc")
+ data['gpg_signature'] = (os.path.basename(filename) + ".asc", asc_file.read())
+ asc_file.close()
# set up the authentication
auth = "Basic " + base64.encodestring(self.username + ":" + self.password).strip()
diff --git a/setuptools/command/upload_docs.py b/setuptools/command/upload_docs.py
index 98fb7233..1d5a7445 100644
--- a/setuptools/command/upload_docs.py
+++ b/setuptools/command/upload_docs.py
@@ -105,7 +105,9 @@ class upload_docs(upload):
shutil.rmtree(tmp_dir)
def upload_file(self, filename):
- content = open(filename, 'rb').read()
+ f = open(filename, 'rb')
+ content = f.read()
+ f.close()
meta = self.distribution.metadata
data = {
':action': 'doc_upload',
diff --git a/setuptools/tests/doctest.py b/setuptools/tests/doctest.py
index be399a9d..cc1e06c3 100644
--- a/setuptools/tests/doctest.py
+++ b/setuptools/tests/doctest.py
@@ -1968,7 +1968,9 @@ def testfile(filename, module_relative=True, name=None, package=None,
runner = DocTestRunner(verbose=verbose, optionflags=optionflags)
# Read the file, convert it to a test, and run it.
- s = open(filename).read()
+ f = open(filename)
+ s = f.read()
+ f.close()
test = parser.get_doctest(s, globs, name, filename, 0)
runner.run(test)
@@ -2353,7 +2355,9 @@ def DocFileTest(path, module_relative=True, package=None,
# Find the file and read it.
name = os.path.basename(path)
- doc = open(path).read()
+ f = open(path)
+ doc = f.read()
+ f.close()
# Convert it to a test, and wrap it in a DocFileCase.
test = parser.get_doctest(doc, globs, name, path, 0)
diff --git a/setuptools/tests/test_develop.py b/setuptools/tests/test_develop.py
index 3e071dad..315058c5 100644
--- a/setuptools/tests/test_develop.py
+++ b/setuptools/tests/test_develop.py
@@ -89,8 +89,12 @@ class TestDevelopTest(unittest.TestCase):
self.assertEqual(content, ['easy-install.pth', 'foo.egg-link'])
# Check that we are using the right code.
- path = open(os.path.join(site.USER_SITE, 'foo.egg-link'), 'rt').read().split()[0].strip()
- init = open(os.path.join(path, 'foo', '__init__.py'), 'rt').read().strip()
+ egg_link_file = open(os.path.join(site.USER_SITE, 'foo.egg-link'), 'rt')
+ path = egg_link_file.read().split()[0].strip()
+ egg_link_file.close()
+ init_file = open(os.path.join(path, 'foo', '__init__.py'), 'rt')
+ init = init_file.read().strip()
+ init_file.close()
if sys.version < "3":
self.assertEqual(init, 'print "foo"')
else:
diff --git a/setuptools/tests/win_script_wrapper.txt b/setuptools/tests/win_script_wrapper.txt
index 2e1bff74..9f7c81d6 100644
--- a/setuptools/tests/win_script_wrapper.txt
+++ b/setuptools/tests/win_script_wrapper.txt
@@ -16,7 +16,8 @@ Let's create a simple script, foo-script.py:
>>> import os, sys, tempfile
>>> from setuptools.command.easy_install import nt_quote_arg
>>> sample_directory = tempfile.mkdtemp()
- >>> open(os.path.join(sample_directory, 'foo-script.py'), 'w').write(
+ >>> f = open(os.path.join(sample_directory, 'foo-script.py'), 'w')
+ >>> f.write(
... """#!%(python_exe)s
... import sys
... input = repr(sys.stdin.read())
@@ -26,6 +27,7 @@ Let's create a simple script, foo-script.py:
... if __debug__:
... print 'non-optimized'
... """ % dict(python_exe=nt_quote_arg(sys.executable)))
+ >>> f.close()
Note that the script starts with a Unix-style '#!' line saying which
Python executable to run. The wrapper will use this to find the
@@ -34,9 +36,11 @@ correct Python executable.
We'll also copy cli.exe to the sample-directory with the name foo.exe:
>>> import pkg_resources
- >>> open(os.path.join(sample_directory, 'foo.exe'), 'wb').write(
+ >>> f = open(os.path.join(sample_directory, 'foo.exe'), 'wb')
+ >>> f.write(
... pkg_resources.resource_string('setuptools', 'cli.exe')
... )
+ >>> f.close()
When the copy of cli.exe, foo.exe in this example, runs, it examines
the path name it was run with and computes a Python script path name
@@ -77,7 +81,8 @@ to start the interactive interpreter. You can combine multiple
options as usual. For example, to run in optimized mode and
enter the interpreter after running the script, you could use -Oi:
- >>> open(os.path.join(sample_directory, 'foo-script.py'), 'w').write(
+ >>> f = open(os.path.join(sample_directory, 'foo-script.py'), 'w')
+ >>> f.write(
... """#!%(python_exe)s -Oi
... import sys
... input = repr(sys.stdin.read())
@@ -88,6 +93,7 @@ enter the interpreter after running the script, you could use -Oi:
... print 'non-optimized'
... sys.ps1 = '---'
... """ % dict(python_exe=nt_quote_arg(sys.executable)))
+ >>> f.close()
>>> input, output = os.popen4(nt_quote_arg(os.path.join(sample_directory, 'foo.exe')))
>>> input.close()
@@ -105,18 +111,24 @@ Now let's test the GUI version with the simple scipt, bar-script.py:
>>> import os, sys, tempfile
>>> from setuptools.command.easy_install import nt_quote_arg
>>> sample_directory = tempfile.mkdtemp()
- >>> open(os.path.join(sample_directory, 'bar-script.pyw'), 'w').write(
+ >>> f = open(os.path.join(sample_directory, 'bar-script.pyw'), 'w')
+ >>> f.write(
... """#!%(python_exe)s
... import sys
- ... open(sys.argv[1], 'wb').write(repr(sys.argv[2]))
+ ... f = open(sys.argv[1], 'wb')
+ ... f.write(repr(sys.argv[2]))
+ ... f.close()
... """ % dict(python_exe=nt_quote_arg(sys.executable)))
+ >>> f.close()
We'll also copy gui.exe to the sample-directory with the name bar.exe:
>>> import pkg_resources
- >>> open(os.path.join(sample_directory, 'bar.exe'), 'wb').write(
+ >>> f = open(os.path.join(sample_directory, 'bar.exe'), 'wb')
+ >>> f.write(
... pkg_resources.resource_string('setuptools', 'gui.exe')
... )
+ >>> f.close()
Finally, we'll run the script and check the result:
@@ -126,8 +138,10 @@ Finally, we'll run the script and check the result:
>>> input.close()
>>> print output.read()
<BLANKLINE>
- >>> print open(os.path.join(sample_directory, 'test_output.txt'), 'rb').read()
+ >>> f = open(os.path.join(sample_directory, 'test_output.txt'), 'rb')
+ >>> print f.read()
'Test Argument'
+ >>> f.close()
We're done with the sample_directory: