Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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...
commit be5eb957c2dfeea2ce64888359791d3554ce6607 1 parent 8d3e501
Christopher Berner authored July 30, 2012

Showing 1 changed file with 10 additions and 16 deletions. Show diff stats Hide diff stats

  1. 26  django/core/management/__init__.py
26  django/core/management/__init__.py
@@ -2,7 +2,7 @@
2 2
 import os
3 3
 import sys
4 4
 from optparse import OptionParser, NO_DEFAULT
5  
-import imp
  5
+import pkgutil
6 6
 import warnings
7 7
 
8 8
 from django.core.management.base import BaseCommand, CommandError, handle_default_options
@@ -37,11 +37,8 @@ def find_management_module(app_name):
37 37
 
38 38
     Raises ImportError if the management module cannot be found for any reason.
39 39
     """
40  
-    parts = app_name.split('.')
41  
-    parts.append('management')
42  
-    parts.reverse()
43  
-    part = parts.pop()
44  
-    path = None
  40
+    module_name = app_name + ".management"
  41
+    loader = pkgutil.find_loader(module_name)
45 42
 
46 43
     # When using manage.py, the project module is added to the path,
47 44
     # loaded, then removed from the path. This means that
@@ -49,16 +46,13 @@ def find_management_module(app_name):
49 46
     # testproject isn't in the path. When looking for the management
50 47
     # module, we need look for the case where the project name is part
51 48
     # of the app_name but the project directory itself isn't on the path.
52  
-    try:
53  
-        f, path, descr = imp.find_module(part,path)
54  
-    except ImportError as e:
55  
-        if os.path.basename(os.getcwd()) != part:
56  
-            raise e
57  
-
58  
-    while parts:
59  
-        part = parts.pop()
60  
-        f, path, descr = imp.find_module(part, path and [path] or None)
61  
-    return path
  49
+    if not loader and os.path.basename(os.getcwd()) == module_name.split('.')[0]:
  50
+        loader = pkgutil.find_loader(".".join(module_name.split(".")[1:]))
  51
+
  52
+    if loader:
  53
+        return loader.filename
  54
+    else:
  55
+        return ''
62 56
 
63 57
 def load_command_class(app_name, name):
64 58
     """

0 notes on commit be5eb95

Please sign in to comment.
Something went wrong with that request. Please try again.