[Distutils] Buildout + namespace packages + Django management commands?
P.J. Eby
pje at telecommunity.com
Sun Sep 20 17:00:44 CEST 2009
At 09:17 AM 9/20/2009 +0100, Kyle MacFarlane wrote:
>2009/9/19 P.J. Eby <pje at telecommunity.com>
> > If they use the package's __path__ attribute, they'll find its
> contents, whether someone is using pkgutil.extend_path, .pth files,
> or setuptools. Â They don't have to support setuptools to support
> namespace packages, just pay attention to the __path__ variable
> that's part of standard Python.
>
>I was hoping more if anybody knew a recipe to get round my problem but
>I had a look inside Django to see how it looks through packages.
>
>The problem is caused by line 58 at this link raising an ImportError:
>http://code.djangoproject.com/browser/django/trunk/django/core/management/__init__.py
>
>It doesn't matter what order find_module is called on various paths,
>it still relies entirely on the order in sys.path. Calling find_module
>on second_app before first_app will still fail if first_app is the
>first app on sys.path (which suggests that something has been done
>wrong even before line 58 or find_module itself doesn't support
>namespaces?).
>
>Unfortunately I've never dealt with the imp module before. What would
>I need to do? Import the package (which is actually "path" in this
>code), get __path__ from it and then do find_module again but with
>__path__ instead?
Basically, yeah, only it has to happen inside the "while parts"
loop. The downside, of course, is that you'll be importing every
application and its management package. It's too bad, really, they
could've saved a ton of code and complexity there (as well as being
able to support namespace packages, zipfiles, etc.) if they'd just
used pkg_resources and entry points. Projects could just declare
their commands without needing a management.commands subpackage, or
separate modules for each command.
More information about the Distutils-SIG
mailing list