def _raw_import(path):
# First, invalidate caches!
# From the docs:
# "If you are dynamically importing a module that was created since the interpreter began execution
# (e.g., created a Python source file), you may need to call invalidate_caches() in order for the
# new module to be noticed by the import system."
# Since we're dealing with config files, we need to support re-reading config files
# which are modified after the interpreter started.
# See:
# https://docs.python.org/3/library/importlib.html#importlib.import_module
# https://docs.python.org/3/library/importlib.html#importlib.invalidate_caches
try:
invalidate_caches = importlib.invalidate_caches
except AttributeError:
# python2
pass
else:
# python3
invalidate_caches()
# Now can safely import the module
return importlib.import_module(path)
评论列表
文章目录