示例#1
0
def gather_all_commands():
    global ALL_COMMANDS

    # Import any project-specific commands
    utils.import_module_or_none('{}.commands'.format(settings.PROJECT_PACKAGE_NAME))

    ALL_COMMANDS = {c.get_name(): c for c in BaseCommand.__subclasses__()}
示例#2
0
async def _init_app(app):
    global _project_app

    _project_app = utils.import_module_or_none('{}.app'.format(settings.PROJECT_PACKAGE_NAME))
    if _project_app is not None:
        init = getattr(_project_app, 'init', None)
        if init:
            init(app, asyncio.get_event_loop())
示例#3
0
    def execute(self, options):
        # have models automatically imported into locals
        loc = locals()
        models = utils.import_module_or_none('{}.models'.format(
            settings.PROJECT_PACKAGE_NAME))
        if models:
            loc['models'] = models

        code.interact(local=loc)
示例#4
0
def _init_routes(web_app):
    routes = utils.import_module_or_none('{}.routes'.format(settings.PROJECT_PACKAGE_NAME))
    if routes is None:
        return

    for route in getattr(routes, 'ROUTES', []):
        _add_route_tuple(web_app, route)

    for route in getattr(routes, 'STATIC_ROUTES', []):
        _add_static_route_tuple(web_app, route)
示例#5
0
def _setup_project_settings():
    project_settings_path = '{}.settings'.format(settings.PROJECT_PACKAGE_NAME)
    project_settings_module = utils.import_module_or_none(
        project_settings_path)
    if project_settings_module is None:
        return

    for name, value in inspect.getmembers(project_settings_module):
        if not _is_setting_name(name):
            continue

        setattr(settings, name, value)
示例#6
0
    def execute(self, options):
        import pytest

        args = list(self.args)
        has_file_or_dir = any(True for arg in args if not arg.startswith('-'))

        # Running tests with "-v" feels like a natural choice
        if '-v' not in args:
            args.append('-v')

        # Run tests from the project's tests subpackage unless a file or directory is given as argument
        if not has_file_or_dir:
            tests_dir = os.path.join(settings.PROJECT_PACKAGE_DIR, _TESTS_DIR)
            os.chdir(tests_dir)

        plugins = list(_PLUGINS)

        # Use project's fixtures as a plugin so that project-specific fixtures are loaded
        fixtures_path = '{}.tests.fixtures'.format(
            settings.PROJECT_PACKAGE_NAME)
        if import_module_or_none(fixtures_path):
            plugins.append(fixtures_path)

        return pytest.main(args, plugins=plugins)