Customized actions for manage.py not working
|Reported by:||Owned by:||nobody|
|Component:||Core (Management commands)||Version:||master|
|Severity:||Keywords:||custom actions manage.py|
|Cc:||eric@…, martin@…, micsco@…, elsdoerfer@…, ehs@…||Triage Stage:||Unreviewed|
|Has patch:||no||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
Custom actions can be added, as described http://www.djangoproject.com/documentation/django-admin/#customized-actions
Following the instructions I am getting the error message: unknown command
To reproduce you can also copy the contents of the folder tests\modeltests\user_commands\management in an application subdirectory of your project.
The regression test for user_commands passes: it seems to use a different sys.path than when you run manage.py from the commandline...
Digging a bit deeper in the source file
- The function imp.find_module in the method find_management_module is using sys.path to locate the management modules. The parent directory of your project is normally not on the path, so looking for an application package "project_name.app_name" doesn't find a module. Manage.py only has the project directory itself on the path.
- The find_commands method in the same source file is using a pretty hack-ish way to discover commands: it looks for files ending in .py. This misses compiled code with extensions as .pyo and .pyc and also doesn't work for source files packaged in a zip file (as produced by eg py2exe). The correct api is to use pkgutil.iter_modules (unfortunately only available in python 2.5)
(I'm willing to look at a patch for the issues, but need some guidance: For the first issue, I am a bit puzzled by the append and popping of the sys.path in the setup_environ method in the same file. For the second issue, it requires more changes and thinking to do it properly across different versions: is it worth the effort?)
Change History (30)
comment:23 Changed 8 years ago by
|milestone:||1.0 → 1.1|
|Status:||closed → reopened|
|Triage Stage:||Ready for checkin → Unreviewed|