diff options
| author | PJ Eby <distutils-sig@python.org> | 2005-08-14 21:01:33 +0000 |
|---|---|---|
| committer | PJ Eby <distutils-sig@python.org> | 2005-08-14 21:01:33 +0000 |
| commit | af4cec2574e4e934e440116be8ff39a5b3d84139 (patch) | |
| tree | 0ab25b8ef9e2653be1493623df40499138a9c48b /pkg_resources.py | |
| parent | 98ab5c9053b781fccb6b5d69bb1fe88580d4941a (diff) | |
| download | python-setuptools-git-af4cec2574e4e934e440116be8ff39a5b3d84139.tar.gz | |
Add experimental support for merging non-empty namespace packages. This
lets you have one distribution containing a non-empty __init__.py for the
package, as long as you call 'declare_namespace()' from that __init__.py
and all other __init__.py files for the namespace package, and do *not*
declare it as a namespace package in setup() (so that it won't be
automatically imported if it's on sys.path, the way empty namespace
packages are.)
--HG--
branch : setuptools
extra : convert_revision : svn%3A6015fed2-1504-0410-9fe1-9d1591cc4771/sandbox/trunk/setuptools%4041202
Diffstat (limited to 'pkg_resources.py')
| -rw-r--r-- | pkg_resources.py | 28 |
1 files changed, 14 insertions, 14 deletions
diff --git a/pkg_resources.py b/pkg_resources.py index 39784ea3..9b91092a 100644 --- a/pkg_resources.py +++ b/pkg_resources.py @@ -13,7 +13,7 @@ The package resource API is designed to work with normal filesystem packages, method. """ -import sys, os, zipimport, time, re, imp +import sys, os, zipimport, time, re, imp, new from sets import ImmutableSet @@ -1412,7 +1412,6 @@ def register_namespace_handler(importer_type, namespace_handler): """ _namespace_handlers[importer_type] = namespace_handler - def _handle_ns(packageName, path_item): """Ensure that named package includes a subpath of path_item (if needed)""" importer = get_importer(path_item) @@ -1421,18 +1420,19 @@ def _handle_ns(packageName, path_item): loader = importer.find_module(packageName) if loader is None: return None - - module = sys.modules.get(packageName) or loader.load_module(packageName) - if not hasattr(module,'__path__'): + module = sys.modules.get(packageName) + if module is None: + module = sys.modules[packageName] = new.module(packageName) + module.__path__ = [] + elif not hasattr(module,'__path__'): raise TypeError("Not a package:", packageName) - handler = _find_adapter(_namespace_handlers, importer) subpath = handler(importer,path_item,packageName,module) if subpath is not None: module.__path__.append(subpath) + loader.load_module(packageName) return subpath - def declare_namespace(packageName): """Declare that package 'packageName' is a namespace package""" @@ -1451,16 +1451,16 @@ def declare_namespace(packageName): except AttributeError: raise TypeError("Not a package:", parent) - for path_item in path: - # Ensure all the parent's path items are reflected in the child, - # if they apply - _handle_ns(packageName, path_item) - # Track what packages are namespaces, so when new path items are added, # they can be updated _namespace_packages.setdefault(parent,[]).append(packageName) _namespace_packages.setdefault(packageName,[]) + for path_item in path: + # Ensure all the parent's path items are reflected in the child, + # if they apply + _handle_ns(packageName, path_item) + finally: imp.release_lock() @@ -1478,9 +1478,9 @@ def file_ns_handler(importer, path_item, packageName, module): """Compute an ns-package subpath for a filesystem or zipfile importer""" subpath = os.path.join(path_item, packageName.split('.')[-1]) - normalized = os.path.normpath(os.path.normcase(subpath)) + normalized = normalize_path(subpath) for item in module.__path__: - if os.path.normpath(os.path.normcase(item))==normalized: + if normalize_path(item)==normalized: break else: # Only return the path if it's not already there |
