Create list of available modules.

    Arguments
    ---------
    pkg : module
        module to inspect

    Returns
    ---------
    method : list
        A list of available submodules
429756
def avail_approaches(pkg):
    '''
    '''
    methods = [modname for importer, modname, ispkg in
               pkgutil.walk_packages(path=pkg.__path__)
               if modname not in
               ['common_args', 'directions', 'sobol_sequence']]
    return methods
146487
function readDefaultModules (pkgDir) { return function (pkg, cb) {
  log.verbose(pkg._id, "readDefaultModules")
  var lib = pkg.directories && pkg.directories.lib || pkg.lib
    , libDir = path.join(pkgDir, lib).replace(/\/+$/, '')
  if (!lib) return cb(null, pkg)
  // create a modules hash from the lib folder.
  pkg.modules = {}
  var cut = pkgDir === "." ? 0 : pkgDir.length + 1
    , libCut = pkgDir === "." ? lib.length - 1 : libDir.length + 1
  find(libDir, function (er, filenames) {
    if (er) return cb(er)
    filenames.filter(function (f) {
      return !f.substr(libCut).match(/(^|\/)\./)
    }).forEach(function (filename) {
      // filename = path.basename(filename, path.extname(filename))
      var key = filename.substr(libCut)
        , val = filename.substr(cut)
      key = key.replace(/\.node$/, ".js")
      if (key.length && val.length) pkg.modules[key] = val
    })
    // require("foo/foo") is dumb, and happens a lot.
    var nameMod = pkg.modules[pkg.name] || pkg.modules[pkg.name+".js"]
    if (!pkg.main
        && !pkg.modules.index
        && !pkg.modules["index.js"]
        && nameMod) {
      pkg.modules["index.js"] = nameMod
    }
    log.silly(pkg.modules, pkg._id+".modules")
    return cb(null, pkg)
  })
}}
866452
def list_pkgs(versions_as_list=False, **kwargs):
    '''
    
    '''
    versions_as_list = salt.utils.data.is_true(versions_as_list)
    # 'removed', 'purge_desired' not yet implemented or not applicable
    if any([salt.utils.data.is_true(kwargs.get(x))
            for x in ('removed', 'purge_desired')]):
        return {}

    if 'pkg.list_pkgs' in __context__:
        if versions_as_list:
            return __context__['pkg.list_pkgs']
        else:
            ret = copy.deepcopy(__context__['pkg.list_pkgs'])
            __salt__['pkg_resource.stringify'](ret)
            return ret

    ret = {}
    cmd = ['port', 'installed']
    out = salt.utils.mac_utils.execute_return_result(cmd)
    for line in out.splitlines():
        try:
            name, version_num, active = re.split(r'\s+', line.lstrip())[0:3]
            version_num = version_num[1:]
        except ValueError:
            continue
        if not LIST_ACTIVE_ONLY or active == '(active)':
            __salt__['pkg_resource.add_pkg'](ret, name, version_num)

    __salt__['pkg_resource.sort_pkglist'](ret)
    __context__['pkg.list_pkgs'] = copy.deepcopy(ret)
    if not versions_as_list:
        __salt__['pkg_resource.stringify'](ret)
    return ret
282401
def create_package_file(root, master_package, subroot, py_files, opts, subs):
    """"""
    package = os.path.split(root)[-1]
    text = format_heading(1, '%s Package' % package)
    # add each package's module
    for py_file in py_files:
        if shall_skip(os.path.join(root, py_file)):
            continue
        is_package = py_file == INIT
        py_file = os.path.splitext(py_file)[0]
        py_path = makename(subroot, py_file)
        if is_package:
            heading = ':mod:`%s` Package' % package
        else:
            heading = ':mod:`%s` Module' % py_file
        text += format_heading(2, heading)
        text += format_directive(is_package and subroot or py_path, master_package)
        text += '\n'

    # build a list of directories that are packages (they contain an INIT file)
    subs = [sub for sub in subs if os.path.isfile(os.path.join(root, sub, INIT))]
    # if there are some package directories, add a TOC for theses subpackages
    if subs:
        text += format_heading(2, 'Subpackages')
        text += '.. toctree::\n\n'
        for sub in subs:
            text += '    %s.%s\n' % (makename(master_package, subroot), sub)
        text += '\n'

    write_file(makename(master_package, subroot), text, opts)
318169
def getAvailableClassesInPackage(package):
    
    l = list(x[1] for x in inspect.getmembers(package, inspect.isclass))

    modules = list(x[1] for x in inspect.getmembers(package, inspect.ismodule))
    for m in modules:
        l.extend(list(x[1] for x in inspect.getmembers(m, inspect.isclass)))
    l = [x for x in l if x.__name__[0] != "_"]
    n = 0
    while n < len(l):
        cls = l[n]
        if not cls.__module__.startswith(package.__name__):
            l.pop(n)
            n -= 1
        n += 1
    return l
1215033
def list_():
    '''
    
    '''
    cmd = 'pkgutil --pkgs'
    ret = salt.utils.mac_utils.execute_return_result(cmd)
    return ret.splitlines()
676008
def _list_packages(self, args):
        '''
        
        '''
        packages = self._pkgdb_fun('list_packages', self.db_conn)
        for package in packages:
            if self.opts['verbose']:
                status_msg = ','.join(package)
            else:
                status_msg = package[0]
            self.ui.status(status_msg)
1142326
def get_app_submodules(submodule_name):
    
    for name, module in get_app_modules():
        if module_has_submodule(module, submodule_name):
            yield name, import_module('%s.%s' % (name, submodule_name))
563402
def list_pkgs(versions_as_list=False, **kwargs):
    '''
    
    '''
    versions_as_list = salt.utils.data.is_true(versions_as_list)
    # not yet implemented or not applicable
    if any([salt.utils.data.is_true(kwargs.get(x))
            for x in ('removed', 'purge_desired')]):
        return {}

    if 'pkg.list_pkgs' in __context__:
        if versions_as_list:
            return __context__['pkg.list_pkgs']
        else:
            ret = copy.deepcopy(__context__['pkg.list_pkgs'])
            __salt__['pkg_resource.stringify'](ret)
            return ret

    ret = {}
    pkgs = _vartree().dbapi.cpv_all()
    for cpv in pkgs:
        __salt__['pkg_resource.add_pkg'](ret,
                                         _cpv_to_cp(cpv),
                                         _cpv_to_version(cpv))
    __salt__['pkg_resource.sort_pkglist'](ret)
    __context__['pkg.list_pkgs'] = copy.deepcopy(ret)
    if not versions_as_list:
        __salt__['pkg_resource.stringify'](ret)
    return ret
1009819
public void listModules() throws Exception {

        Set<String> modules = OpenCms.getModuleManager().getModuleNames();
        m_shell.getOut().println(
            "\n" + getMessages().key(Messages.GUI_SHELL_LIST_MODULES_1, new Integer(modules.size())));
        Iterator<String> i = modules.iterator();
        while (i.hasNext()) {
            String moduleName = i.next();
            m_shell.getOut().println(moduleName);
        }
        m_shell.getOut().println();
    }
899297
def find_modules(self, path, prefix):
        """"""

        modules = set([prefix])

        # https://docs.python.org/2/library/pkgutil.html#pkgutil.iter_modules
        for module_info in pkgutil.iter_modules([path]):
            # we want to ignore any "private" modules
            if module_info[1].startswith('_'): continue

            module_prefix = ".".join([prefix, module_info[1]])
            if module_info[2]:
                # module is a package
                submodules = self.find_modules(os.path.join(path, module_info[1]), module_prefix)
                modules.update(submodules)
            else:
                modules.add(module_prefix)

        return modules
980541
def import_apps_submodule(submodule):
    
    found_apps = []
    for appconfig in apps.get_app_configs():
        app = appconfig.name
        if import_module_or_none('{0}.{1}'.format(app, submodule)) is not None:
            found_apps.append(app)

    return found_apps
1055920
def explore_package(module_name):
    

    packages = []
    loader = pkgutil.get_loader(module_name)
    for sub_module in pkgutil.walk_packages([os.path.dirname(loader.get_filename())],
                                            prefix=module_name + '.'):
        _, sub_module_name, _ = sub_module
        packages.append(sub_module_name)

    return packages
1334017
def import_submodules(name, submodules=None):
    """"""
    sys.path.insert(0, name)
    if submodules:
        for submodule in submodules:
            import_string('{0}.{1}'.format(name, submodule))
    else:
        for item in pkgutil.walk_packages([name]):
            import_string('{0}.{1}'.format(name, item[1]))
1029332
def get_modules(package_name, module_names):
  
  def get_module(name):
    return __import__(".".join([package_name, name]), fromlist=[package_name])
  return [get_module(name) for name in module_names]
840963
def get_app_modules(self, apps):
        
        modules = getattr(self, "_modules", [])

        if not modules:
            from django.utils.module_loading import module_has_submodule

            # Try importing a modules from the module package
            package_string = '.'.join(['leonardo', 'module'])

            for app in apps:
                exc = '...'
                try:
                    # check if is not full app
                    _app = import_module(app)
                except Exception as e:
                    _app = False
                    exc = e

                if module_has_submodule(
                        import_module(package_string), app) or _app:
                    if _app:
                        mod = _app
                    else:
                        mod = import_module('.{0}'.format(app), package_string)
                    if mod:
                        modules.append(mod)
                        continue

                warnings.warn('%s was skipped because %s ' % (app, exc))

            self._modules = modules
        return self._modules
217586
def import_submodules(module):
    """"""
    submodules = {}
    for loader, name, ispkg in pkgutil.iter_modules(module.__path__,
                                                    module.__name__ + '.'):
        try:
            submodule = import_module(name)
        except ImportError as e:
            # FIXME: Make the errors non-fatal (do we want that?).
            logging.warning("Error importing %s", name)
            logging.exception(e)
        else:
            parent, child = name.rsplit('.', 1)
            submodules[child] = submodule
    return submodules