Permalink
Browse files

Change the way that management modules are found to use pkgutil instead

of imp, so that multiple modules in the same heirarchy can be installed
from different setuptools packages. Addresses ticket #18685
  • Loading branch information...
1 parent 8d3e501 commit be5eb957c2dfeea2ce64888359791d3554ce6607 @cberner cberner committed Jul 30, 2012
Showing with 10 additions and 16 deletions.
  1. +10 −16 django/core/management/__init__.py
View
26 django/core/management/__init__.py
@@ -2,7 +2,7 @@
import os
import sys
from optparse import OptionParser, NO_DEFAULT
-import imp
+import pkgutil
import warnings
from django.core.management.base import BaseCommand, CommandError, handle_default_options
@@ -37,28 +37,22 @@ def find_management_module(app_name):
Raises ImportError if the management module cannot be found for any reason.
"""
- parts = app_name.split('.')
- parts.append('management')
- parts.reverse()
- part = parts.pop()
- path = None
+ module_name = app_name + ".management"
+ loader = pkgutil.find_loader(module_name)
# When using manage.py, the project module is added to the path,
# loaded, then removed from the path. This means that
# testproject.testapp.models can be loaded in future, even if
# testproject isn't in the path. When looking for the management
# module, we need look for the case where the project name is part
# of the app_name but the project directory itself isn't on the path.
- try:
- f, path, descr = imp.find_module(part,path)
- except ImportError as e:
- if os.path.basename(os.getcwd()) != part:
- raise e
-
- while parts:
- part = parts.pop()
- f, path, descr = imp.find_module(part, path and [path] or None)
- return path
+ if not loader and os.path.basename(os.getcwd()) == module_name.split('.')[0]:
+ loader = pkgutil.find_loader(".".join(module_name.split(".")[1:]))
+
+ if loader:
+ return loader.filename
+ else:
+ return ''
def load_command_class(app_name, name):
"""

0 comments on commit be5eb95

Please sign in to comment.