Commit 9b985a91 authored by Jason R. Coombs's avatar Jason R. Coombs

Use the same technique in pkg_resources, relying on an 'extern' module to...

Use the same technique in pkg_resources, relying on an 'extern' module to resolve the conditional import.

--HG--
branch : feature/issue-229
parent ddb91c20
......@@ -87,15 +87,10 @@ try:
except ImportError:
pass
try:
import pkg_resources._vendor.packaging.version
import pkg_resources._vendor.packaging.specifiers
packaging = pkg_resources._vendor.packaging
except ImportError:
# fallback to naturally-installed version; allows system packagers to
# omit vendored packages.
import packaging.version
import packaging.specifiers
from pkg_resources.extern import packaging
__import__('pkg_resources.extern.packaging.version')
__import__('pkg_resources.extern.packaging.specifiers')
if (3, 0) < sys.version_info < (3, 3):
......
"""
Handle loading a package from system or from the bundled copy
"""
import imp
_SEARCH_PATH = ['pkg_resources._vendor.packaging', 'packaging']
def _find_module(name, path=None):
"""
Alternative to `imp.find_module` that can also search in subpackages.
"""
parts = name.split('.')
for part in parts:
if path is not None:
path = [path]
fh, path, descr = imp.find_module(part, path)
return fh, path, descr
def _import_in_place(search_path=_SEARCH_PATH):
for mod_name in search_path:
try:
mod_info = _find_module(mod_name)
except ImportError:
continue
imp.load_module(__name__, *mod_info)
break
else:
raise ImportError(
"The '{name}' package is required; "
"normally this is bundled with this package so if you get "
"this warning, consult the packager of your "
"distribution.".format(name=_SEARCH_PATH[-1]))
_import_in_place()
......@@ -5,14 +5,13 @@ import shutil
import string
import pytest
from pkg_resources.extern import packaging
import pkg_resources
from pkg_resources import (parse_requirements, VersionConflict, parse_version,
Distribution, EntryPoint, Requirement, safe_version, safe_name,
WorkingSet)
packaging = pkg_resources.packaging
def safe_repr(obj, short=False):
""" copied from Python2.7"""
......
[pytest]
addopts=--doctest-modules --ignore release.py --ignore setuptools/lib2to3_ex.py --ignore tests/manual_test.py --ignore tests/shlib_test --doctest-glob=pkg_resources/api_tests.txt --ignore scripts/upload-old-releases-as-zip.py
norecursedirs=dist build *.egg setuptools/extern
norecursedirs=dist build *.egg setuptools/extern pkg_resources/extern
......@@ -26,7 +26,7 @@ from pkg_resources import (
safe_version, yield_lines, EntryPoint, iter_entry_points, to_filename)
import setuptools.unicode_utils as unicode_utils
from pkg_resources import packaging
from pkg_resources.extern import packaging
try:
from setuptools_svn import svn_utils
......
......@@ -14,13 +14,12 @@ from distutils.errors import (DistutilsOptionError, DistutilsPlatformError,
DistutilsSetupError)
from setuptools.extern import six
from pkg_resources.extern import packaging
from setuptools.depends import Require
from setuptools import windows_support
import pkg_resources
packaging = pkg_resources.packaging
def _get_unpatched(cls):
"""Protect against re-patching the distutils if reloaded
......
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