Return module name that doesn't already exist
963584
def nonpresent_module_filename():
    """"""
    while True:
        module_name = get_random_name()
        loader = pkgutil.find_loader(module_name)
        if loader is not None:
            continue
        importlib.invalidate_caches()
        return "{}.py".format(module_name)
164772
def named_module(name):
    """"""
    module = __import__(name)
    packages = name.split(".")[1:]
    m = module
    for p in packages:
        m = getattr(m, p)
    return m
979505
def compare(all_dict, others, names, module_name):
    """"""
    only_all = set()
    for name in all_dict:
        if name not in names:
            only_all.add(name)

    only_ref = set()
    missing = set()
    for name in names:
        if name not in all_dict:
            for pat in REFGUIDE_ALL_SKIPLIST:
                if re.match(pat, module_name + '.' + name):
                    if name not in others:
                        missing.add(name)
                    break
            else:
                only_ref.add(name)

    return only_all, only_ref, missing
1349037
def get_func_name(func):
    """"""
    func_name = getattr(func, '__name__', func.__class__.__name__)
    module_name = func.__module__

    if module_name is not None:
        module_name = func.__module__
        return '{}.{}'.format(module_name, func_name)

    return func_name
1072130
def findModuleOfName(self, dotted_name, level, filename, extrapath=None):
        """"""
        if dotted_name.endswith('.*'):
            return dotted_name[:-2]
        name = dotted_name

        # extrapath is None only in a couple of test cases; in real life it's
        # always present
        if level and level > 1 and extrapath:
            # strip trailing path bits for each extra level to account for
            # relative imports
            # from . import X has level == 1 and nothing is stripped (the level > 1 check accounts for this case)
            # from .. import X has level == 2 and one trailing path component must go
            # from ... import X has level == 3 and two trailing path components must go
            extrapath = extrapath.split(os.path.sep)
            level -= 1
            extrapath = extrapath[0:-level]
            extrapath = os.path.sep.join(extrapath)

        while name:
            candidate = self.isModule(name, extrapath)
            if candidate:
                return candidate
            candidate = self.isPackage(name, extrapath)
            if candidate:
                return candidate
            name = name[:name.rfind('.')]
        self.warn(dotted_name, '%s: could not find %s', filename, dotted_name)
        return dotted_name
465799
def _find_module(name, path=None):
    

    parts = name.split('.')

    for part in parts:
        if path is not None:
            path = [path]

        fh, path, descr = imp.find_module(part, path)
        if fh is not None and part != parts[-1]:
            fh.close()

    return fh, path, descr
753465
def from_modulename(cls, module_name):
        
        # XXX make this more robust (pyc files? zip archives? etc)
        slug = module_name.replace('.', '/')
        paths = [slug + '.py', slug + '/__init__.py']

        # always search from current directory
        for base in [''] + sys.path:
            for path in paths:
                fullpath = os.path.join(base, path)
                if os.path.exists(fullpath):
                    return cls(fullpath, prefix=module_name)
        else:
            raise ValueError("Module not found: %s" % module_name)
484341
def getModulePath(project_path,module_name,verbose):
    ''''''
    if not module_name:
        return None
    sys.path.append(project_path)
    try:
        package = pkgutil.get_loader(module_name)
    except ImportError:
        if verbose:
            print("Parent module for "+module_name+" not found.")
        return None
    except:
        if verbose:
            print(module_name+" not loaded for bizarre reasons")
    try:
        if package: 
                if package.get_code(module_name):
                    filename = package.get_code(module_name).co_filename
                    return filename
                elif package.find_spec(module_name).has_location==False:
                    return None #built-in module such as itertools
                else:
                    pass #perhaps filename is in package.find_spec(module_name).origin?
                    pass #a good reference is https://www.python.org/dev/peps/pep-0302/
    except ImportError:
        if verbose:
            print("Code object unavailable for "+module_name)
        return None
    except AttributeError:
        if verbose:
            print(module_name+" is an ExtensionFileLoader object")
        return None
    except:
        if verbose:
            print(module_name+" not loaded for bizarre reasons")
        return None
    else:
        if verbose:
            print ("Module "+module_name+" not found.")
        return None
952910
def is_builtin_module(module_name):
    """"""
    module_name = module_name.split(".")[0]
    return (module_name in MODULES or
            (module_name in cxx_keywords and module_name + "_" in MODULES))
256705
def update(self, module_name=None):
        
        if not module_name:
            return self._module.force_update()
        else:
            module_info = self._get_module_info(module_name)
            if module_info:
                module_info["module"].force_update()
1037270
def _try_import(module_name):
  """"""
  try:
    mod = importlib.import_module(module_name)
    return mod
  except ImportError:
    err_msg = ("Tried importing %s but failed. See setup.py extras_require. "
               "The dataset you are trying to use may have additional "
               "dependencies.")
    utils.reraise(err_msg)
234231
def get_module_doc(module, config=default_config, already_met=None):
    """"""
    # Avoid recursion loops (init)
    if already_met is None:
        already_met = set()

    if config.exclude_module:
        for ex in config.exclude_module:
            if ex.match(module.__name__):
                return None

    # Force load submodules into module's dict
    if hasattr(module, '__path__'):
        subm = [
            modname for importer, modname, ispkg
            in pkgutil.iter_modules(module.__path__)
        ]
        __import__(module.__name__, fromlist=subm)

    # We don't want to include imported items,
    # so we parse the code to blacklist them.

    # Be sure to parse .py and not .pyc file on Python 2.X
    if hasattr(module, '__file__'):
        module_file = module.__file__
    else:
        module_file = inspect.getsourcefile(module)
    path, ext = os.path.splitext(module_file)
    if ext == '.pyc':
        module_file = path + '.py'

    try:
        code = open(module_file).read()
        body = ast.parse(code).body
    except SyntaxError:
        code = open(module_file).read().encode('utf-8')
        body = ast.parse(code).body

    imported = []
    for node in body:
        if isinstance(node, (ast.Import, ast.ImportFrom)):
            imported.extend([n.name for n in node.names])

    nested_doc = []
    module_dict = module.__dict__

    for item in dir(module):
        if item not in imported and item in module_dict.keys():
            # Avoid recursion loops
            if id(item) in already_met:
                continue
            already_met.add(id(item))

            appended = None
            if isinstance(module_dict[item], types.ModuleType):
                appended = get_module_doc(module_dict[item], config, already_met)  # noqa
            elif isinstance(module_dict[item], type):
                appended = get_class_doc(module_dict[item], config)
            elif isinstance(module_dict[item], types.FunctionType):
                appended = get_function_doc(module_dict[item], config)
            if appended is not None:
                nested_doc.append(appended)

    return _doc_object(module, 'module', nested_doc, config)
781067
def external_name(self):
        """"""
        target = self.target
        if target is not None:
            return "{}.{}".format(target.name.lower(), self.name)
        else:
            return "{}.{}".format(self.module.name.lower(), self.name)
1090379
def check_module(mod_name):
    """"""
    # Special cases #
    if mod_name in module_name: mod_name = module_name[mod_name]
    # Use a try except block #
    try:
        __import__(mod_name)
    except ImportError as e:
        if str(e) != 'No module named %s' % mod_name: raise e
        print 'You do not seem to have the "%s" package properly installed.' \
              ' Either you never installed it or your $PYTHONPATH is not set up correctly.' \
              ' For more instructions see the README file. (%s)' % (mod_name, e)
        sys.exit()
91274
def make_non_magical_flask_import(flask_ext_name):
    ''''''
    match = re.match(r'flask\.ext\.(.*)', flask_ext_name)
    if match is None:
        raise LookupError("Module name `{}` doesn't match"
                          "`flask.ext` style import.")
    from_name = match.group(1)
    actual_module_name = 'flask_{}'.format(from_name)
    return actual_module_name
1096796
def get_module_name(self, path_args):
        """"""
        controller_prefix = self.controller_prefix
        cset = self.module_names
        module_name = controller_prefix
        mod_name = module_name
        while path_args:
            mod_name += "." + path_args[0]
            if mod_name in cset:
                module_name = mod_name
                path_args.pop(0)
            else:
                break

        return module_name, path_args
478254
def name2mount(self, name):
        """"""
        if not self.is_module(name):
            raise ValueError('%r is not a supported module name' % (name, ))
        return name.replace(self.module_prefix, self.mount_prefix)