Ticket #8413: 8413.patch
File 8413.patch, 3.2 KB (added by , 16 years ago) |
---|
-
django/utils/autoreload.py
diff --git a/django/utils/autoreload.py b/django/utils/autoreload.py index 8d9d6f2..c878a51 100644
a b 27 27 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 28 28 # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 29 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 from ihooks import ModuleImporter, ModuleLoader 31 import ihooks 30 32 31 import os, sys, time 32 33 import os, sys, time, imp 33 34 try: 34 35 import thread 35 36 except ImportError: … … try: 42 43 except ImportError: 43 44 pass 44 45 46 try: 47 set 48 except NameError: 49 from sets import Set as set # For Python 2.3 45 50 46 51 RUN_RELOADER = True 47 52 48 53 _mtimes = {} 49 54 _win = (sys.platform == "win32") 50 55 56 class ModuleLoaderHook(ModuleLoader): 57 __caught = set() 58 def __init__(self, hooks = None, verbose = False): 59 ModuleLoader.__init__(self, hooks, verbose) 60 before = filter(lambda v: v, map(lambda m: getattr(m, "__file__", None), sys.modules.values())) 61 for filename in before: 62 self.note('Already loaded %s', filename) 63 ModuleLoaderHook.__caught = set(before) 64 65 def tracked(self): 66 return list(self.__caught) 67 68 def load_module(self, name, stuff): 69 file, filename, info = stuff 70 if filename: 71 if info[2] == imp.PKG_DIRECTORY: 72 filename = filename+os.sep+'__init__.py' 73 #DEBUG information, please remove 74 if not filename in self.__caught: 75 self.note('Caught %s', filename) 76 self.__caught.add(filename) 77 return ModuleLoader.load_module(self, name, stuff) 78 79 class ModuleImporterHook(ModuleImporter): 80 def ensure_fromlist(self, m, fromlist, recursive=0): 81 try: 82 ModuleImporter.ensure_fromlist(self, m, fromlist, recursive) 83 except ValueError: 84 # It's recommended to fix django to never reach this place 85 # and remove this except case, see http://bugs.python.org/issue2090 86 # and related django bugs: #6587 and #6579 87 # XXX: Turn it on to catch empty-name module imports. 88 # print 'Importing empty module with __import__:', m.__name__ 89 pass 90 except ImportError: 91 # ihooks catches missing fromlist imports by default 92 pass 93 94 loader = None 95 def hook_imports(verbose=False): 96 global loader 97 loader = ModuleLoaderHook() 98 importer = ModuleImporterHook(loader=loader, verbose=verbose) 99 ihooks.install(importer) 100 51 101 def code_changed(): 52 102 global _mtimes, _win 53 for filename in filter(lambda v: v, map(lambda m: getattr(m, "__file__", None), sys.modules.values())): 103 files = filter(lambda v: v, map(lambda m: getattr(m, "__file__", None), sys.modules.values())) 104 if loader: 105 files = loader.tracked() 106 for filename in files: 54 107 if filename.endswith(".pyc") or filename.endswith(".pyo"): 55 108 filename = filename[:-1] 56 109 if not os.path.exists(filename): … … def jython_reloader(main_func, args, kwargs): 107 160 108 161 109 162 def main(main_func, args=None, kwargs=None): 163 hook_imports() 110 164 if args is None: 111 165 args = () 112 166 if kwargs is None: