-
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathcli.py
More file actions
74 lines (61 loc) · 1.49 KB
/
Copy pathcli.py
File metadata and controls
74 lines (61 loc) · 1.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import os
import subprocess
import sys
from pathlib import Path
from typing import List, Optional
import typer
def main(
path: Path = typer.Option(
...,
"--path", "-p",
help="Path of the sub pre-commit call.",
),
files: Optional[List[Path]] = typer.Argument(
None,
help="List of files to pass to sub pre-commit.",
),
config_file: str = typer.Option(
".pre-commit-config.yaml",
"--config-file", "-c",
help="Path to the configuration file for sub pre-commit.",
),
) -> None:
relevant_files = []
if files: # No files mean --all-files was used
for file in files:
if file.is_relative_to(path):
relevant_files.append(file)
if not relevant_files:
print("Nothing to check")
return
print(f"Running pre-commit for {path}:")
print("-" * 79)
print("")
os.chdir(str(path.resolve()))
cmd = [
"sub-pre-commit-run",
"run",
"--config-file",
config_file,
]
if files:
cmd.extend([
"--files",
*[
str(file.relative_to(path))
for file
in relevant_files
],
])
else:
cmd.append("--all-files")
result = subprocess.run(cmd)
print("")
print("-" * 79)
print("")
if result.returncode != 0:
sys.exit(1)
def run() -> None:
typer.run(main)
if __name__ == "__main__":
run()