def _Import_All (self, mod_skip_pat = None) : """Import all modules of this package namespace""" from _TFL.import_module import import_module ### avoid circular imports from _TFL import sos dir = sos.path.dirname (self.__file__) pns = self.__module_name for f in sos.listdir (dir) : is_py = f.endswith (".py") want = \ ( ( is_py or sos.path.exists (sos.path.join (dir, f, "__init__.py")) ) and not ( f.startswith (("__", ".")) or f == "setup.py" or ( mod_skip_pat.search (f) if mod_skip_pat is not None else False ) ) ) if want : mn = f [:-3] if is_py else f mod = ".".join ((pns, mn)) try : import_module (mod) except Exception as exc : logging.exception \ ( "%s._Import_All: " "exception during import of %s\n %s" % (self.__name__, mn, exc) )
def new_plugin (cls, name) : from _TFL.Environment import script_path, frozen from _TFL.Filename import Filename from _TFL.import_module import import_module if frozen () : plain_name = name.rsplit ("_", 3) [0] ### XXX cls.plain_to_version [plain_name] = name pkg_name = "_Plugins._%s" % (plain_name, ) tooldir = script_path () plugin_dir = os.path.join (tooldir, "_Plugins") if not hasattr (cls, plugin_dir) : cls.plugin_dir = plugin_dir directory = os.path.join (plugin_dir, "_%s" % name) cls._run_setup (directory, name) module = import_module (pkg_name) return directory, module, plain_name else : pkg_name = "_Plugins._%s" % (name, ) module = import_module (pkg_name) directory = Filename (module.__file__).directory return directory, module, name
def _gen_template_dirs (self, defaults) : yield self.app_dir tpds = defaults.get ("template_package_dirs", ["_JNJ"]) for tpd in tpds : mod = import_module (tpd) yield sos.path.dirname (mod.__file__)
def _Import_Module (self, name) : """Import module `name` from this package namespace""" from _TFL.import_module import import_module ### avoid circular imports return import_module (".".join ((self.__module_name, name)))