Fix reload to use mod.__cache__ to get name of pyc files
This commit is contained in:
parent
7a154f74fa
commit
0bc186fe7d
@ -46,26 +46,32 @@ def reloadAll(prefix=None, debug=False):
|
|||||||
if modName == '__main__':
|
if modName == '__main__':
|
||||||
continue
|
continue
|
||||||
|
|
||||||
## Ignore if the file name does not start with prefix
|
# Ignore modules without a __file__ that is .py or .pyc
|
||||||
if not hasattr(mod, '__file__') or mod.__file__ is None or os.path.splitext(mod.__file__)[1] not in ['.py', '.pyc']:
|
if not hasattr(mod, '__file__') or mod.__file__ is None or os.path.splitext(mod.__file__)[1] not in ['.py', '.pyc']:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
# Ignore if the file name does not start with prefix
|
||||||
if prefix is not None and mod.__file__[:len(prefix)] != prefix:
|
if prefix is not None and mod.__file__[:len(prefix)] != prefix:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
## ignore if the .pyc is newer than the .py (or if there is no pyc or py)
|
|
||||||
py = os.path.splitext(mod.__file__)[0] + '.py'
|
py = os.path.splitext(mod.__file__)[0] + '.py'
|
||||||
pyc = py + 'c'
|
if not os.path.isfile(py):
|
||||||
if py not in changed and os.path.isfile(pyc) and os.path.isfile(py) and os.stat(pyc).st_mtime >= os.stat(py).st_mtime:
|
# skip modules that lie about their __file__
|
||||||
#if debug:
|
|
||||||
#print "Ignoring module %s; unchanged" % str(mod)
|
|
||||||
continue
|
continue
|
||||||
changed.append(py) ## keep track of which modules have changed to insure that duplicate-import modules get reloaded.
|
|
||||||
|
|
||||||
try:
|
# if source file is newer than cache file, then it needs to be reloaded.
|
||||||
reload(mod, debug=debug)
|
pyc = getattr(mod, '__cached__', py + 'c')
|
||||||
except:
|
if not os.path.isfile(pyc):
|
||||||
printExc("Error while reloading module %s, skipping\n" % mod)
|
continue
|
||||||
failed.append(mod.__name__)
|
|
||||||
|
if py not in changed and os.stat(pyc).st_mtime < os.stat(py).st_mtime:
|
||||||
|
changed.append(py) ## keep track of which modules have changed to insure that duplicate-import modules get reloaded.
|
||||||
|
|
||||||
|
try:
|
||||||
|
reload(mod, debug=debug)
|
||||||
|
except:
|
||||||
|
printExc("Error while reloading module %s, skipping\n" % mod)
|
||||||
|
failed.append(mod.__name__)
|
||||||
|
|
||||||
if len(failed) > 0:
|
if len(failed) > 0:
|
||||||
raise Exception("Some modules failed to reload: %s" % ', '.join(failed))
|
raise Exception("Some modules failed to reload: %s" % ', '.join(failed))
|
||||||
|
Loading…
Reference in New Issue
Block a user