diff options
-rw-r--r-- | .hgignore | 1 | ||||
-rw-r--r-- | docs/conf.py | 8 | ||||
-rw-r--r-- | pkg_resources.py | 9 | ||||
-rw-r--r-- | setuptools.egg-info/entry_points.txt | 124 | ||||
-rw-r--r-- | setuptools.egg-info/requires.txt | 5 | ||||
-rwxr-xr-x | setuptools/command/easy_install.py | 8 | ||||
-rwxr-xr-x | setuptools/command/egg_info.py | 6 | ||||
-rwxr-xr-x | setuptools/command/install_egg_info.py | 1 | ||||
-rw-r--r-- | setuptools/command/test.py | 2 | ||||
-rw-r--r-- | setuptools/command/upload_docs.py | 12 | ||||
-rw-r--r-- | setuptools/compat.py | 4 | ||||
-rw-r--r-- | setuptools/extension.py | 2 | ||||
-rwxr-xr-x | setuptools/package_index.py | 14 | ||||
-rwxr-xr-x | setuptools/sandbox.py | 3 | ||||
-rw-r--r-- | setuptools/script template (dev).py | 5 | ||||
-rw-r--r-- | setuptools/ssl_support.py | 5 | ||||
-rw-r--r-- | setuptools/tests/__init__.py | 3 | ||||
-rw-r--r-- | setuptools/tests/test_develop.py | 2 | ||||
-rw-r--r-- | setuptools/tests/test_easy_install.py | 1 | ||||
-rw-r--r-- | setuptools/tests/test_sdist.py | 5 | ||||
-rw-r--r-- | tests/test_pkg_resources.py | 107 |
21 files changed, 179 insertions, 148 deletions
@@ -4,6 +4,7 @@ syntax: glob *.swp .coverage distribute.egg-info +setuptools.egg-info build dist lib diff --git a/docs/conf.py b/docs/conf.py index d2e5276c..3fccd87f 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -40,8 +40,8 @@ source_suffix = '.txt' master_doc = 'index' # General information about the project. -project = u'Setuptools' -copyright = u'2009-2013, The fellowship of the packaging' +project = 'Setuptools' +copyright = '2009-2013, The fellowship of the packaging' # The version info for the project you're documenting, acts as replacement for # |version| and |release|, also used in various other places throughout the @@ -175,8 +175,8 @@ htmlhelp_basename = 'Setuptoolsdoc' # Grouping the document tree into LaTeX files. List of tuples # (source start file, target name, title, author, documentclass [howto/manual]). latex_documents = [ - ('index', 'Setuptools.tex', ur'Setuptools Documentation', - ur'The fellowship of the packaging', 'manual'), + ('index', 'Setuptools.tex', 'Setuptools Documentation', + 'The fellowship of the packaging', 'manual'), ] # The name of an image file (relative to this directory) to place at the top of diff --git a/pkg_resources.py b/pkg_resources.py index 4c2b9959..e03667e0 100644 --- a/pkg_resources.py +++ b/pkg_resources.py @@ -40,6 +40,7 @@ try: except NameError: basestring = str from io import StringIO + from functools import reduce exec_ = eval("exec") def execfile(fn, globs=None, locs=None): if globs is None: @@ -47,8 +48,6 @@ except NameError: if locs is None: locs = globs exec_(compile(open(fn).read(), fn, 'exec'), globs, locs) - import functools - reduce = functools.reduce # capture these to bypass sandboxing from os import utime @@ -2315,7 +2314,7 @@ class EntryPoint(object): def parse_map(cls, data, dist=None): """Parse a map of entry point groups""" if isinstance(data,dict): - data = list(data.items()) + data = data.items() else: data = split_sections(data) maps = {} @@ -2493,7 +2492,8 @@ class Distribution(object): self.insert_on(path) if path is sys.path: fixup_namespace_packages(self.location) - list(map(declare_namespace, self._get_metadata('namespace_packages.txt'))) + list(map(declare_namespace, + self._get_metadata('namespace_packages.txt'))) def egg_name(self): @@ -3009,4 +3009,3 @@ run_main = run_script # backward compatibility add_activation_listener(lambda dist: dist.activate()) working_set.entries=[]; list(map(working_set.add_entry,sys.path)) # match order - diff --git a/setuptools.egg-info/entry_points.txt b/setuptools.egg-info/entry_points.txt index 29654589..64d16767 100644 --- a/setuptools.egg-info/entry_points.txt +++ b/setuptools.egg-info/entry_points.txt @@ -1,62 +1,62 @@ -[distutils.commands]
-bdist_rpm = setuptools.command.bdist_rpm:bdist_rpm
-rotate = setuptools.command.rotate:rotate
-develop = setuptools.command.develop:develop
-setopt = setuptools.command.setopt:setopt
-build_py = setuptools.command.build_py:build_py
-saveopts = setuptools.command.saveopts:saveopts
-egg_info = setuptools.command.egg_info:egg_info
-register = setuptools.command.register:register
-upload_docs = setuptools.command.upload_docs:upload_docs
-install_egg_info = setuptools.command.install_egg_info:install_egg_info
-alias = setuptools.command.alias:alias
-easy_install = setuptools.command.easy_install:easy_install
-install_scripts = setuptools.command.install_scripts:install_scripts
-bdist_wininst = setuptools.command.bdist_wininst:bdist_wininst
-bdist_egg = setuptools.command.bdist_egg:bdist_egg
-install = setuptools.command.install:install
-test = setuptools.command.test:test
-install_lib = setuptools.command.install_lib:install_lib
-build_ext = setuptools.command.build_ext:build_ext
-sdist = setuptools.command.sdist:sdist
-
-[egg_info.writers]
-dependency_links.txt = setuptools.command.egg_info:overwrite_arg
-requires.txt = setuptools.command.egg_info:write_requirements
-PKG-INFO = setuptools.command.egg_info:write_pkg_info
-eager_resources.txt = setuptools.command.egg_info:overwrite_arg
-top_level.txt = setuptools.command.egg_info:write_toplevel_names
-namespace_packages.txt = setuptools.command.egg_info:overwrite_arg
-entry_points.txt = setuptools.command.egg_info:write_entries
-depends.txt = setuptools.command.egg_info:warn_depends_obsolete
-
-[console_scripts]
-easy_install = setuptools.command.easy_install:main
-easy_install-2.7 = setuptools.command.easy_install:main
-
-[setuptools.file_finders]
-svn_cvs = setuptools.command.sdist:_default_revctrl
-
-[distutils.setup_keywords]
-dependency_links = setuptools.dist:assert_string_list
-entry_points = setuptools.dist:check_entry_points
-extras_require = setuptools.dist:check_extras
-use_2to3_exclude_fixers = setuptools.dist:assert_string_list
-package_data = setuptools.dist:check_package_data
-install_requires = setuptools.dist:check_requirements
-use_2to3 = setuptools.dist:assert_bool
-use_2to3_fixers = setuptools.dist:assert_string_list
-include_package_data = setuptools.dist:assert_bool
-exclude_package_data = setuptools.dist:check_package_data
-namespace_packages = setuptools.dist:check_nsp
-test_suite = setuptools.dist:check_test_suite
-eager_resources = setuptools.dist:assert_string_list
-zip_safe = setuptools.dist:assert_bool
-test_loader = setuptools.dist:check_importable
-packages = setuptools.dist:check_packages
-convert_2to3_doctests = setuptools.dist:assert_string_list
-tests_require = setuptools.dist:check_requirements
-
-[setuptools.installation]
-eggsecutable = setuptools.command.easy_install:bootstrap
-
+[console_scripts] +easy_install = setuptools.command.easy_install:main +easy_install-3.3 = setuptools.command.easy_install:main + +[distutils.setup_keywords] +namespace_packages = setuptools.dist:check_nsp +use_2to3_exclude_fixers = setuptools.dist:assert_string_list +package_data = setuptools.dist:check_package_data +use_2to3 = setuptools.dist:assert_bool +install_requires = setuptools.dist:check_requirements +entry_points = setuptools.dist:check_entry_points +convert_2to3_doctests = setuptools.dist:assert_string_list +dependency_links = setuptools.dist:assert_string_list +test_suite = setuptools.dist:check_test_suite +test_loader = setuptools.dist:check_importable +tests_require = setuptools.dist:check_requirements +packages = setuptools.dist:check_packages +use_2to3_fixers = setuptools.dist:assert_string_list +extras_require = setuptools.dist:check_extras +include_package_data = setuptools.dist:assert_bool +eager_resources = setuptools.dist:assert_string_list +exclude_package_data = setuptools.dist:check_package_data +zip_safe = setuptools.dist:assert_bool + +[distutils.commands] +bdist_wininst = setuptools.command.bdist_wininst:bdist_wininst +test = setuptools.command.test:test +easy_install = setuptools.command.easy_install:easy_install +install_egg_info = setuptools.command.install_egg_info:install_egg_info +upload_docs = setuptools.command.upload_docs:upload_docs +setopt = setuptools.command.setopt:setopt +install = setuptools.command.install:install +bdist_egg = setuptools.command.bdist_egg:bdist_egg +alias = setuptools.command.alias:alias +saveopts = setuptools.command.saveopts:saveopts +sdist = setuptools.command.sdist:sdist +rotate = setuptools.command.rotate:rotate +develop = setuptools.command.develop:develop +install_lib = setuptools.command.install_lib:install_lib +register = setuptools.command.register:register +build_py = setuptools.command.build_py:build_py +install_scripts = setuptools.command.install_scripts:install_scripts +bdist_rpm = setuptools.command.bdist_rpm:bdist_rpm +egg_info = setuptools.command.egg_info:egg_info +build_ext = setuptools.command.build_ext:build_ext + +[setuptools.file_finders] +svn_cvs = setuptools.command.sdist:_default_revctrl + +[egg_info.writers] +requires.txt = setuptools.command.egg_info:write_requirements +namespace_packages.txt = setuptools.command.egg_info:overwrite_arg +entry_points.txt = setuptools.command.egg_info:write_entries +top_level.txt = setuptools.command.egg_info:write_toplevel_names +depends.txt = setuptools.command.egg_info:warn_depends_obsolete +PKG-INFO = setuptools.command.egg_info:write_pkg_info +eager_resources.txt = setuptools.command.egg_info:overwrite_arg +dependency_links.txt = setuptools.command.egg_info:overwrite_arg + +[setuptools.installation] +eggsecutable = setuptools.command.easy_install:bootstrap + diff --git a/setuptools.egg-info/requires.txt b/setuptools.egg-info/requires.txt index e4fb4954..77cddef2 100644 --- a/setuptools.egg-info/requires.txt +++ b/setuptools.egg-info/requires.txt @@ -10,4 +10,7 @@ wincertstore==0.1 certifi==0.0.8 [ssl:python_version in '2.4, 2.5'] -ssl==1.16
\ No newline at end of file +ssl==1.16 + +[ssl:sys_platform=='win32' and python_version=='2.4'] +ctypes==1.0.2
\ No newline at end of file diff --git a/setuptools/command/easy_install.py b/setuptools/command/easy_install.py index 731a4dc3..000fefa0 100755 --- a/setuptools/command/easy_install.py +++ b/setuptools/command/easy_install.py @@ -58,7 +58,10 @@ from pkg_resources import yield_lines, normalize_path, resource_string, \ DistributionNotFound, VersionConflict, \ DEVELOP_DIST -sys_executable = os.path.normpath(sys.executable) +if '__VENV_LAUNCHER__' in os.environ: + sys_executable = os.environ['__VENV_LAUNCHER__'] +else: + sys_executable = os.path.normpath(sys.executable) __all__ = [ 'samefile', 'easy_install', 'PthDistributions', 'extract_wininst_cfg', @@ -282,6 +285,8 @@ class easy_install(Command): self.script_dir = self.install_scripts # default --record from the install command self.set_undefined_options('install', ('record', 'record')) + # Should this be moved to the if statement below? It's not used + # elsewhere normpath = map(normalize_path, sys.path) self.all_site_dirs = get_site_dirs() if self.site_dirs is not None: @@ -1486,7 +1491,6 @@ def extract_wininst_cfg(dist_filename): f.seek(prepended-12) from setuptools.compat import StringIO, ConfigParser - import struct tag, cfglen, bmlen = struct.unpack("<iii",f.read(12)) if tag not in (0x1234567A, 0x1234567B): return None # not a valid tag diff --git a/setuptools/command/egg_info.py b/setuptools/command/egg_info.py index ae14bb54..6b0d2426 100755 --- a/setuptools/command/egg_info.py +++ b/setuptools/command/egg_info.py @@ -235,7 +235,7 @@ class egg_info(Command): log.warn("unrecognized .svn/entries format; skipping %s", base) dirs[:] = [] continue - + data = list(map(str.splitlines,data.split('\n\x0c\n'))) del data[0][0] # get rid of the '8' or '9' or '10' dirurl = data[0][3] @@ -283,7 +283,7 @@ class FileList(_FileList): item = item[:-1] path = convert_path(item) - if sys.version_info >= (3,): + if PY3: try: if os.path.exists(path) or os.path.exists(path.encode('utf-8')): self.files.append(path) @@ -337,7 +337,7 @@ class manifest_maker(sdist): named by 'self.manifest'. """ # The manifest must be UTF-8 encodable. See #303. - if sys.version_info >= (3,): + if PY3: files = [] for file in self.filelist.files: try: diff --git a/setuptools/command/install_egg_info.py b/setuptools/command/install_egg_info.py index f44b34b5..87ddff9c 100755 --- a/setuptools/command/install_egg_info.py +++ b/setuptools/command/install_egg_info.py @@ -1,5 +1,6 @@ from setuptools import Command from setuptools.archive_util import unpack_archive +from setuptools.compat import PY3 from distutils import log, dir_util import os, shutil, pkg_resources diff --git a/setuptools/command/test.py b/setuptools/command/test.py index a02ac142..db2fc7b1 100644 --- a/setuptools/command/test.py +++ b/setuptools/command/test.py @@ -154,7 +154,7 @@ class test(Command): for name in sys.modules: if name.startswith(module): del_modules.append(name) - map(sys.modules.__delitem__, del_modules) + list(map(sys.modules.__delitem__, del_modules)) loader_ep = EntryPoint.parse("x="+self.test_loader) loader_class = loader_ep.load(require=False) diff --git a/setuptools/command/upload_docs.py b/setuptools/command/upload_docs.py index a75c3b7e..12bc916b 100644 --- a/setuptools/command/upload_docs.py +++ b/setuptools/command/upload_docs.py @@ -23,15 +23,21 @@ try: except ImportError: from setuptools.command.upload import upload -from setuptools.compat import httplib, urlparse +from setuptools.compat import httplib, urlparse, unicode, iteritems _IS_PYTHON3 = sys.version > '3' +if _IS_PYTHON3: + errors = 'surrogateescape' +else: + errors = 'strict' + + # This is not just a replacement for byte literals # but works as a general purpose encoder def b(s, encoding='utf-8'): if isinstance(s, unicode): - return s.encode(encoding) + return s.encode(encoding, errors) return s @@ -127,7 +133,7 @@ class upload_docs(upload): sep_boundary = b('\n--') + b(boundary) end_boundary = sep_boundary + b('--') body = [] - for key, values in data.iteritems(): + for key, values in iteritems(data): title = '\nContent-Disposition: form-data; name="%s"' % key # handle multiple entries for the same name if type(values) != type([]): diff --git a/setuptools/compat.py b/setuptools/compat.py index e2f64de2..437fb710 100644 --- a/setuptools/compat.py +++ b/setuptools/compat.py @@ -26,7 +26,7 @@ if sys.version_info[0] < 3: reduce = reduce unichr = unichr unicode = unicode - from urllib import url2pathname + from urllib import url2pathname, quote # Python 2.4 has no quote in urllib2 import urllib2 from urllib2 import urlopen, HTTPError, URLError, unquote, splituser from urlparse import urlparse, urlunparse, urljoin @@ -72,7 +72,7 @@ else: from urllib.error import HTTPError, URLError import urllib.request as urllib2 from urllib.request import urlopen, url2pathname - from urllib.parse import urlparse, urlunparse, unquote, splituser, urljoin + from urllib.parse import urlparse, urlunparse, quote, unquote, splituser, urljoin xrange = range filterfalse = itertools.filterfalse diff --git a/setuptools/extension.py b/setuptools/extension.py index eb8b836c..d7892d3d 100644 --- a/setuptools/extension.py +++ b/setuptools/extension.py @@ -35,7 +35,7 @@ class Extension(_Extension): if source.endswith('.pyx'): source = source[:-4] + '.c' return source - self.sources = map(pyx_to_c, self.sources) + self.sources = list(map(pyx_to_c, self.sources)) class Library(Extension): """Just like a regular Extension, but built as a library instead""" diff --git a/setuptools/package_index.py b/setuptools/package_index.py index 99247ef1..61a66c6d 100755 --- a/setuptools/package_index.py +++ b/setuptools/package_index.py @@ -179,7 +179,7 @@ def find_external_links(url, page): for match in REL.finditer(page): tag, rel = match.groups() - rels = map(str.strip, rel.lower().split(',')) + rels = set(map(str.strip, rel.lower().split(','))) if 'homepage' in rels or 'download' in rels: for match in HREF.finditer(tag): yield urljoin(url, htmldecode(match.group(1))) @@ -699,7 +699,7 @@ class PackageIndex(Environment): elif scheme.startswith('hg+'): return self._download_hg(url, filename) elif scheme=='file': - return url2pathname(urlparse.urlparse(url)[2]) + return url2pathname(urlparse(url)[2]) else: self.url_ok(url, True) # raises error if not allowed return self._attempt_download(url, filename) @@ -749,10 +749,10 @@ class PackageIndex(Environment): url = url.split('#',1)[0] # remove any fragment for svn's sake creds = '' if url.lower().startswith('svn:') and '@' in url: - scheme, netloc, path, p, q, f = urlparse.urlparse(url) + scheme, netloc, path, p, q, f = urlparse(url) if not netloc and path.startswith('//') and '/' in path[2:]: netloc, path = path[2:].split('/',1) - auth, host = urllib.splituser(netloc) + auth, host = splituser(netloc) if auth: if ':' in auth: user, pw = auth.split(':',1) @@ -760,13 +760,13 @@ class PackageIndex(Environment): else: creds = " --username="+auth netloc = host - url = urlparse.urlunparse((scheme, netloc, url, p, q, f)) + url = urlunparse((scheme, netloc, url, p, q, f)) self.info("Doing subversion checkout from %s to %s", url, filename) os.system("svn checkout%s -q %s %s" % (creds, url, filename)) return filename def _vcs_split_rev_from_url(self, url, pop_prefix=False): - scheme, netloc, path, query, frag = urlparse.urlsplit(url) + scheme, netloc, path, query, frag = urlsplit(url) scheme = scheme.split('+', 1)[-1] @@ -778,7 +778,7 @@ class PackageIndex(Environment): path, rev = path.rsplit('@', 1) # Also, discard fragment - url = urlparse.urlunsplit((scheme, netloc, path, query, '')) + url = urlunsplit((scheme, netloc, path, query, '')) return url, rev diff --git a/setuptools/sandbox.py b/setuptools/sandbox.py index 441cae01..91dfc519 100755 --- a/setuptools/sandbox.py +++ b/setuptools/sandbox.py @@ -9,6 +9,7 @@ except NameError: _file = None _open = open from distutils.errors import DistutilsError +from setuptools.compat import builtins, execfile, reduce from pkg_resources import working_set from setuptools.compat import builtins, execfile, reduce @@ -86,7 +87,7 @@ def run_setup(setup_script, args): # exclude any encodings modules. See #285 and not mod_name.startswith('encodings.') ] - map(sys.modules.__delitem__, del_modules) + list(map(sys.modules.__delitem__, del_modules)) os.chdir(old_dir) sys.path[:] = save_path sys.argv[:] = save_argv diff --git a/setuptools/script template (dev).py b/setuptools/script template (dev).py index 6dd9dd45..901790e7 100644 --- a/setuptools/script template (dev).py +++ b/setuptools/script template (dev).py @@ -3,4 +3,7 @@ __requires__ = """%(spec)r""" from pkg_resources import require; require("""%(spec)r""") del require __file__ = """%(dev_path)r""" -execfile(__file__) +try: + execfile(__file__) +except NameError: + exec(compile(open(__file__).read(), __file__, 'exec')) diff --git a/setuptools/ssl_support.py b/setuptools/ssl_support.py index 2aec655a..e749b312 100644 --- a/setuptools/ssl_support.py +++ b/setuptools/ssl_support.py @@ -4,6 +4,11 @@ from pkg_resources import ResolutionError, ExtractionError from setuptools.compat import urllib2 try: + import urllib2 +except ImportError: + import urllib.request as urllib2 + +try: import ssl except ImportError: ssl = None diff --git a/setuptools/tests/__init__.py b/setuptools/tests/__init__.py index 298141a7..b5328ce6 100644 --- a/setuptools/tests/__init__.py +++ b/setuptools/tests/__init__.py @@ -2,7 +2,7 @@ import sys import os import unittest -import doctest +from setuptools.tests import doctest import distutils.core import distutils.cmd from distutils.errors import DistutilsOptionError, DistutilsPlatformError @@ -11,6 +11,7 @@ from distutils.core import Extension from distutils.version import LooseVersion from setuptools.compat import func_code +from setuptools.compat import func_code import setuptools.dist import setuptools.depends as dep from setuptools import Feature diff --git a/setuptools/tests/test_develop.py b/setuptools/tests/test_develop.py index 9d7ce711..7b90161a 100644 --- a/setuptools/tests/test_develop.py +++ b/setuptools/tests/test_develop.py @@ -51,7 +51,7 @@ class TestDevelopTest(unittest.TestCase): site.USER_SITE = tempfile.mkdtemp() def tearDown(self): - if sys.version < "2.6" or hasattr(sys, 'real_prefix'): + if sys.version < "2.6" or hasattr(sys, 'real_prefix') or (hasattr(sys, 'base_prefix') and sys.base_prefix != sys.prefix): return os.chdir(self.old_cwd) diff --git a/setuptools/tests/test_easy_install.py b/setuptools/tests/test_easy_install.py index 277b4844..b0609eb1 100644 --- a/setuptools/tests/test_easy_install.py +++ b/setuptools/tests/test_easy_install.py @@ -12,6 +12,7 @@ import textwrap import tarfile import distutils.core +from setuptools.compat import StringIO, BytesIO, next, urlparse from setuptools.sandbox import run_setup, SandboxViolation from setuptools.command.easy_install import easy_install, fix_jython_executable, get_script_args from setuptools.command.easy_install import PthDistributions diff --git a/setuptools/tests/test_sdist.py b/setuptools/tests/test_sdist.py index 438f7ced..a58b749c 100644 --- a/setuptools/tests/test_sdist.py +++ b/setuptools/tests/test_sdist.py @@ -9,7 +9,8 @@ import tempfile import unittest import unicodedata -from setuptools.compat import StringIO, unicode + +from setuptools.compat import StringIO, quote, unicode from setuptools.command.sdist import sdist from setuptools.command.egg_info import manifest_maker from setuptools.dist import Distribution @@ -55,7 +56,7 @@ def b(s, encoding='utf-8'): # Convert to POSIX path def posix(path): - if sys.version_info >= (3,) and not isinstance(path, str): + if sys.version_info >= (3,) and not isinstance(path, unicode): return path.replace(os.sep.encode('ascii'), b('/')) else: return path.replace(os.sep, '/') diff --git a/tests/test_pkg_resources.py b/tests/test_pkg_resources.py index 7009b4ab..b05ea44b 100644 --- a/tests/test_pkg_resources.py +++ b/tests/test_pkg_resources.py @@ -5,57 +5,62 @@ import zipfile import pkg_resources +try: + unicode +except NameError: + unicode = str + class EggRemover(unicode): - def __call__(self): - if self in sys.path: - sys.path.remove(self) - if os.path.exists(self): - os.remove(self) + def __call__(self): + if self in sys.path: + sys.path.remove(self) + if os.path.exists(self): + os.remove(self) class TestZipProvider(object): - finalizers = [] - - @classmethod - def setup_class(cls): - "create a zip egg and add it to sys.path" - egg = tempfile.NamedTemporaryFile(suffix='.egg', delete=False) - zip_egg = zipfile.ZipFile(egg, 'w') - zip_info = zipfile.ZipInfo() - zip_info.filename = 'mod.py' - zip_info.date_time = 2013, 5, 12, 13, 25, 0 - zip_egg.writestr(zip_info, 'x = 3\n') - zip_info = zipfile.ZipInfo() - zip_info.filename = 'data.dat' - zip_info.date_time = 2013, 5, 12, 13, 25, 0 - zip_egg.writestr(zip_info, 'hello, world!') - zip_egg.close() - egg.close() - - sys.path.append(egg.name) - cls.finalizers.append(EggRemover(egg.name)) - - @classmethod - def teardown_class(cls): - for finalizer in cls.finalizers: - finalizer() - - def test_resource_filename_rewrites_on_change(self): - """ - If a previous call to get_resource_filename has saved the file, but - the file has been subsequently mutated with different file of the - same size and modification time, it should not be overwritten on a - subsequent call to get_resource_filename. - """ - import mod - manager = pkg_resources.ResourceManager() - zp = pkg_resources.ZipProvider(mod) - filename = zp.get_resource_filename(manager, 'data.dat') - assert os.stat(filename).st_mtime == 1368379500 - f = open(filename, 'wb') - f.write('hello, world?') - f.close() - os.utime(filename, (1368379500, 1368379500)) - filename = zp.get_resource_filename(manager, 'data.dat') - f = open(filename) - assert f.read() == 'hello, world!' - manager.cleanup_resources() + finalizers = [] + + @classmethod + def setup_class(cls): + "create a zip egg and add it to sys.path" + egg = tempfile.NamedTemporaryFile(suffix='.egg', delete=False) + zip_egg = zipfile.ZipFile(egg, 'w') + zip_info = zipfile.ZipInfo() + zip_info.filename = 'mod.py' + zip_info.date_time = 2013, 5, 12, 13, 25, 0 + zip_egg.writestr(zip_info, 'x = 3\n') + zip_info = zipfile.ZipInfo() + zip_info.filename = 'data.dat' + zip_info.date_time = 2013, 5, 12, 13, 25, 0 + zip_egg.writestr(zip_info, 'hello, world!') + zip_egg.close() + egg.close() + + sys.path.append(egg.name) + cls.finalizers.append(EggRemover(egg.name)) + + @classmethod + def teardown_class(cls): + for finalizer in cls.finalizers: + finalizer() + + def test_resource_filename_rewrites_on_change(self): + """ + If a previous call to get_resource_filename has saved the file, but + the file has been subsequently mutated with different file of the + same size and modification time, it should not be overwritten on a + subsequent call to get_resource_filename. + """ + import mod + manager = pkg_resources.ResourceManager() + zp = pkg_resources.ZipProvider(mod) + filename = zp.get_resource_filename(manager, 'data.dat') + assert os.stat(filename).st_mtime == 1368379500 + f = open(filename, 'wb') + f.write('hello, world?') + f.close() + os.utime(filename, (1368379500, 1368379500)) + filename = zp.get_resource_filename(manager, 'data.dat') + f = open(filename) + assert f.read() == 'hello, world!' + manager.cleanup_resources() |