diff options
| author | Jason R. Coombs <jaraco@jaraco.com> | 2015-12-31 16:47:55 -0500 |
|---|---|---|
| committer | Jason R. Coombs <jaraco@jaraco.com> | 2015-12-31 16:47:55 -0500 |
| commit | 9b985a9112d9be396adca6a1948076378c70cc34 (patch) | |
| tree | 99e334a9df66bdeeb5a470c4abe65d9c66e0090d /pkg_resources/extern | |
| parent | ddb91c20793d8e5e8a01e0302afeaaba76776741 (diff) | |
| download | python-setuptools-git-9b985a9112d9be396adca6a1948076378c70cc34.tar.gz | |
Use the same technique in pkg_resources, relying on an 'extern' module to resolve the conditional import.
--HG--
branch : feature/issue-229
Diffstat (limited to 'pkg_resources/extern')
| -rw-r--r-- | pkg_resources/extern/__init__.py | 0 | ||||
| -rw-r--r-- | pkg_resources/extern/packaging.py | 45 |
2 files changed, 45 insertions, 0 deletions
diff --git a/pkg_resources/extern/__init__.py b/pkg_resources/extern/__init__.py new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/pkg_resources/extern/__init__.py diff --git a/pkg_resources/extern/packaging.py b/pkg_resources/extern/packaging.py new file mode 100644 index 00000000..47f58eab --- /dev/null +++ b/pkg_resources/extern/packaging.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() |
