Attempt to fetch source code via pkgutil. In an ideal world, this would
        be the only required implementation of get_module().
768839
def _get_module_via_pkgutil(self, fullname):
        
        try:
            # Pre-'import spec' this returned None, in Python3.6 it raises
            # ImportError.
            loader = pkgutil.find_loader(fullname)
        except ImportError:
            e = sys.exc_info()[1]
            LOG.debug('%r._get_module_via_pkgutil(%r): %s',
                      self, fullname, e)
            return None

        IOLOG.debug('%r._get_module_via_pkgutil(%r) -> %r',
                    self, fullname, loader)
        if not loader:
            return

        try:
            path = self._py_filename(loader.get_filename(fullname))
            source = loader.get_source(fullname)
            is_pkg = loader.is_package(fullname)
        except (AttributeError, ImportError):
            # - Per PEP-302, get_source() and is_package() are optional,
            #   calling them may throw AttributeError.
            # - get_filename() may throw ImportError if pkgutil.find_loader()
            #   picks a "parent" package's loader for some crap that's been
            #   stuffed in sys.modules, for example in the case of urllib3:
            #       "loader for urllib3.contrib.pyopenssl cannot handle
            #        requests.packages.urllib3.contrib.pyopenssl"
            e = sys.exc_info()[1]
            LOG.debug('%r: loading %r using %r failed: %s',
                      self, fullname, loader, e)
            return

        if path is None or source is None:
            return

        if isinstance(source, mitogen.core.UnicodeType):
            # get_source() returns "string" according to PEP-302, which was
            # reinterpreted for Python 3 to mean a Unicode string.
            source = source.encode('utf-8')

        return path, source, is_pkg
1268162
def get_modules(modulepath):
    """"""
    m = importlib.import_module(modulepath)
    mpath = m.__file__
    ret = set([m])

    if "__init__." in mpath.lower():
        mpath = os.path.dirname(mpath)

        # https://docs.python.org/2/library/pkgutil.html#pkgutil.iter_modules
        for module_info in pkgutil.iter_modules([mpath]):
            submodulepath = ".".join([modulepath, module_info[1]])
            if module_info[2]:
                # module is a package
                submodules = get_modules(submodulepath)
                ret.update(submodules)
            else:
                ret.add(importlib.import_module(submodulepath))

    return ret
1122673
function getPythonCode(options) {
    var pythonCode = [],
        internalPylint = !options.externalPylint,
        pylintPath = path.join(__dirname, 'lib'),
        initHook = options.initHook;
    delete options.initHook;

    if (initHook) {
      pythonCode.push(initHook);
    }

    if (internalPylint) {
      pythonCode.push('import sys', 'sys.path.insert(0, r"' + pylintPath + '")');
    }

    pythonCode.push('import pylint', 'pylint.run_pylint()');
    delete options.externalPylint;
    return pythonCode.join('; ');
  }
451381
def load_module(name, filename):
    ''''''
    if sys.version_info < (3, 5):
        import imp
        import warnings
        with warnings.catch_warnings():  # Required for Python 2.7
            warnings.simplefilter("ignore", RuntimeWarning)
            return imp.load_source(name, filename)
    else:
        from importlib.machinery import SourceFileLoader
        loader = SourceFileLoader(name, filename)
        return loader.load_module()
556339
def find_module(self, modname, folder=None):
        
        for src in self.get_source_folders():
            module = _find_module_in_folder(src, modname)
            if module is not None:
                return module
        for src in self.get_python_path_folders():
            module = _find_module_in_folder(src, modname)
            if module is not None:
                return module
        if folder is not None:
            module = _find_module_in_folder(folder, modname)
            if module is not None:
                return module
        return None
54262
def fetch_pkg_list(self):
        """"""
        self.logger.debug("DEBUG: Fetching package name list from PyPI")
        package_list = self.list_packages()
        cPickle.dump(package_list, open(self.pkg_cache_file, "w"))
        self.pkg_list = package_list
483862
def get_package_version(module_obj, value):
    
    for key in ['version', '__version__']:
        if hasattr(module_obj, key):
            return getattr(module_obj, key)
    parts = value.split('.')
    for index, part in enumerate(parts):
        try:
            return pkg_resources.get_distribution(
                '.'.join(parts[0:index + 1])).version
        except (pkg_resources.DistributionNotFound,
                pkg_resources.RequirementParseError):
            continue
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
1035505
def import_module_and_get_function(whole_function):
        
        module, function = whole_function.rsplit('.', 1)
        app_module = importlib.import_module(module)
        app_function = getattr(app_module, function)
        return app_function
505885
def try_import(module_name, names=None, default=ImportErrorModule, warn=True):
    
    try:
        module = importlib.import_module(module_name)
    except ImportError:
        if warn:
            if warn is True:
                Config.utils_logger.warning(
                    "Module `%s` not found. Install it to remove this warning"
                    % module_name
                )
            else:
                warn(module_name, names, default)
        module = (
            ImportErrorModule(module_name) if default is ImportErrorModule else default
        )
    if not names:
        return module
    if not isinstance(names, (tuple, set, list)):
        names = [names]
    result = []
    for name in names:
        if hasattr(module, name):
            result.append(module.__getattribute__(name))
        else:
            result.append(
                ImportErrorModule("%s.%s" % (module_name, name))
                if default is ImportErrorModule
                else default
            )
    return result[0] if len(result) == 1 else result
423183
def get_module(self, module_name):
        """"""
        try:
            return self.module[module_name]

        except KeyError:
            return sys.modules[module_name]
506175
def linkcode_resolve(domain, info):
    
    # Only link to Python source
    if domain != 'py':
        return None

    # Get a reference to the object in question
    modname = info['module']
    fullname = info['fullname']

    submod = sys.modules.get(modname)
    if submod is None:
        return None

    obj = submod
    for part in fullname.split('.'):
        try:
            obj = getattr(obj, part)
        except:
            return None

    # Find the file which contains the object
    try:
        file_name = inspect.getsourcefile(obj)
    except:
        file_name = None
    if not file_name:
        return None

    # Convert the filename into a path relative to the rig module top-level
    file_name = os.path.relpath(file_name, start=os.path.dirname(local_module_path))

    # Get the line number range that object lives on
    try:
        source, lineno = inspect.getsourcelines(obj)
    except:
        lineno = None
    if lineno:
        linespec = "#L{}-L{}".format(lineno,
                                     lineno + len(source) - 1)
    else:
        linespec = ""
    
    # Generate a link to the code in the official GitHub repository with the
    # current-version's tag.
    return ("https://github.com/{repo}/blob/v{version}/"
            "{module_path}{file_name}{linespec}".format(repo=github_repo,
                                                        version=version,
                                                        module_path=github_module_path,
                                                        file_name=file_name,
                                                        linespec=linespec))
750
def load_code(name, base_path=None, recurse=False):
    """"""
    if '/' in name:
        return load_location(name, base_path, module=False)

    return importer.import_code(name, base_path, recurse=recurse)
28739
def linkcode_resolve(domain, info):  # NOQA: C901
    
    if domain != 'py':
        return None

    modname = info['module']
    fullname = info['fullname']

    submod = sys.modules.get(modname)
    if submod is None:
        return None

    obj = submod
    for part in fullname.split('.'):
        try:
            obj = getattr(obj, part)
        except Exception:
            return None

    # strip decorators, which would resolve to the source of the decorator
    # possibly an upstream bug in getsourcefile, bpo-1764286
    try:
        unwrap = inspect.unwrap
    except AttributeError:
        pass
    else:
        obj = unwrap(obj)

    try:
        fn = inspect.getsourcefile(obj)
    except Exception:
        fn = None
    if not fn:
        return None

    try:
        source, lineno = inspect.getsourcelines(obj)
    except Exception:
        lineno = None

    if lineno:
        linespec = "#L%d-L%d" % (lineno, lineno + len(source) - 1)
    else:
        linespec = ""

    fn = relpath(fn, start=dirname(cihai.__file__))

    if 'dev' in about['__version__']:
        return "%s/blob/master/%s/%s%s" % (
            about['__github__'],
            about['__package_name__'],
            fn,
            linespec,
        )
    else:
        return "%s/blob/v%s/%s/%s%s" % (
            about['__github__'],
            about['__version__'],
            about['__package_name__'],
            fn,
            linespec,
        )
84349
def _get_source(self):
        
        logger.debug('Getting module source for webhook2lambda2sqs.lambda_func')
        orig = getsourcelines(lambda_func)
        src = ''
        in_docstr = False
        have_docstr = False
        for line in orig[0]:
            if line.strip() == '"""' and not in_docstr and not have_docstr:
                in_docstr = True
                continue
            if line.strip() == '"""' and in_docstr:
                in_docstr = False
                have_docstr = True
                continue
            if not in_docstr:
                src += line
        return src
574316
def _get_packages(add_pckg):
        """

        # Mandatory packages
        pckgs = [numpy, scipy, empymod]

        # Optional packages
        for module in [IPython, numexpr, matplotlib]:
            if module:
                pckgs += [module]

        # Cast and add add_pckg
        if add_pckg is not None:

            # Cast add_pckg
            if isinstance(add_pckg, tuple):
                add_pckg = list(add_pckg)

            if not isinstance(add_pckg, list):
                add_pckg = [add_pckg, ]

            # Add add_pckg
            pckgs += add_pckg

        return pckgs
570042
def getmodule(object):
    """"""
    if ismodule(object):
        return object
    if isclass(object):
        return sys.modules.get(object.__module__)
    try:
        file = getabsfile(object)
    except TypeError:
        return None
    if modulesbyfile.has_key(file):
        return sys.modules[modulesbyfile[file]]
    for module in sys.modules.values():
        if hasattr(module, '__file__'):
            modulesbyfile[getabsfile(module)] = module.__name__
    if modulesbyfile.has_key(file):
        return sys.modules[modulesbyfile[file]]
    main = sys.modules['__main__']
    if hasattr(main, object.__name__):
        mainobject = getattr(main, object.__name__)
        if mainobject is object:
            return main
    builtin = sys.modules['__builtin__']
    if hasattr(builtin, object.__name__):
        builtinobject = getattr(builtin, object.__name__)
        if builtinobject is object:
            return builtin