コード例 #1
0
ファイル: python_checks.py プロジェクト: erwincoumans/pigweed
def test_python_packages(ctx: pw_presubmit.PresubmitContext,
                         patterns: Iterable[str] = TEST_PATTERNS) -> None:
    """Finds and runs test files in Python package directories.

    Finds the Python packages containing the affected paths, then searches
    within that package for test files. All files matching the provided patterns
    are executed with Python.
    """
    packages: List[PythonPackage] = []
    for repo in ctx.repos:
        packages += python_packages_containing(ctx.paths, repo=repo)[0]

    if not packages:
        _LOG.info('No Python packages were found.')
        return

    for package in packages:
        for test in list_files(pathspecs=tuple(patterns),
                               repo_path=package.root):
            call('python', test)
コード例 #2
0
def init_virtualenv(ctx: PresubmitContext):
    """Set up virtualenv, assumes recent Python 3 is already installed."""
    virtualenv_source = ctx.repository_root.joinpath('pw_env_setup', 'py',
                                                     'pw_env_setup',
                                                     'virtualenv_setup')

    # For speed, don't build the venv if it exists. Use --clean to recreate it.
    if not ctx.output_directory.joinpath('pyvenv.cfg').is_file():
        call(
            'python3',
            virtualenv_source,
            f'--venv_path={ctx.output_directory}',
            '--requirements={}'.format(
                virtualenv_source.joinpath('requirements.txt')),
        )

    os.environ['PATH'] = os.pathsep.join((
        str(ctx.output_directory.joinpath('bin')),
        os.environ['PATH'],
    ))
コード例 #3
0
def clang_tidy(ctx: PresubmitContext):
    build.gn_gen(ctx.root, ctx.output_dir, '--export-compile-commands')
    build.ninja(ctx.output_dir)
    build.ninja(ctx.output_dir, '-t', 'compdb', 'objcxx', 'cxx')

    run_clang_tidy = None
    for var in ('PW_PIGWEED_CIPD_INSTALL_DIR', 'PW_CIPD_INSTALL_DIR'):
        if var in os.environ:
            possibility = os.path.join(os.environ[var],
                                       'share/clang/run-clang-tidy.py')
            if os.path.isfile(possibility):
                run_clang_tidy = possibility
                break

    checks = ','.join(_CLANG_TIDY_CHECKS)
    call(
        run_clang_tidy,
        f'-p={ctx.output_dir}',
        f'-checks={checks}',
        # TODO(pwbug/45) not sure if this is needed.
        # f'-extra-arg-before=-warnings-as-errors={checks}',
        *ctx.paths)
コード例 #4
0
def init_virtualenv(pigweed_root: Path, output_directory: Path) -> None:
    """Sets up a virtualenv, assumes recent Python 3 is already installed."""
    virtualenv_source = pigweed_root.joinpath('pw_env_setup', 'py',
                                              'pw_env_setup',
                                              'virtualenv_setup')

    # TODO(pwbug/138): find way to support dependent project requirements.

    # For speed, don't build the venv if it exists. Use --clear-py to rebuild.
    if not output_directory.joinpath('pyvenv.cfg').is_file():
        call(
            'python3',
            virtualenv_source,
            f'--venv_path={output_directory}',
            '--requirements={}'.format(
                virtualenv_source.joinpath('requirements.txt')),
            '--setup-py-roots={}'.format(pigweed_root),
        )

    os.environ['PATH'] = os.pathsep.join((
        str(output_directory.joinpath('bin')),
        os.environ['PATH'],
    ))
コード例 #5
0
def gn_gen(gn_source_dir: Path,
           gn_output_dir: Path,
           *args: str,
           gn_check: bool = True,
           gn_fail_on_unused: bool = True,
           **gn_arguments) -> None:
    """Runs gn gen in the specified directory with optional GN args."""
    args_option = (gn_args(**gn_arguments), ) if gn_arguments else ()

    # Delete args.gn to ensure this is a clean build.
    args_gn = gn_output_dir / 'args.gn'
    if args_gn.is_file():
        args_gn.unlink()

    call('gn',
         'gen',
         gn_output_dir,
         '--color=always',
         *(['--check'] if gn_check else []),
         *(['--fail-on-unused-args'] if gn_fail_on_unused else []),
         *args,
         *args_option,
         cwd=gn_source_dir)
コード例 #6
0
ファイル: python_checks.py プロジェクト: erwincoumans/pigweed
def run_module(*args, **kwargs):
    return call('python', '-m', *args, **kwargs)
コード例 #7
0
ファイル: build.py プロジェクト: turon/pigweed
def cmake(source_dir: Path,
          output_dir: Path,
          env: Mapping['str', 'str'] = None) -> None:
    """Runs CMake for Ninja on the given source and output directories."""
    call('cmake', '-B', output_dir, '-S', source_dir, '-G', 'Ninja', env=env)
コード例 #8
0
ファイル: build.py プロジェクト: turon/pigweed
def ninja(directory: Path, *args, **kwargs) -> None:
    """Runs ninja in the specified directory."""
    call('ninja', '-C', directory, *args, **kwargs)