diff options
| author | Jason R. Coombs <jaraco@jaraco.com> | 2016-09-14 13:54:26 -0400 |
|---|---|---|
| committer | Jason R. Coombs <jaraco@jaraco.com> | 2016-09-14 13:54:26 -0400 |
| commit | 11ef9a98f1da8c883fc346ce78afbad78d5eff83 (patch) | |
| tree | bbb1d64d448be9966512bdb9cb96cc128965137c /pkg_resources | |
| parent | 2388233e4106937064bf1cdb087e7e1cfc5c7ea7 (diff) | |
| download | python-setuptools-git-11ef9a98f1da8c883fc346ce78afbad78d5eff83.tar.gz | |
Suppress ValueError in fixup_namespace_packages. Fixes #520. Fixes #513.
Diffstat (limited to 'pkg_resources')
| -rw-r--r-- | pkg_resources/__init__.py | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/pkg_resources/__init__.py b/pkg_resources/__init__.py index a93a3da7..4208c4ec 100644 --- a/pkg_resources/__init__.py +++ b/pkg_resources/__init__.py @@ -2066,6 +2066,15 @@ def _rebuild_mod_path(orig_path, package_name, module): """ sys_path = [_normalize_cached(p) for p in sys.path] + def safe_sys_path_index(entry): + """ + Workaround for #520 and #513. + """ + try: + return sys_path.index(entry) + except ValueError: + return float('inf') + def position_in_sys_path(path): """ Return the ordinal of the path based on its position in sys.path @@ -2073,7 +2082,7 @@ def _rebuild_mod_path(orig_path, package_name, module): path_parts = path.split(os.sep) module_parts = package_name.count('.') + 1 parts = path_parts[:-module_parts] - return sys_path.index(_normalize_cached(os.sep.join(parts))) + return safe_sys_path_index(_normalize_cached(os.sep.join(parts))) orig_path.sort(key=position_in_sys_path) module.__path__[:] = [_normalize_cached(p) for p in orig_path] |
