diff options
| author | Jason R. Coombs <jaraco@jaraco.com> | 2015-12-31 16:30:47 -0500 |
|---|---|---|
| committer | Jason R. Coombs <jaraco@jaraco.com> | 2015-12-31 16:30:47 -0500 |
| commit | 952c1bafda1929c74c737646aa025e6ffad6632e (patch) | |
| tree | 1fd158d08ce61d8a9f4e2b88d27026e7774f80ff /setuptools/extern | |
| parent | 06872bb0bbbeb953e90bd0941444b0d499056557 (diff) | |
| download | python-setuptools-git-952c1bafda1929c74c737646aa025e6ffad6632e.tar.gz | |
Modeling after Astropy's technique for bundling libraries, the imports are now much cleaner. Thanks @embray. Ref #229.
--HG--
branch : feature/issue-229
Diffstat (limited to 'setuptools/extern')
| -rw-r--r-- | setuptools/extern/__init__.py | 0 | ||||
| -rw-r--r-- | setuptools/extern/six.py | 46 |
2 files changed, 46 insertions, 0 deletions
diff --git a/setuptools/extern/__init__.py b/setuptools/extern/__init__.py new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/setuptools/extern/__init__.py diff --git a/setuptools/extern/six.py b/setuptools/extern/six.py new file mode 100644 index 00000000..2685c5e6 --- /dev/null +++ b/setuptools/extern/six.py @@ -0,0 +1,46 @@ +""" +Handle loading six package from system or from the bundled copy +""" + +import imp + + +_SIX_SEARCH_PATH = ['setuptools._vendor.six', 'six'] + + +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_six(search_path=_SIX_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 'six' module of minimum version {0} is required; " + "normally this is bundled with this package so if you get " + "this warning, consult the packager of your " + "distribution.") + + +_import_six() |
