示例#1
0
def test_expand_paths():
    read_values = []
    globs = ['fixtures/glob/*.txt', 'fixtures/glob/**/*.txt']
    for path in helpers.expand_paths(__file__, globs):
        read_values.append(open(path).read())
    assert set(read_values) == set(
        ['1\n', '2\n', '3\n', 'A\n', 'B\n', 'C\n', 'D\n'])
示例#2
0
def main(check: bool, path: Tuple[Path]) -> None:
    """Format source code with black"""
    arguments = ["black", "-l120"]
    if check:
        arguments.append("--check")

    pypaths = [str(p) for p in expand_paths(path)]
    if not pypaths:
        raise click.BadParameter("No paths found matching {paths!r}".format(paths=path))

    result = subprocess.run(arguments + pypaths)
    sys.exit(result.returncode)
示例#3
0
def main(check: bool, paths: Tuple[Path]) -> None:

    pyfiles = expand_paths(paths)
    args = ["reorder-python-imports", "--py3-plus"]

    if check:
        args.append("--diff-only")

    pypaths = [str(p) for p in pyfiles]
    if not pypaths:
        raise click.BadParameter(
            "No paths found matching {paths!r}".format(paths=paths))

    pc = subprocess.run(args + pypaths)
    sys.exit(pc.returncode)
示例#4
0
def main(exclude_pytest: bool, path: Tuple[Path]) -> None:
    """Run mypy on a list of files"""
    pyfiles = expand_paths(path)

    if not path:
        raise click.BadParameter("No paths found for PATH {!r}".format(path))

    mypy_config = __gitroot__ / "mypy.ini"
    args = ["mypy"]
    if mypy_config.exists():
        args.extend(("--config-file", f"{mypy_config!s}"))

    with tempfile.TemporaryDirectory() as tdir:
        mypy_pyfiles = Path(tdir) / "mypy_pyfiles.txt"
        with mypy_pyfiles.open("w") as fs:
            fs.write("\n".join(str(f) for f in pyfiles))

        args.append(f"@{mypy_pyfiles!s}")
        result = subprocess.run(args)

    sys.exit(result.returncode)
示例#5
0
def test_expand_path_with_single_path():
    expected = helpers.expand_path(__file__, 'fixtures/glob/*.txt')
    actual = helpers.expand_paths(__file__, 'fixtures/glob/*.txt')
    assert actual == expected