Пример #1
0
def run(install: bool, **presubmit_args) -> int:
    """Entry point for presubmit."""

    if install:
        install_hook(__file__, 'pre-push',
                     ['--base', 'origin/master..HEAD', '--program', 'quick'],
                     Path.cwd())
        return 0

    return cli.run(**presubmit_args)
Пример #2
0
def run(
    program_name: str,
    clear: bool,
    clear_py: bool,
    install: bool,
    repository: Path,
    output_directory: Path,
    steps: Sequence[str],
    **presubmit_args,
) -> int:
    """Entry point for presubmit."""

    os.environ.setdefault('PW_ROOT',
                          str(pw_presubmit.git_repo_path(repo=repository)))

    if not output_directory:
        output_directory = pw_presubmit.git_repo_path('.presubmit',
                                                      repo=repository)
    _LOG.debug('Using environment at %s', output_directory)

    if clear or clear_py:
        _LOG.info('Clearing presubmit%s environment',
                  '' if clear else ' Python')

        if clear and output_directory.exists():
            shutil.rmtree(output_directory)
            _LOG.info('Deleted %s', output_directory)

        init_venv = output_directory.joinpath('init_virtualenv')
        if clear_py and init_venv.exists():
            shutil.rmtree(init_venv)
            _LOG.info('Deleted %s', init_venv)

        return 0

    if install:
        install_hook(__file__, 'pre-push',
                     ['--base', 'origin/master..HEAD', '--program', 'quick'],
                     repository)
        return 0

    program: Sequence[Callable] = PROGRAMS[program_name]
    if steps:
        program = [PROGRAMS.all_steps()[name] for name in steps]

    if pw_presubmit.run_presubmit(program,
                                  program_name,
                                  repo_path=repository,
                                  output_directory=output_directory,
                                  **presubmit_args):
        return 0

    return 1
Пример #3
0
def main(
    program_name: str,
    clean: bool,
    clean_py: bool,
    install: bool,
    repository: Path,
    output_directory: Path,
    steps: Sequence[str],
    **presubmit_args,
) -> int:
    """Entry point for presubmit."""

    os.environ.setdefault('PW_ROOT',
                          str(pw_presubmit.git_repo_path(repo=repository)))

    if not output_directory:
        output_directory = pw_presubmit.git_repo_path('.presubmit',
                                                      repo=repository)
    environment = output_directory
    _LOG.debug('Using environment at %s', environment)

    if clean and environment.exists():
        shutil.rmtree(environment)
    elif clean_py and environment.joinpath('init_virtualenv').exists():
        shutil.rmtree(environment.joinpath('init_virtualenv'))

    if install:
        install_hook(__file__, 'pre-push',
                     ['--base', 'origin/master..HEAD', '--program', 'quick'],
                     repository)
        return 0

    program: Sequence = PROGRAMS[program_name]
    if steps:
        program = [ALL_STEPS[name] for name in steps]

    if pw_presubmit.run_presubmit(program,
                                  repository=repository,
                                  output_directory=output_directory,
                                  **presubmit_args):
        return 0

    return 1