liuyang1520 / django-command-extensions

Automatically exported from code.google.com/p/django-command-extensions
MIT License
0 stars 0 forks source link

create_jobs fails when target app is contained within a namespace package #37

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Create two django apps with namespace packages, using the same
namespace. (Easiest way is to easy_install ZopeSkel, then paster create -t
basic_namespace). Let's say you create foo.bar and foo.baz.
2. Put foo.bar and foo.baz somewhere on your pythonpath (say in
site-packages). You should have paths like
$PYTHONPATH/foo.bar/foo/bar/models.py.
3. Add a .pth file in your site-packages so python can load them. In the
above example, you might have a foo.pth containing:
./foo.bar
./foo.baz
4. Create a Django project, and put foo.bar and foo.baz in the INSTALLED_APPS.
5. Run python manage.py create_jobs baz. (If that appears to work, then try
create_jobs bar - it depends what your search path is as to which one will
error)

One of the above will give an ImportError. This is happening because
create_jobs.py iteratively walks the path of the located app, trying to
figure its directory out. It just uses the first one returned by
find_module. If we're trying to find foo.baz, for exmaple, and the first
module found happens to be that for foo.bar, site-packages/foo.bar/foo/
will eventually wind up as the app_dir. ImportError will then be raised
when the script tries to import 'baz' from that path.

I've attached a patch against r83 which works around this. There could be a
nicer way of doing this, but it works for me (as they say).

What version of the product are you using? On what operating system?

Please provide any additional information below.

Original issue reported on code.google.com by dan.fairs on 31 Jul 2008 at 3:06

Attachments:

GoogleCodeExporter commented 8 years ago
Oops - should have mentioned that you need probably need to drop a models.py 
file
into each of the paster-created skeletons for Django to recognise them as apps.

Original comment by dan.fairs on 31 Jul 2008 at 3:09

GoogleCodeExporter commented 8 years ago
added to svn

Original comment by v.oostv...@gmail.com on 2 Aug 2008 at 3:25