Imports a module from the generated autoboto package in the build directory (not target_dir).

        For example, to import autoboto.services.s3.shapes, call:
            botogen.import_generated_autoboto_module("services.s3.shapes")
350656
def import_generated_autoboto_module(self, name):
        
        if str(self.config.build_dir) not in sys.path:
            sys.path.append(str(self.config.build_dir))
        return importlib.import_module(f"{self.config.target_package}.{name}")
623655
def import_submodules(package_name: str) -> None:
    
    importlib.invalidate_caches()

    # For some reason, python doesn't always add this by default to your path, but you pretty much
    # always want it when using `--include-package`.  And if it's already there, adding it again at
    # the end won't hurt anything.
    sys.path.append('.')

    # Import at top level
    module = importlib.import_module(package_name)
    path = getattr(module, '__path__', [])
    path_string = '' if not path else path[0]

    # walk_packages only finds immediate children, so need to recurse.
    for module_finder, name, _ in pkgutil.walk_packages(path):
        # Sometimes when you import third-party libraries that are on your path,
        # `pkgutil.walk_packages` returns those too, so we need to skip them.
        if path_string and module_finder.path != path_string:
            continue
        subpackage = f"{package_name}.{name}"
        import_submodules(subpackage)
462168
def modpath_pkg_resources(module, entry_point):
    

    result = []
    try:
        path = resource_filename_mod_entry_point(module.__name__, entry_point)
    except ImportError:
        logger.warning("module '%s' could not be imported", module.__name__)
    except Exception:
        logger.warning("%r does not appear to be a valid module", module)
    else:
        if path:
            result.append(path)
    return result
1334785
def import_task_modules():
    
    top_level_modules = settings.INSTALLED_APPS
    module_names = []
    for module in top_level_modules:
        #Import package
        mod = import_module(module)
        #Find all modules in package path
        for loader, module_name, is_pkg in  pkgutil.walk_packages(mod.__path__):
            if not module_name.startswith("__"):
                #If the module is not __init__, add it to the registry
                submod_name = "{0}.{1}".format(module,module_name)
                module_names.append(submod_name)
    #Once everything is imported, the metaclass will register them automatically
    modules = map(import_module, module_names)
    return modules
969535
def locate_module(module_id: str, module_type: str = None):
    

    entry_point = None

    if module_type:
        entry_point = 'ehforwarderbot.%s' % module_type

    module_id = module_id.split('#', 1)[0]

    if entry_point:
        for i in pkg_resources.iter_entry_points(entry_point):
            if i.name == module_id:
                return i.load()

    return pydoc.locate(module_id)
551983
def autodoc_module(module):
    
    doc = getattr(module, '__doc__')
    if doc is None:
        doc = ''
    members = []
    for name, member in inspect.getmembers(module):
        if ((not name.startswith('_')) and
                (inspect.getmodule(member) is module)):
            members.append((name, member))
    members = sorted(members, key=_number_of_line)
    if members:
        lines = ['\n\nModule :mod:`~%s` implements the following members:\n'
                 % module.__name__]
        for (name, member) in members:
            if inspect.isfunction(member):
                type_ = 'func'
            elif inspect.isclass(member):
                type_ = 'class'
            else:
                type_ = 'obj'
            lines.append('      * :%s:`~%s` %s'
                         % (type_, name, objecttools.description(member)))
        doc = doc + '\n\n' + '\n'.join(lines) + '\n\n' + 80*'_'
        module.__doc__ = doc
970337
def install_aliases():
    
    if PY3:
        return
    # if hasattr(install_aliases, 'run_already'):
    #     return
    for (newmodname, newobjname, oldmodname, oldobjname) in MOVES:
        __import__(newmodname)
        # We look up the module in sys.modules because __import__ just returns the
        # top-level package:
        newmod = sys.modules[newmodname]
        # newmod.__future_module__ = True

        __import__(oldmodname)
        oldmod = sys.modules[oldmodname]

        obj = getattr(oldmod, oldobjname)
        setattr(newmod, newobjname, obj)

    # Hack for urllib so it appears to have the same structure on Py2 as on Py3
    import urllib
    from future.backports.urllib import request
    from future.backports.urllib import response
    from future.backports.urllib import parse
    from future.backports.urllib import error
    from future.backports.urllib import robotparser
    urllib.request = request
    urllib.response = response
    urllib.parse = parse
    urllib.error = error
    urllib.robotparser = robotparser
    sys.modules['urllib.request'] = request
    sys.modules['urllib.response'] = response
    sys.modules['urllib.parse'] = parse
    sys.modules['urllib.error'] = error
    sys.modules['urllib.robotparser'] = robotparser

    # Patch the test module so it appears to have the same structure on Py2 as on Py3
    try:
        import test
    except ImportError:
        pass
    try:
        from future.moves.test import support
    except ImportError:
        pass
    else:
        test.support = support
        sys.modules['test.support'] = support

    # Patch the dbm module so it appears to have the same structure on Py2 as on Py3
    try:
        import dbm
    except ImportError:
        pass
    else:
        from future.moves.dbm import dumb
        dbm.dumb = dumb
        sys.modules['dbm.dumb'] = dumb
        try:
            from future.moves.dbm import gnu
        except ImportError:
            pass
        else:
            dbm.gnu = gnu
            sys.modules['dbm.gnu'] = gnu
        try:
            from future.moves.dbm import ndbm
        except ImportError:
            pass
        else:
            dbm.ndbm = ndbm
            sys.modules['dbm.ndbm'] = ndbm
249618
def ast_from_module(self, module, modname=None):
        """"""
        modname = modname or module.__name__
        if modname in self.astroid_cache:
            return self.astroid_cache[modname]
        try:
            # some builtin modules don't have __file__ attribute
            filepath = module.__file__
            if modutils.is_python_source(filepath):
                return self.ast_from_file(filepath, modname)
        except AttributeError:
            pass
        from astroid.builder import AstroidBuilder

        return AstroidBuilder(self).module_build(module, modname)
904077
def _import_module_from_path(module_name, plugin_path):
    
    module = None
    try:
        if PY2:
            info = imp.find_module(module_name, [plugin_path])
            if info:
                module = imp.load_module(module_name, *info)
        else:  # Python 3.4+
            spec = importlib.machinery.PathFinder.find_spec(
                module_name,
                [plugin_path])
            if spec:
                module = spec.loader.load_module(module_name)
    except Exception:
        pass

    return module
931169
def import_from_cwd(module, imp=None, package=None):
    
    if imp is None:
        imp = importlib.import_module
    with cwd_in_path():
        return imp(module, package=package)
784291
def build_tree(self):
        """"""
        for m in listdir(self.path):
            abs_m = join(self.path, m)
            if isfile(abs_m) and m.endswith('.py'):
                name = splitext(m)[0]
                if not self.limit_to or name in self.limit_to:
                    self.modules.append(Module(name, abs_m, self.dsm, self))
            elif isdir(abs_m):
                if isfile(join(abs_m, '__init__.py')) or not self.enforce_init:
                    heads, new_limit_to = self.split_limits_heads()
                    if not heads or m in heads:
                        self.packages.append(
                            Package(m, abs_m, self.dsm, self, new_limit_to,
                                    build_tree=True,
                                    build_dependencies=False,
                                    enforce_init=self.enforce_init))
218839
def import_submodules(context, root_module, path):
    
    for _, module_name, _ in pkgutil.walk_packages(path, root_module + '.'):
        # this causes a Runtime error with model conflicts
        # module = loader.find_module(module_name).load_module(module_name)
        module = __import__(module_name, globals(), locals(), ['__name__'])
        for k, v in vars(module).items():
            if not k.startswith('_'):
                context[k] = v
        context[module_name] = module
1284462
def _import_module(name, package=None):
    
    if name.startswith('.'):
        name = '{package}.{module}'.format(package=package, module=str(name).strip('.'))
    __import__(name)
    return sys.modules[name]
560011
def importfile(filename):
    
    pkg = packageFromPath(filename, includeModule=True)
    root = packageRootPath(filename)

    if root not in sys.path:
        sys.path.insert(0, root)

    __import__(pkg)
    return sys.modules[pkg]
733631
def autodiscover():
    '''
    
    '''
    from .compat import importlib

    # Bail out if autodiscover didn't finish loading from a previous call so
    # that we avoid running autodiscover again when the URLconf is loaded by
    # the exception handler to resolve the handler500 view.  This prevents an
    # autofixtures.py module with errors from re-registering models and raising a
    # spurious AlreadyRegistered exception (see #8245).
    global LOADING
    if LOADING:
        return
    LOADING = True
    app_paths = {}

    # For each app, we need to look for an autofixture.py inside that app's
    # package. We can't use os.path here -- recall that modules may be
    # imported different ways (think zip files) -- so we need to get
    # the app's __path__ and look for autofixture.py on that path.

    # Step 1: find out the app's __path__ Import errors here will (and
    # should) bubble up, but a missing __path__ (which is legal, but weird)
    # fails silently -- apps that do weird things with __path__ might
    # need to roll their own autofixture registration.

    import imp
    try:
        from django.apps import apps

        for app_config in apps.get_app_configs():
            app_paths[app_config.name] = [app_config.path]

    except ImportError:
        # Django < 1.7
        from django.conf import settings

        for app in settings.INSTALLED_APPS:
            mod = importlib.import_module(app)
            try:
                app_paths[app] = mod.__path__
            except AttributeError:
                continue

    for app, app_path in app_paths.items():
        # Step 2: use imp.find_module to find the app's autofixtures.py. For some
        # reason imp.find_module raises ImportError if the app can't be found
        # but doesn't actually try to import the module. So skip this app if
        # its autofixtures.py doesn't exist
        try:
            file, _, _ = imp.find_module('autofixtures', app_path)
        except ImportError:
            continue
        else:
            if file:
                file.close()

        # Step 3: import the app's autofixtures file. If this has errors we want them
        # to bubble up.
        try:
            importlib.import_module("%s.autofixtures" % app)
        except Exception as e:
            warnings.warn(u'Error while importing %s.autofixtures: %r' %
                (app, e))

    for app, app_path in app_paths.items():
        try:
            file, _, _ = imp.find_module('tests', app_path)
        except ImportError:
            continue
        else:
            if file:
                file.close()

        try:
            importlib.import_module("%s.tests" % app)
        except Exception as e:
            warnings.warn(u'Error while importing %s.tests: %r' %
                (app, e))

    # autodiscover was successful, reset loading flag.
    LOADING = False
221476
def create(cls, entry):
        
        # trading_bots.example.bot.ExampleBot
        try:
            # If import_module succeeds, entry is a path to a bot module,
            # which may specify a bot class with a default_bot attribute.
            # Otherwise, entry is a path to a bot class or an error.
            module = import_module(entry)

        except ImportError:
            # Track that importing as a bot module failed. If importing as a
            # bot class fails too, we'll trigger the ImportError again.
            module = None

            mod_path, _, cls_name = entry.rpartition('.')

            # Raise the original exception when entry cannot be a path to an
            # bot config class.
            if not mod_path:
                raise

        else:
            try:
                # If this works, the bot module specifies a bot class.
                entry = module.default_bot
            except AttributeError:
                # Otherwise, it simply uses the default bot registry class.
                return cls(f'{entry}.Bot', module)
            else:
                mod_path, _, cls_name = entry.rpartition('.')

        # If we're reaching this point, we must attempt to load the bot
        # class located at <mod_path>.<cls_name>
        mod = import_module(mod_path)
        try:
            bot_cls = getattr(mod, cls_name)
        except AttributeError:
            if module is None:
                # If importing as an bot module failed, that error probably
                # contains the most informative traceback. Trigger it again.
                import_module(entry)
            raise

        # Check for obvious errors. (This check prevents duck typing, but
        # it could be removed if it became a problem in practice.)
        if not issubclass(bot_cls, Bot):
            raise ImproperlyConfigured(
                "'%s' isn't a subclass of Bot." % entry)

        # Entry is a path to an bot config class.
        return cls(entry, mod, bot_cls.label)
157985
def generatePlugin(sourcePath, buildPath = None):
    
    if ( buildPath is None ):
        buildPath = BUILD_PATH
        
    pkg_name = projex.packageFromPath(sourcePath)
    module = os.path.basename(sourcePath).split('.')[0]
    if module != '__init__':
        pkg_name += '.' + module
    
    try:
        __import__(pkg_name)
    except ImportError, e:
        logging.exception(e)
        return
    
    module = sys.modules.get(pkg_name)
    if not module:
        return
        
    if not hasattr(module, '__designer_plugins__'):
        logger.info('%s has no __designer_plugins__ defined.' % pkg_name)
        return
    
    if not os.path.exists(buildPath):
        os.mkdir(buildPath)
    
    for plug in module.__designer_plugins__:
        output_path = os.path.join(buildPath, 
                                   '%splugin.py' % plug.__name__.lower())
        
        # generate the options
        options = {}
        options['module'] = pkg_name
        options['class']  = plug.__name__
        
        # save the plugin
        f = open(output_path, 'w')
        f.write(PLUGIN_DEF % options)
        f.close()