1 """Core modules package for the mudpy engine."""
3 # Copyright (c) 2004-2019 mudpy authors. Permission to use, copy,
4 # modify, and distribute this software is granted under terms
5 # provided in the LICENSE file distributed with this software.
13 """Import/reload some modules (be careful, as this can result in loops)."""
15 # hard-coded fallback list of modules expected in this package
16 # TODO(fungi) remove this once Python 3.6 is no longer supported
28 # dynamically build module list from package contents (this only works
29 # in Python 3.7 and later, hence the try/except)
31 for module in mudpy.__loader__.contents():
34 # make sure it's a module file, not a directory
35 module.endswith('.py')
37 # don't include this file, we're inside it
38 and module != '__init__.py'):
40 # trim off the .py file extension
41 modules.append(module[:-3])
43 # make sure the fallback list is kept up to date with package contents
44 if fallback_modules != sorted(modules):
45 raise Exception("Fallback module list is incomplete")
47 except AttributeError:
48 modules = fallback_modules
50 # iterate over the list of module files included in the package
51 for module in modules:
53 # attempt to reload the module, assuming it was probably imported
56 importlib.reload(getattr(mudpy, module))
58 # must not have been, so import it now
59 except AttributeError:
60 importlib.import_module("mudpy.%s" % module)