Find the commands module in each app (if it exists) and return the path
    app_name : The name of an app in the INSTALLED_APPS setting
    return - path to the app
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
1113462
def _locate_settings(settings=''):
    ""

    import imp
    import sys
    sys.path.append(os.getcwd())
    settings = settings or os.getenv('DJANGO_SETTINGS_MODULE')
    if settings:
        parts = settings.split('.')
        f = imp.find_module(parts[0])[1]
        args = [f] + parts[1:]
        path = os.path.join(*args)
        path = path + '.py'
        if os.path.exists(path):
            return path
226108
def set_root_path(self, root_path=None, settings_module=None):
        
        if root_path:
            self.root_path = root_path
            return

        if settings_module:
            self.root_path = os.path.dirname(os.path.abspath(settings_module.__file__))
            return

        # try to guess which module import app.py
        import inspect

        caller = inspect.stack()[1]
        caller_module = inspect.getmodule(caller[0])
        assert hasattr(caller_module, '__file__'), 'Caller module %s should have __file__ attr' % caller_module
        self.root_path = os.path.dirname(os.path.abspath(caller_module.__file__))
799219
def get_permissions_app_name():
    
    global permissions_app_name

    if not permissions_app_name:
        permissions_app_name = getattr(settings, 'PERMISSIONS_APP', None)

        if not permissions_app_name:
            app_names_with_models = [a.name for a in apps.get_app_configs() if a.models_module is not None]
            if app_names_with_models:
                permissions_app_name = app_names_with_models[-1]

    return permissions_app_name
506290
def get_config(cli_args=None, config_path=None):
    
    config = Config(app_name="MYAPP",
                    cli_args=cli_args,
                    config_path=config_path)
    config_dict = config.get_config()
    return config_dict
232595
def _get_app_config(self, app_name):
        

        matches = [app_config for app_config in apps.get_app_configs()
                   if app_config.name == app_name]
        if not matches:
            return
        return matches[0]
549112
def get_management_commands(settings):
    
    app_commands = getattr(settings, 'MANAGEMENT_COMMANDS', ())
    commands = {}
    for name in itertools.chain(SHELTER_MANAGEMENT_COMMANDS, app_commands):
        command_obj = import_object(name)
        if not issubclass(command_obj, BaseCommand):
            raise ValueError("'%s' is not subclass of the BaseCommand" % name)
        commands[command_obj.name] = command_obj
    return commands
410689
def install_app(self, app_path, app_package):
        
        driver = self._current_application()
        driver.install_app(app_path)
        return driver.is_app_installed(app_package)
951153
def get_command(self, ctx, cmd_name):
        
        if cmd_name not in self._commands:
            logger.error("Command %s not available", cmd_name)
            return

        pkg_name = self._commands[cmd_name]

        try:
            mod = importlib.import_module(pkg_name)
        except ImportError:
            logger.exception("Command '%s' is not configured correctly. Unable to import '%s'", cmd_name, pkg_name)
            return

        if not hasattr(mod, "cli"):
            logger.error("Command %s is not configured correctly. It must expose an function called 'cli'", cmd_name)
            return

        return mod.cli
64511
def get_app_dir(app):
    
    path = __app_dirs__.get(app)
    if path is not None:
        return path
    else:
        p = app.split('.')
        try:
            path = pkg.resource_filename(p[0], '')
        except ImportError as e:
            log.error("Can't import app %s" % app)
            log.exception(e)
            path = ''
        if len(p) > 1:
            path = os.path.join(path, *p[1:])
        
        __app_dirs__[app] = path
        return path
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
291290
def get_classes(module_label, classnames):
    
    app_label = module_label.split('.')[0]

    app_module_path = _get_app_module_path(module_label)
    if not app_module_path:
        raise AppNotFoundError('No app found matching \'{}\''.format(module_label))

    # Determines the full module path by appending the module label
    # to the base package path of the considered application.
    module_path = app_module_path
    if '.' in app_module_path:
        base_package = app_module_path.rsplit('.' + app_label, 1)[0]
        module_path = '{}.{}'.format(base_package, module_label)

    # Try to import this module from the related app that is specified
    # in the Django settings.
    local_imported_module = _import_module(module_path, classnames)

    # If the module we tried to import is not located inside the machina
    # vanilla apps, try to import it from the corresponding machina app.
    machina_imported_module = None
    if not app_module_path.startswith('machina.apps'):
        machina_imported_module = _import_module(
            '{}.{}'.format('machina.apps', module_label), classnames,
        )

    if local_imported_module is None and machina_imported_module is None:
        raise AppNotFoundError('Error importing \'{}\''.format(module_path))

    # Any local module is prioritized over the corresponding machina module
    imported_modules = [
        m for m in (local_imported_module, machina_imported_module) if m is not None
    ]
    return _pick_up_classes(imported_modules, classnames)
828921
def find_module(self, fullname, path=None):
        
        root, base, target = fullname.partition(self.root_name + '.')
        if root:
            return
        if not any(map(target.startswith, self.vendored_names)):
            return
        return self
157945
def find_module_path():
    """"""
    master_modname = __name__.split(".", 1)[0]
    master_module = sys.modules[master_modname]
    #return os.path.dirname(os.path.realpath(os.path.join(inspect.getsourcefile(endpoints), "..")))
    path = os.path.dirname(inspect.getsourcefile(master_module))
    return path
237780
def _get_installed_apps_paths():
    
    out = set()
    for app in django_settings.INSTALLED_APPS:
        out.add(app)
    return out
110106
def get_install_paths(name):
    
    paths = {}

    i = get_install_command(name)

    for key in install.SCHEME_KEYS:
        paths[key] = getattr(i, 'install_' + key)

    # pip uses a similar path as an alternative to the system's (read-only)
    # include directory:
    if hasattr(sys, 'real_prefix'):  # virtualenv
        paths['headers'] = os.path.join(sys.prefix,
                                        'include',
                                        'site',
                                        'python' + sys.version[:3],
                                        name)

    return paths
398235
def get_class_from_settings_from_apps(settings_key):
    
    cls_path = getattr(settings, settings_key, None)

    if not cls_path:
        raise NotImplementedError()

    try:
        app_label = cls_path.split('.')[-2]
        model_name = cls_path.split('.')[-1]
    except ValueError:
        raise ImproperlyConfigured("{0} must be of the form "
                                   "'app_label.model_name'".format(
                                                                settings_key))

    app = apps.get_app_config(app_label).models_module

    if not app:
        raise ImproperlyConfigured("{0} setting refers to an app that has not "
                                   "been installed".format(settings_key))

    return getattr(app, model_name)