Ticket #8280: zip_egg_fixed.diff
File zip_egg_fixed.diff, 10.1 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 1214a82..88d3945 100644
a b import os 3 3 import sys 4 4 from optparse import OptionParser, NO_DEFAULT 5 5 import imp 6 import pkgutil 6 7 import warnings 7 8 8 9 from django.core.management.base import BaseCommand, CommandError, handle_default_options 9 10 from django.core.management.color import color_style 10 from django.utils.importlib import import_module 11 from django.utils.importlib import import_module, find_package_path 11 12 12 13 # For backwards compatibility: get_version() used to be in this module. 13 14 from django import get_version … … def find_commands(management_dir): 23 24 24 25 Returns an empty list if no commands are defined. 25 26 """ 26 command_dir = os.path.join(management_dir, 'commands')27 27 try: 28 return [f[:-3] for f in os.listdir(command_dir) 29 if not f.startswith('_') and f.endswith('.py')] 30 except OSError: 28 commands_dir = find_package_path('commands', [management_dir])[0] 29 return [name for loader,name,ispkg in pkgutil.iter_modules([commands_dir]) 30 if not name.startswith('_') ] 31 except ImportError: 31 32 return [] 32 33 33 34 def find_management_module(app_name): … … def find_management_module(app_name): 54 55 else: 55 56 parts.reverse() 56 57 part = parts.pop() 57 path = sys.path58 path = None 58 59 59 60 # When using manage.py, the project module is added to the path, 60 61 # loaded, then removed from the path. This means that … … def find_management_module(app_name): 63 64 # module, we need look for the case where the project name is part 64 65 # of the app_name but the project directory itself isn't on the path. 65 66 try: 66 next_path = [] 67 for p in path: 68 try: 69 next_path.append(imp.find_module(part, [p])[1]) 70 except ImportError: 71 pass 72 if not next_path: 73 raise ImportError("No module named %s" % part) 74 path = next_path 67 path = find_package_path(part, path) 75 68 except ImportError,e: 76 69 if os.path.basename(os.getcwd()) != part: 77 70 raise e 78 71 79 72 while parts: 80 73 part = parts.pop() 81 next_path = [] 82 for p in path: 83 try: 84 next_path.append(imp.find_module(part, [p])[1]) 85 except ImportError: 86 pass 87 if not next_path: 88 raise ImportError("No module named %s" % part) 89 path = next_path 90 74 path = find_package_path(part, path) 91 75 return path[0] 92 76 93 77 def load_command_class(app_name, name): -
django/utils/importlib.py
diff --git a/django/utils/importlib.py b/django/utils/importlib.py index ef4d0e4..f53abd9 100644
a b 1 1 # Taken from Python 2.7 with permission from/by the original author. 2 import os 2 3 import sys 4 import imp 5 import pkgutil 6 import warnings 3 7 4 8 def _resolve_name(name, package, level): 5 9 """Return the absolute name of the module to be imported.""" … … def import_module(name, package=None): 34 38 name = _resolve_name(name[level:], package, level) 35 39 __import__(name) 36 40 return sys.modules[name] 41 42 43 def find_package_path(name, path=None): 44 """Finds search path for package with given name. 45 46 The 'path' argument defaults to ``sys.path``. 47 48 Raises ImportError if no search path could be found. 49 """ 50 if path is None: 51 path = sys.path 52 53 results = [] 54 55 for path_item in path: 56 importer = get_importer(path_item) 57 58 if importer is None: 59 continue 60 61 try: 62 loader = importer.find_module(name) 63 64 if loader is not None: 65 66 if not hasattr(loader, 'is_package'): 67 warnings.warn( 68 "Django cannot find search path for package '%s' ", 69 "under '%s', because the loader returned by '%s' does ", 70 "not implement 'is_package' method."%( 71 name, 72 path_item, 73 importer.__class__.__name__)) 74 continue 75 76 if not hasattr(loader, 'get_filename'): 77 warnings.warn( 78 "Django cannot find search path for package '%s' ", 79 "under '%s', because the loader returned by '%s' does ", 80 "not implement 'get_filename' method."%( 81 name, 82 path_item, 83 importer.__class__.__name__)) 84 continue 85 86 if loader.is_package(name): 87 results.append(os.path.dirname(loader.get_filename(name))) 88 except ImportError: 89 pass 90 91 if not results: 92 raise ImportError("No package named %s" % name) 93 94 return results 95 96 97 get_importer = pkgutil.get_importer 98 99 try: 100 import zipimport 101 102 if hasattr(zipimport.zipimporter, 'get_filename'): 103 class ZipImporter(zipimport.zipimporter): 104 def get_filename(self, fullname): 105 archivepath = os.path.join(self.archive, self.prefix) 106 if self.is_package(fullname): 107 return os.path.join(archivepath, fullname, '__init__.py') 108 109 return os.path.join(archivepath, fullname + '.py') 110 111 def get_importer(path_item): 112 importer = pkgutil.get_importer(path_item) 113 114 if isinstance(importer, zipimport.zipimporter): 115 archivepath = os.path.join(importer.archive, importer.prefix) 116 importer = ZipImporter(os.path.dirname(archivepath)) 117 118 return importer 119 120 except ImportError: 121 pass 122 123 -
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/test_egg.egg
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 45852ba..1240ca4 100644
a b class AdminScriptTestCase(unittest.TestCase): 93 93 lib1_dir = os.path.join(os.path.dirname(__file__), 'lib1') 94 94 lib2_dir = os.path.join(os.path.dirname(__file__), 'lib2') 95 95 lib3_dir = os.path.join(os.path.dirname(__file__), 'lib3') 96 eggs_dir = os.path.join(os.path.dirname(__file__), 'eggs') 96 97 ext_backend_base_dirs = self._ext_backend_paths() 97 98 98 99 # Remember the old environment … … class StartProject(LiveServerTestCase, AdminScriptTestCase): 1558 1559 1559 1560 class NamespacePackagedApps(AdminScriptTestCase): 1560 1561 def setUp(self): 1561 self.write_settings('settings.py', apps=['nons_app', 'nsapps.contrib.app1','nsapps.contrib.app2','exapps.app3']) 1562 test_dir = os.path.dirname(os.path.dirname(__file__)) 1562 self.write_settings('settings.py', apps=['nons_app', 'nsapps.contrib.app1','nsapps.contrib.app2','exapps.app3', 'egg_module']) 1563 1563 settings_file = open(os.path.join(test_dir, 'settings.py'), 'a') 1564 1564 settings_file.write('import _addsitedir') 1565 1565 settings_file.close() … … class NamespacePackagedApps(AdminScriptTestCase): 1574 1574 self.assertOutput(out, "app1_command1") 1575 1575 self.assertOutput(out, "app2_command1") 1576 1576 self.assertOutput(out, "app3_command1") 1577 self.assertOutput(out, "egg_command") 1577 1578 1578 1579 def test_nons_app(self): 1579 1580 args = ['nons_app_command1'] … … class NamespacePackagedApps(AdminScriptTestCase): 1598 1599 self.assertNoOutput(err) 1599 1600 self.assertOutput(out, "EXECUTE:app3_command1") 1600 1601 1602 def test_exapps(self): 1603 args = ['egg_command'] 1604 out, err = self.run_manage(args) 1605 self.assertNoOutput(err) 1606 self.assertOutput(out, "EXECUTE:egg_command") 1607 1608 1601 1609 class PreloadedNamespacePackagedApps(AdminScriptTestCase): 1602 1610 def setUp(self): 1603 1611 self.write_settings('settings.py', apps=['nsapps.contrib.app1','nsapps.contrib.app2']) 1604 test_dir = os.path.dirname(os.path.dirname(__file__))1605 1612 settings_file = open(os.path.join(test_dir, 'settings.py'), 'a') 1606 1613 settings_file.write('import nsapps') 1607 1614 settings_file.close()