Load commands defined within a pkg_resources entry point.

        Each entry will be a module that should be searched for functions
        decorated with the :func:`subparse.command` decorator. This
        operation is not recursive.
964497
def load_commands_from_entry_point(self, specifier):
        
        for ep in pkg_resources.iter_entry_points(specifier):
            module = ep.load()
            command.discover_and_call(module, self.command)
350231
def _load_commands(root):
    """"""
    def proto_text(t):
        if t.tag == 'name':
            return '{name}'
        elif t.tag == 'ptype':
            return '{type}'
        out = []
        if t.text:
            out.append(_escape_tpl_str(t.text))
        for x in t:
            out.append(proto_text(x))
            if x.tail:
                out.append(_escape_tpl_str(x.tail))
        return ''.join(out)
    out = collections.OrderedDict()
    for elem in root.findall('commands/command'):
        type_elem = elem.find('proto/ptype')
        name = elem.get('name') or elem.find('proto/name').text
        type = type_elem.text if type_elem is not None else None
        proto_template = proto_text(elem.find('proto'))
        params = [_load_param(x) for x in elem.findall('param')]
        comment = elem.get('comment')
        out[name] = Command(name, type, proto_template, params, comment)
    return out
960500
def load(force=False):
    

    if GRAFTS and not force:
        return GRAFTS

    # insert missing paths
    # this could be a configurated item
    userpath = settings.userpath
    if os.path.isdir(userpath) and userpath not in __path__:
        __path__.append(userpath)

    def notify_error(name):
        logging.error('unable to load %s package' % name)

    # autoload decorated functions
    walker = walk_packages(__path__, '%s.' % __name__, onerror=notify_error)
    for module_finder, name, ispkg in walker:
        loader = module_finder.find_module(name)
        mod = loader.load_module(name)
        for func in mod.__dict__.values():
            if is_graft(func):
                GRAFTS.append(func)

    # append setuptools modules
    for entry_point in iter_entry_points(group=settings.entry_point):
        try:
            func = entry_point.load()
            if is_graft(func):
                GRAFTS.append(func)
            else:
                notify_error(entry_point.name)
        except Exception as error:
            logging.exception(error)
            notify_error(entry_point.name)

    return GRAFTS
356351
def find_commands_module(app_name):
    
    parts = app_name.split('.')
    parts.append('commands')
    parts.reverse()
    part = parts.pop()
    path = None

    #Load the module if needed
    try:
        f, path, descr = imp.find_module(part, path)
    except ImportError as e:
        if os.path.basename(os.getcwd()) != part:
            raise e
        else:
            try:
                if f:
                    f.close()
            except UnboundLocalError:
                log.error("Could not import module {0} at path {1}.  Sys.path is {2}".format(part, path, sys.path))

    #Go down level by and level and try to load the module at each level
    while parts:
        part = parts.pop()
        f, path, descr = imp.find_module(part, [path] if path else None)
        if f:
            f.close()
    return path
476186
def load(description, add_arguments_cb = lambda x: None, postprocess_conf_cb = lambda x: None):
        

        argparser = ArgumentParser(
            description = description,
            prefix_chars = '-+'
        )

        argparser.add_argument(
            '--version',
            dest = 'PRINT_VERSION',
            action = 'store_true',
            help = 'Print version and exit'
        )

        add_arguments_cb(argparser)

        # set up plugin argument argparser
        plugin_argparser = argparser.add_argument_group('Plugins')

        plugins = {}
        def load_plugin_group(group):
            """Load all plugins from the given plugin_group."""
            for entry_point in iter_entry_points(group = group):
                name = str(entry_point).split(' =',1)[0]
                plugin = entry_point.load()
                if isclass(plugin) \
                    and not plugin in Conf.SUPPORTED_PLUGIN_INTERFACES \
                    and any([
                        issubclass(plugin, supported_plugin_interface)
                        for supported_plugin_interface in Conf.SUPPORTED_PLUGIN_INTERFACES
                    ]):

                    plugin_argparser.add_argument(
                        '+{}'.format(name),
                        dest = 'PLUGIN_{}'.format(name),
                        type = str,
                        nargs = '?',
                        default = DEFAULT,
                        metavar = 'args'.format(name),
                        help = make_argparse_help_safe(
                            call_plugin(
                                plugin,
                                'help'
                            )
                        )
                    )

                    # register plugin
                    plugins[name] = plugin
                else:
                    warning('Plugin not supported: {}'.format(name))

        load_plugin_group(Conf.PLUGIN_GROUP_BASE)
        if Conf.LOAD_PLUGINS:
            load_plugin_group(Conf.PLUGIN_GROUP)

        conf = vars(
            argparser.parse_args([
                v if i == 0 or v[0] == '+' or Conf.ARGS[i-1][0] != '+'
                else b32encode(v.encode()).decode()
                for i, v in enumerate(Conf.ARGS)
            ])
        )

        postprocess_conf_cb(conf)

        # apply configuration
        Conf.set(conf)

        if Conf.PRINT_VERSION:
            print(
                'pdml2flow version {}'.format(
                    Conf.VERSION
                ),
                file = Conf.OUT
            )
            sys.exit(0)

        # initialize plugins
        Conf.PLUGINS = []
        for conf_name, args in conf.items():
            if conf_name.startswith('PLUGIN_') and args != DEFAULT:
                plugin_name = conf_name[7:]
                Conf.PLUGINS.append(
                    # instantiate plugin
                    plugins[plugin_name](
                        *split(
                            b32decode(args.encode()).decode() if args is not None else ''
                        )
                    )
                )
1121434
def load(self, require=True, *args, **kwargs):
        
        if not require or args or kwargs:
            warnings.warn(
                "Parameters to load are deprecated.  Call .resolve and "
                ".require separately.",
                PkgResourcesDeprecationWarning,
                stacklevel=2,
            )
        if require:
            self.require(*args, **kwargs)
        return self.resolve()
1325798
def command(self, *args, **kwargs):
        
        def decorator(f):
            cmd = command(*args, **kwargs)(f)
            self.add_command(cmd)
            return cmd
        return decorator
349954
function loadCommand(name, command, silent) {
    var resource = app.commands[name];
    var usage = app.usage || [
      name
        ? 'Cannot find commands for ' + name.magenta
        : 'Cannot find commands'
    ];

    if (resource && (!command || resource[command])) {
      return true;
    }

    if (app.cli.source) {
      if (!app.cli.sourceDir) {
        try {
          var stats = fs.statSync(app.cli.source);
          app.cli.sourceDir = stats.isDirectory();
        }
        catch (ex) {
          if (app.cli.notFoundUsage) {
            showUsage(usage)
          }

          return false;
        }
      }

      try {
        if (app.cli.sourceDir) {
          app.commands[name] = require(path.join(app.cli.source, name || ''));
        }
        else {
          app.commands = common.mixin(app.commands, require(app.cli.source));
        }
        return true;
      }
      catch (err) {
        // If that file could not be found, error message should start with
        // "Cannot find module" and contain the name of the file we tried requiring.
        if (!err.message.match(/^Cannot find module/) || (name && err.message.indexOf(name) === -1)) {
          throw err;
        }

        if (!silent) {
          if (app.cli.notFoundUsage) {
            showUsage(usage);
          }
        }

        return false;
      }
    }
  }
246591
def set_subcommands(func, parser):
    
    if hasattr(func, '__subcommands__') and func.__subcommands__:
        sub_parser = parser.add_subparsers(
            title=SUBCOMMANDS_LIST_TITLE, dest='subcommand',
            description=SUBCOMMANDS_LIST_DESCRIPTION.format(
                func.__cmd_name__),
            help=func.__doc__)
        for sub_func in func.__subcommands__.values():
            parser = get_parser(sub_func, sub_parser)
            for args, kwargs in get_shared(sub_func):
                parser.add_argument(*args, **kwargs)
    else:
        for args, kwargs in get_shared(func):
            parser.add_argument(*args, **kwargs)
261943
def patch_pkg_resources(cls, working_set):
    """"""
    pkg_resources.working_set = working_set
    pkg_resources.require = working_set.require
    pkg_resources.iter_entry_points = working_set.iter_entry_points
    pkg_resources.run_script = pkg_resources.run_main = working_set.run_script
    pkg_resources.add_activation_listener = working_set.subscribe
269760
def install(cmd, packages):
    
    check_cmd(cmd)

    all_pkgs_str = " ".join(all_pkgs)
    print("INSTALLING: " + cmd + " install " + all_pkgs_str)
    subprocess.check_call([cmd, 'install'] + packages)
256530
def load_hooks():
    
    hooks = {}
    for entrypoint in pkg_resources.iter_entry_points(ENTRYPOINT):
        name = str(entrypoint).split('=')[0].strip()
        try:
            hook = entrypoint.load()
        except Exception as e:
            write_message('failed to load entry-point %r (error="%s")' % (name, e), 'yellow')
        else:
            hooks[name] = hook
    return hooks
726471
def load_commands(self, namespace):
        """"""
        for ep in pkg_resources.iter_entry_points(namespace):
            LOG.debug('found command %r', ep.name)
            cmd_name = (ep.name.replace('_', ' ')
                        if self.convert_underscores
                        else ep.name)
            self.commands[cmd_name] = ep
        return
828352
def load
      load_source_and_set_module
      module_callbacks if @module
      yield if block_given? # load dependencies
      detect_additions { load_commands } if load_commands?
      set_library_commands
      loaded_correctly? && (@loaded = true)
    end
314371
def add_cmd(self, name, help=None, func=None):
        
        if self.subparsers is None:
            self.subparsers = self.add_subparsers(
                title="sub-commands",
                help=help or 'sub-commands',
            )

        parser = self.subparsers.add_parser(
            name,
            help=help,
        )
        if func is not None:
            parser.set_defaults(_func=func)
        return parser
956070
def fetch_command(self, global_options, subcommand):
        
        commands = self.get_commands(global_options)
        try:
            klass = commands[subcommand]
        except KeyError:
            sys.stderr.write("Unknown command: %r\nType '%s help' for usage.\nMany commands will only run at project directory, maybe the directory is not right.\n" % \
                (subcommand, self.prog_name))
            sys.exit(1)
        return klass
1302889
def find_commands(cls):
    
    cmds = []
    for subclass in cls.__subclasses__():
        cmds.append(subclass)
        cmds.extend(find_commands(subclass))
    return cmds