def get_module(cmd_name): """Imports the module for a particular command name and returns it. Parameters ---------- cmd_name : str name of the command for which to get a module (contains ``-``, not ``_``). """ pname = python_name(cmd_name) # Import the command from the built-in directory module_name = "{0}.{1}".format(__name__, pname) module = __import__(module_name, fromlist=[pname, SETUP_PARSER, DESCRIPTION], level=0) tty.debug("Imported {0} from built-in commands".format(pname)) attr_setdefault(module, SETUP_PARSER, lambda *args: None) # null-op attr_setdefault(module, DESCRIPTION, "") if not hasattr(module, pname): # pragma: no cover tty.die("Command module {0} ({1}) must define function {2!r}.".format( module.__name__, module.__file__, pname)) return module
def get_module(cmd_name): """Imports the module for a particular command name and returns it. Args: cmd_name (str): name of the command for which to get a module (contains ``-``, not ``_``). """ require_cmd_name(cmd_name) pname = python_name(cmd_name) try: # Try to import the command from the built-in directory module_name = "%s.%s" % (__name__, pname) module = __import__(module_name, fromlist=[pname, SETUP_PARSER, DESCRIPTION], level=0) tty.debug('Imported {0} from built-in commands'.format(pname)) except ImportError: module = spack.extensions.get_module(cmd_name) attr_setdefault(module, SETUP_PARSER, lambda *args: None) # null-op attr_setdefault(module, DESCRIPTION, "") if not hasattr(module, pname): tty.die("Command module %s (%s) must define function '%s'." % (module.__name__, module.__file__, pname)) return module
def get_command_module_from(cmd_name, namespace): """Imports the module for a particular command from the specified namespace. Args: cmd_name (str): name of the command for which to get a module (contains ``-``, not ``_``). namespace (str): namespace for command. Invoke this from command implementations in order to find sub-commands. """ spack.cmd.require_cmd_name(cmd_name) pname = spack.cmd.python_name(cmd_name) module_name = '{0}.cmd.{1}'.format(namespace, pname) module = __import__(module_name, fromlist=[pname, SETUP_PARSER, DESCRIPTION], level=0) tty.debug('Imported command {0} as {1}'.format(cmd_name, module_name)) attr_setdefault(module, SETUP_PARSER, lambda *args: None) # null-op attr_setdefault(module, DESCRIPTION, "") if not hasattr(module, pname): tty.die("Command module %s (%s) must define function '%s'." % (module.__name__, module.__file__, pname)) return module
def get_module(name): """Imports the module for a particular command name and returns it.""" module_name = "%s.%s" % (__name__, name) module = __import__( module_name, fromlist=[name, SETUP_PARSER, DESCRIPTION], level=0) attr_setdefault(module, SETUP_PARSER, lambda *args: None) # null-op attr_setdefault(module, DESCRIPTION, "") fn_name = get_cmd_function_name(name) if not hasattr(module, fn_name): tty.die("Command module %s (%s) must define function '%s'." % (module.__name__, module.__file__, fn_name)) return module
def get_module(name): """Imports the module for a particular command name and returns it.""" module_name = "%s.%s" % (__name__, name) module = __import__(module_name, fromlist=[name, SETUP_PARSER, DESCRIPTION], level=0) attr_setdefault(module, SETUP_PARSER, lambda *args: None) # null-op attr_setdefault(module, DESCRIPTION, "") fn_name = get_cmd_function_name(name) if not hasattr(module, fn_name): tty.die("Command module %s (%s) must define function '%s'." % (module.__name__, module.__file__, fn_name)) return module
def get_module(cmd_name): """Imports the module for a particular command name and returns it. Args: cmd_name (str): name of the command for which to get a module (contains ``-``, not ``_``). """ pname = python_name(cmd_name) module_name = "%s.%s" % (__name__, pname) module = __import__(module_name, fromlist=[pname, SETUP_PARSER, DESCRIPTION], level=0) attr_setdefault(module, SETUP_PARSER, lambda *args: None) # null-op attr_setdefault(module, DESCRIPTION, "") if not hasattr(module, pname): tty.die("Command module %s (%s) must define function '%s'." % (module.__name__, module.__file__, pname)) return module
def get_module(cmd_name): """Imports the module for a particular command name and returns it. Args: cmd_name (str): name of the command for which to get a module (contains ``-``, not ``_``). """ pname = python_name(cmd_name) module_name = "%s.%s" % (__name__, pname) module = __import__(module_name, fromlist=[pname, SETUP_PARSER, DESCRIPTION], level=0) attr_setdefault(module, SETUP_PARSER, lambda *args: None) # null-op attr_setdefault(module, DESCRIPTION, "") if not hasattr(module, pname): tty.die("Command module %s (%s) must define function '%s'." % (module.__name__, module.__file__, pname)) return module
def get_module(cb_name): """Imports the module for a particular callback name and returns it. Parameters ---------- cb_name : str name of the callback for which to get a module (contains ``-``, not ``_``). """ # Import the callback from the built-in directory module_name = "{0}.{1}".format(__name__, cb_name) module = __import__(module_name, fromlist=[cb_name, CATEGORY], level=0) attr_setdefault(module, CATEGORY, "") if not hasattr(module, cb_name): # pragma: no cover tty.die( "callback module {0} ({1}) must define function {2!r}.".format( module.__name__, module.__file__, cb_name ) ) return module