def load_module(self, fullname):
"""
Loads the source for a module found at `fullname`.
For most of the module path here, we're going to be generating
placeholders that don't actually have code; they'd be the equivalent of
a bunch of empty dirs with __init__.py's, but ansible doesn't have the
init file in the path.
"""
if fullname in sys.modules:
mod = sys.modules[fullname]
else:
mod = sys.modules.setdefault(fullname, imp.new_module(fullname))
mod.__file__ = os.path.join(self.path, fullname)
mod.__loader__ = self
mod.__path__ = [self.path]
mod.__package__ = '.'.join(fullname.split('.')[:-1])
# We don't want to actually load unless we get to the Python code.
# This is assuming that the guards in the __init__() function worked
if self.basename not in ANSIBLE_DIRS and self.basename not in PLUGINS:
mod = imp.load_source(self.basename, self.path + self.extension)
return mod
评论列表
文章目录