From 9a531b50020849193a55262b3f9cfc375ad3f37c Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Fri, 1 Jan 2016 21:22:29 -0500 Subject: Move extern.packaging into a package to enable package-relative imports to resolve propertly. Ref #229. --HG-- branch : feature/issue-229 --- pkg_resources/extern/packaging.py | 45 ------------------------------ pkg_resources/extern/packaging/__init__.py | 45 ++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 45 deletions(-) delete mode 100644 pkg_resources/extern/packaging.py create mode 100644 pkg_resources/extern/packaging/__init__.py (limited to 'pkg_resources/extern') diff --git a/pkg_resources/extern/packaging.py b/pkg_resources/extern/packaging.py deleted file mode 100644 index 47f58eab..00000000 --- a/pkg_resources/extern/packaging.py +++ /dev/null @@ -1,45 +0,0 @@ -""" -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() diff --git a/pkg_resources/extern/packaging/__init__.py b/pkg_resources/extern/packaging/__init__.py new file mode 100644 index 00000000..47f58eab --- /dev/null +++ b/pkg_resources/extern/packaging/__init__.py @@ -0,0 +1,45 @@ +""" +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() -- cgit v1.2.1