Django: Ticket Query!closed&cc=~bhuztez&order=priority The Web framework for perfectionists with deadlines. en-US Django!closed&cc=~bhuztez&order=priority Trac 1.0 #8280: Commands framework doesn't support alternate import methods Wed, 13 Aug 2008 07:08:07 GMT jdetaeye <p> From this thread on the developer mailing list <a class="ext-link" href=""><span class="icon">​</span></a># I understand that the Django team is keen on supporting alternate ways of packaging django: in a zip-file, in a jar-file(Jython) or other "frozen" formats. </p> <p> One place that'll need fixing to achieve this is to update the command framework. <br /> The find available commands, the current Django code is browsing the command subdirectories and looking for files that end with a .py extension<br /> To support alternate packaging, the code should use the proper Python APIs to iterate over the available modules in a package. </p> <p> A patch along these lines was already included with <a class="closed ticket" href="" title="Customized actions for not working (closed: fixed)">#5825</a>. (The patch would need updating to the SVN version however - Once this ticket is accepted I can take care of it.) </p> Results #14087: only sees commands in the last package of a namespace package Tue, 10 Aug 2010 00:07:24 GMT KyleMac <p> If using the namespace features of setuptools, then get_commands will only see the commands in the last package. If you have something like the following: </p> <pre class="wiki"> </pre><p> then Django will only spot command2. I don't know what the proper fix would be, but I use the following to fill in the gaps: </p> <pre class="wiki">def find_namespace_commands(): try: from django.conf import settings apps = settings.INSTALLED_APPS except (AttributeError, EnvironmentError, ImportError): apps = [] import imp from import _commands, find_commands from django.utils.importlib import import_module for app in apps: try: app_path = import_module(app).__path__ except AttributeError: continue try: imp.find_module('management', app_path) except ImportError: continue mod = import_module('' % app) if hasattr(mod, '__path__'): for cmd in find_commands(mod.__path__[0]): if _commands is None: _commands = {} if cmd not in _commands: _commands[cmd] = app find_namespace_commands() </pre> Results