Ticket #14087: eggs_broken.diff
File eggs_broken.diff, 18.8 KB (added by , 13 years ago) |
---|
-
django/core/management/__init__.py
diff --git a/django/core/management/__init__.py b/django/core/management/__init__.py index bafab17..0166d60 100644
a b import imp 5 5 6 6 import django 7 7 from django.core.management.base import BaseCommand, CommandError, handle_default_options 8 from django.utils.importlib import import_module 8 from django.utils.importlib import import_module, find_modules 9 9 10 10 # For backwards compatibility: get_version() used to be in this module. 11 11 get_version = django.get_version … … def find_management_module(app_name): 36 36 Raises ImportError if the management module cannot be found for any reason. 37 37 """ 38 38 parts = app_name.split('.') 39 parts.append('management') 40 parts.reverse() 41 part = parts.pop() 42 path = None 43 44 # When using manage.py, the project module is added to the path, 45 # loaded, then removed from the path. This means that 46 # testproject.testapp.models can be loaded in future, even if 47 # testproject isn't in the path. When looking for the management 48 # module, we need look for the case where the project name is part 49 # of the app_name but the project directory itself isn't on the path. 50 try: 51 f, path, descr = imp.find_module(part,path) 52 except ImportError,e: 53 if os.path.basename(os.getcwd()) != part: 54 raise e 39 40 for i in range(len(parts), 0, -1): 41 try: 42 paths = sys.modules['.'.join(parts[:i])].__path__ 43 except KeyError: 44 continue 45 46 parts = parts[i:] + ['management'] 47 parts.reverse() 48 break 49 else: 50 parts = app_name.split('.') 51 parts.append('management') 52 parts.reverse() 53 part = parts.pop() 54 paths = None 55 56 # When using manage.py, the project module is added to the path, 57 # loaded, then removed from the path. This means that 58 # testproject.testapp.models can be loaded in future, even if 59 # testproject isn't in the path. When looking for the management 60 # module, we need look for the case where the project name is part 61 # of the app_name but the project directory itself isn't on the path. 62 try: 63 modules = find_modules(part, paths) 64 paths = [m[1] for m in modules] 65 except ImportError,e: 66 if os.path.basename(os.getcwd()) != part: 67 raise e 55 68 56 69 while parts: 57 70 part = parts.pop() 58 f, path, descr = imp.find_module(part, path and [path] or None) 59 return path 71 modules = find_modules(part, paths) 72 paths = [m[1] for m in modules] 73 return paths[0] 60 74 61 75 def load_command_class(app_name, name): 62 76 """ -
django/utils/importlib.py
diff --git a/django/utils/importlib.py b/django/utils/importlib.py index ef4d0e4..1507a2b 100644
a b 1 1 # Taken from Python 2.7 with permission from/by the original author. 2 2 import sys 3 import imp 3 4 4 5 def _resolve_name(name, package, level): 5 6 """Return the absolute name of the module to be imported.""" … … def import_module(name, package=None): 34 35 name = _resolve_name(name[level:], package, level) 35 36 __import__(name) 36 37 return sys.modules[name] 38 39 40 def find_modules(name, path=None): 41 """Find all modules with name 'name' 42 43 Unlike find_module in the imp package this returns a list of all 44 matched modules. 45 """ 46 results = [] 47 if path is None: path = sys.path 48 for p in path: 49 importer = sys.path_importer_cache.get(p, None) 50 if importer is None: 51 find_module = imp.find_module 52 else: 53 find_module = importer.find_module 54 55 try: 56 result = find_module(name, [p]) 57 if result is not None: 58 results.append(result) 59 except ImportError: 60 pass 61 if not results: 62 raise ImportError("No module named %.200s" % name) 63 return results -
new file tests/regressiontests/admin_scripts/lib1/nons_app/management/commands/nons_app_command1.py
diff --git a/tests/regressiontests/admin_scripts/lib1/nons_app/__init__.py b/tests/regressiontests/admin_scripts/lib1/nons_app/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/regressiontests/admin_scripts/lib1/nons_app/management/__init__.py b/tests/regressiontests/admin_scripts/lib1/nons_app/management/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/regressiontests/admin_scripts/lib1/nons_app/management/commands/__init__.py b/tests/regressiontests/admin_scripts/lib1/nons_app/management/commands/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/regressiontests/admin_scripts/lib1/nons_app/management/commands/nons_app_command1.py b/tests/regressiontests/admin_scripts/lib1/nons_app/management/commands/nons_app_command1.py new file mode 100644 index 0000000..a393663
- + 1 from django.core.management.base import BaseCommand 2 3 class Command(BaseCommand): 4 help = 'Test managment commands in non-namespaced app' 5 requires_model_validation = False 6 args = '' 7 8 def handle(self, *labels, **options): 9 print 'EXECUTE:nons_app_command1' -
new file tests/regressiontests/admin_scripts/lib1/nsapps/__init__.py
diff --git a/tests/regressiontests/admin_scripts/lib1/nons_app/models.py b/tests/regressiontests/admin_scripts/lib1/nons_app/models.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/regressiontests/admin_scripts/lib1/nsapps/__init__.py b/tests/regressiontests/admin_scripts/lib1/nsapps/__init__.py new file mode 100644 index 0000000..32f26d8
- + 1 # http://packages.python.org/distribute/setuptools.html#namespace-packages 2 try: 3 __import__('pkg_resources').declare_namespace(__name__) 4 except ImportError: 5 from pkgutil import extend_path 6 __path__ = extend_path(__path__, __name__) -
new file tests/regressiontests/admin_scripts/lib1/nsapps/contrib/__init__.py
diff --git a/tests/regressiontests/admin_scripts/lib1/nsapps/contrib/__init__.py b/tests/regressiontests/admin_scripts/lib1/nsapps/contrib/__init__.py new file mode 100644 index 0000000..32f26d8
- + 1 # http://packages.python.org/distribute/setuptools.html#namespace-packages 2 try: 3 __import__('pkg_resources').declare_namespace(__name__) 4 except ImportError: 5 from pkgutil import extend_path 6 __path__ = extend_path(__path__, __name__) -
new file tests/regressiontests/admin_scripts/lib1/nsapps/contrib/app1/management/commands/app1_command1.py
diff --git a/tests/regressiontests/admin_scripts/lib1/nsapps/contrib/app1/__init__.py b/tests/regressiontests/admin_scripts/lib1/nsapps/contrib/app1/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/regressiontests/admin_scripts/lib1/nsapps/contrib/app1/management/__init__.py b/tests/regressiontests/admin_scripts/lib1/nsapps/contrib/app1/management/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/regressiontests/admin_scripts/lib1/nsapps/contrib/app1/management/commands/__init__.py b/tests/regressiontests/admin_scripts/lib1/nsapps/contrib/app1/management/commands/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/regressiontests/admin_scripts/lib1/nsapps/contrib/app1/management/commands/app1_command1.py b/tests/regressiontests/admin_scripts/lib1/nsapps/contrib/app1/management/commands/app1_command1.py new file mode 100644 index 0000000..2f479bb
- + 1 from django.core.management.base import BaseCommand 2 3 class Command(BaseCommand): 4 help = 'Test managment commands in namespaced apps' 5 requires_model_validation = False 6 args = '' 7 8 def handle(self, *labels, **options): 9 print 'EXECUTE:app1_command1' -
new file tests/regressiontests/admin_scripts/lib2/nsapps/__init__.py
diff --git a/tests/regressiontests/admin_scripts/lib1/nsapps/contrib/app1/models.py b/tests/regressiontests/admin_scripts/lib1/nsapps/contrib/app1/models.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/regressiontests/admin_scripts/lib2/nsapps/__init__.py b/tests/regressiontests/admin_scripts/lib2/nsapps/__init__.py new file mode 100644 index 0000000..32f26d8
- + 1 # http://packages.python.org/distribute/setuptools.html#namespace-packages 2 try: 3 __import__('pkg_resources').declare_namespace(__name__) 4 except ImportError: 5 from pkgutil import extend_path 6 __path__ = extend_path(__path__, __name__) -
new file tests/regressiontests/admin_scripts/lib2/nsapps/contrib/__init__.py
diff --git a/tests/regressiontests/admin_scripts/lib2/nsapps/contrib/__init__.py b/tests/regressiontests/admin_scripts/lib2/nsapps/contrib/__init__.py new file mode 100644 index 0000000..32f26d8
- + 1 # http://packages.python.org/distribute/setuptools.html#namespace-packages 2 try: 3 __import__('pkg_resources').declare_namespace(__name__) 4 except ImportError: 5 from pkgutil import extend_path 6 __path__ = extend_path(__path__, __name__) -
new file tests/regressiontests/admin_scripts/lib2/nsapps/contrib/app2/management/commands/app2_command1.py
diff --git a/tests/regressiontests/admin_scripts/lib2/nsapps/contrib/app2/__init__.py b/tests/regressiontests/admin_scripts/lib2/nsapps/contrib/app2/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/regressiontests/admin_scripts/lib2/nsapps/contrib/app2/management/__init__.py b/tests/regressiontests/admin_scripts/lib2/nsapps/contrib/app2/management/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/regressiontests/admin_scripts/lib2/nsapps/contrib/app2/management/commands/__init__.py b/tests/regressiontests/admin_scripts/lib2/nsapps/contrib/app2/management/commands/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/regressiontests/admin_scripts/lib2/nsapps/contrib/app2/management/commands/app2_command1.py b/tests/regressiontests/admin_scripts/lib2/nsapps/contrib/app2/management/commands/app2_command1.py new file mode 100644 index 0000000..b9e20a7
- + 1 from django.core.management.base import BaseCommand 2 3 class Command(BaseCommand): 4 help = 'Test managment commands in namespaced apps' 5 requires_model_validation = False 6 args = '' 7 8 def handle(self, *labels, **options): 9 print 'EXECUTE:app2_command1' -
new file tests/regressiontests/admin_scripts/lib3/_addsitedir.py
diff --git a/tests/regressiontests/admin_scripts/lib2/nsapps/contrib/app2/models.py b/tests/regressiontests/admin_scripts/lib2/nsapps/contrib/app2/models.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/regressiontests/admin_scripts/lib3/_addsitedir.py b/tests/regressiontests/admin_scripts/lib3/_addsitedir.py new file mode 100644 index 0000000..9e264d2
- + 1 import os.path, site; site.addsitedir(os.path.dirname(__file__)) -
new file tests/regressiontests/admin_scripts/lib3/egg_module.pth
diff --git a/tests/regressiontests/admin_scripts/lib3/egg_module.pth b/tests/regressiontests/admin_scripts/lib3/egg_module.pth new file mode 100644 index 0000000..9367ab5
- + 1 test_egg.egg -
new file tests/regressiontests/admin_scripts/lib3/exapps-nspkg.pth
diff --git a/tests/regressiontests/admin_scripts/lib3/exapps-nspkg.pth b/tests/regressiontests/admin_scripts/lib3/exapps-nspkg.pth new file mode 100644 index 0000000..1f31155
- + 1 import sys,new,os; p = os.path.join(sys._getframe(1).f_locals['sitedir'], *('exapps',)); ie = os.path.exists(os.path.join(p,'__init__.py')); m = not ie and sys.modules.setdefault('exapps',new.module('exapps')); mp = (m or []) and m.__dict__.setdefault('__path__',[]); (p not in mp) and mp.append(p) -
new file tests/regressiontests/admin_scripts/lib3/exapps/app3/management/commands/app3_command1.py
diff --git a/tests/regressiontests/admin_scripts/lib3/exapps/app3/__init__.py b/tests/regressiontests/admin_scripts/lib3/exapps/app3/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/regressiontests/admin_scripts/lib3/exapps/app3/management/__init__.py b/tests/regressiontests/admin_scripts/lib3/exapps/app3/management/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/regressiontests/admin_scripts/lib3/exapps/app3/management/commands/__init__.py b/tests/regressiontests/admin_scripts/lib3/exapps/app3/management/commands/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/regressiontests/admin_scripts/lib3/exapps/app3/management/commands/app3_command1.py b/tests/regressiontests/admin_scripts/lib3/exapps/app3/management/commands/app3_command1.py new file mode 100644 index 0000000..97f5d33
- + 1 from django.core.management.base import BaseCommand 2 3 class Command(BaseCommand): 4 help = 'Test managment commands in namespaced apps' 5 requires_model_validation = False 6 args = '' 7 8 def handle(self, *labels, **options): 9 print 'EXECUTE:app3_command1' -
new file tests/regressiontests/admin_scripts/lib3/exapps/app3/models.py
diff --git a/tests/regressiontests/admin_scripts/lib3/exapps/app3/models.py b/tests/regressiontests/admin_scripts/lib3/exapps/app3/models.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/regressiontests/admin_scripts/lib3/test_egg.egg b/tests/regressiontests/admin_scripts/lib3/test_egg.egg new file mode 100644 index 0000000000000000000000000000000000000000..d9e57de006a3d602515293f8e980bf3a16fb42c0 GIT binary patch literal 2210 zcmWIWW@Zs#W&na+g#z{<8U{Fl3|Dt|T~9wZfBgWcG7g3{KxHDAuKle5O78$-K~!ZB z^|5C+avd@dV0&QeKT+IcWwzNt$AHBOuWGiW^E|0~S|nLhZ9Ow6Z`b?h&-X7l#KHBh zGf2q)-n(7*SQNg9C6^pYKAZ6`^S*BSyQv&cUcXhIbLgw+nTectc?6~3uC9yNw%@sF z%ItZU8-gRR@<p(DZr01@&6oUg*2%XH)tT;p3*R&VooCL-z#xL`%wYe}AZOQLy^@NO zseK1QE_HeT&--$}fT-Y_2pj#SlFkL2Ia9R1z3&YW$hEDwHMjD;fuxnn<YS_977M&R zu%dHMh3c<Wrx~B0zcgk0r=s4kFE_0Ic06}8$L(iDarse;`D34maV9DL^?37iT78$4 zu;IH0CoB42FDd2_n0t1<bS;nS%|HFW4h3s`69&1M3mpESfSt^C-3aJd1`w7-c5zB- zL26z~YF=_>d`@Owb}`85T&Q|ip0Nz)2I>J}F=V|Z`33Pgsb#4-AWf<1>G8SwDWy57 zXxfpjMv2p^%mUrw#59O{NK!eBmQ+AiA`Av67Koo#6`-amkh_o+#>Z#oWtPOp>lIYO zVvd0U-EcHLxrup+>8ZJ?c_m2p+{#0>M-kN?Bt1k~DUVZoa(*t*u#{pvc54yVjKvWg z3_F2gHQm(j`*xsy9$*5{C2S5TD4{L_2BB}CcONJzf46gee`Y}-UxUeP$C<(gLc3RV zY9Cwi_n@qWz2AwZxYCuY=4Gw2oV2^}(@yDPS8>aY?k=--b8BlHne^Ic|6BWKH)7Jy zXsq#?eWx}ep56KFx(QD9DgGB`hCMj6_@itPSErDB#zVor9U@z^*FXBlA!>Exjl$u{ zsuuH{{dm6}Ulb7>vsbSqJM5*w#jS~~)~!DGw}|g^*kb!TX4*Er&D*q1x2SHj|9<>` zaDBt~!)B*vi6f<AwA2F1vq-50m~2yXiot1xkx7IZcc}%`1_S~P2OL2(QW*x*hP@O6 zDP~|$XxP%I4y2K^LCUlMZ&dB*r3+X$So=9-?MP(}#01>A9brNPF#h2Vz?S#XjY7}- z2&48O8--F7pqqhS0wB!zjcf+2JV1m8W}XEV2oL~@1#Kpjcto}rTLA&l2#SXgRE;Rv z1{N8ZmV*im2mo2$focX)QGo0YYy}9!43Ina;536sCxHqS2mm?hH%{Y_iWiXoAV~$? zZJ+`M0zhuF09GEznFLWh!VSafNbCg;!rTVJ=Asrq$icY=OHM`@-Nb_GWJJDZWdo_= P1Hv0X>$d>aF)#oC`tnrE
-
tests/regressiontests/admin_scripts/tests.py
literal 0 HcmV?d00001 diff --git a/tests/regressiontests/admin_scripts/tests.py b/tests/regressiontests/admin_scripts/tests.py index ed4bd35..67b597e 100644
a b class AdminScriptTestCase(unittest.TestCase): 84 84 test_dir = os.path.dirname(os.path.dirname(__file__)) 85 85 project_dir = os.path.dirname(test_dir) 86 86 base_dir = os.path.dirname(project_dir) 87 lib1_dir = os.path.join(os.path.dirname(__file__), 'lib1') 88 lib2_dir = os.path.join(os.path.dirname(__file__), 'lib2') 89 lib3_dir = os.path.join(os.path.dirname(__file__), 'lib3') 90 eggs_dir = os.path.join(os.path.dirname(__file__), 'eggs') 87 91 ext_backend_base_dirs = self._ext_backend_paths() 88 92 89 93 # Remember the old environment … … class AdminScriptTestCase(unittest.TestCase): 101 105 os.environ['DJANGO_SETTINGS_MODULE'] = settings_file 102 106 elif 'DJANGO_SETTINGS_MODULE' in os.environ: 103 107 del os.environ['DJANGO_SETTINGS_MODULE'] 104 python_path = [test_dir, base_dir ]108 python_path = [test_dir, base_dir, lib1_dir, lib2_dir, lib3_dir] 105 109 python_path.extend(ext_backend_base_dirs) 106 110 os.environ[python_path_var_name] = os.pathsep.join(python_path) 107 111 … … class ArgumentOrder(AdminScriptTestCase): 1291 1295 out, err = self.run_manage(args) 1292 1296 self.assertNoOutput(err) 1293 1297 self.assertOutput(out, "EXECUTE:BaseCommand labels=('testlabel',), options=[('option_a', 'x'), ('option_b', 'y'), ('option_c', '3'), ('pythonpath', None), ('settings', 'alternate_settings'), ('traceback', None), ('verbosity', '1')]") 1298 1299 class NamespacePackagedApps(AdminScriptTestCase): 1300 def setUp(self): 1301 self.write_settings('settings.py', apps=['nons_app', 'nsapps.contrib.app1','nsapps.contrib.app2','exapps.app3', 'egg_module']) 1302 test_dir = os.path.dirname(os.path.dirname(__file__)) 1303 settings_file = open(os.path.join(test_dir, 'settings.py'), 'a') 1304 settings_file.write('import _addsitedir') 1305 settings_file.close() 1306 1307 def tearDown(self): 1308 self.remove_settings('settings.py') 1309 1310 def test_help(self): 1311 out, err = self.run_manage(['help']) 1312 self.assertOutput(err, "nons_app_command1") 1313 self.assertOutput(err, "app1_command1") 1314 self.assertOutput(err, "app2_command1") 1315 self.assertOutput(err, "app3_command1") 1316 self.assertOutput(err, "egg_command") 1317 1318 def test_nons_app(self): 1319 args = ['nons_app_command1'] 1320 out, err = self.run_manage(args) 1321 self.assertNoOutput(err) 1322 self.assertOutput(out, "EXECUTE:nons_app_command1") 1323 1324 def test_nsapps(self): 1325 args = ['app1_command1'] 1326 out, err = self.run_manage(args) 1327 self.assertNoOutput(err) 1328 self.assertOutput(out, "EXECUTE:app1_command1") 1329 1330 args = ['app2_command1'] 1331 out, err = self.run_manage(args) 1332 self.assertNoOutput(err) 1333 self.assertOutput(out, "EXECUTE:app2_command1") 1334 1335 def test_exapps(self): 1336 args = ['app3_command1'] 1337 out, err = self.run_manage(args) 1338 self.assertNoOutput(err) 1339 self.assertOutput(out, "EXECUTE:app3_command1") 1340 1341 class PreloadedNamespacePackagedApps(AdminScriptTestCase): 1342 def setUp(self): 1343 self.write_settings('settings.py', apps=['nsapps.contrib.app1','nsapps.contrib.app2']) 1344 test_dir = os.path.dirname(os.path.dirname(__file__)) 1345 settings_file = open(os.path.join(test_dir, 'settings.py'), 'a') 1346 settings_file.write('import nsapps') 1347 settings_file.close() 1348 1349 def tearDown(self): 1350 self.remove_settings('settings.py') 1351 1352 def test_help(self): 1353 out, err = self.run_manage(['help']) 1354 self.assertOutput(err, "app1_command1") 1355 self.assertOutput(err, "app2_command1") 1356 1357 1358 def test_nsapps(self): 1359 args = ['app1_command1'] 1360 out, err = self.run_manage(args) 1361 self.assertNoOutput(err) 1362 self.assertOutput(out, "EXECUTE:app1_command1") 1363 1364 args = ['app2_command1'] 1365 out, err = self.run_manage(args) 1366 self.assertNoOutput(err) 1367 self.assertOutput(out, "EXECUTE:app2_command1") 1368 1369 1370 1371