Skip to content

Commit a769432

Browse files
MarcoGorellinoatamir
authored andcommitted
STYLE,BUG: autotyping hook fails if run on no files (pandas-dev#48814)
* add run_autotyping script * simplify * exit 0 if no paths Co-authored-by: MarcoGorelli <>
1 parent bedad5f commit a769432

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

.pre-commit-config.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ repos:
268268
|/_testing/
269269
- id: autotyping
270270
name: autotyping
271-
entry: python -m libcst.tool codemod autotyping.AutotypeCommand --aggressive
271+
entry: python -m scripts.run_autotyping
272272
types_or: [python, pyi]
273273
files: ^pandas
274274
exclude: ^(pandas/tests|pandas/_version.py|pandas/io/clipboard)

scripts/run_autotyping.py

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
"""
2+
Script to run ``autotyping``, to get around the fact that
3+
pre-commit puts ``args`` before the list of files, whereas
4+
``autotyping`` wants the files to come after, see
5+
https://github.com/pandas-dev/pandas/issues/48808#issuecomment-1259711679.
6+
"""
7+
from __future__ import annotations
8+
9+
import argparse
10+
import subprocess
11+
import sys
12+
from typing import Sequence
13+
14+
15+
def main(argv: Sequence[str] | None = None) -> None:
16+
parser = argparse.ArgumentParser()
17+
parser.add_argument("paths", nargs="*")
18+
args = parser.parse_args(argv)
19+
if not args.paths:
20+
sys.exit(0)
21+
output = subprocess.run(
22+
[
23+
"python",
24+
"-m",
25+
"libcst.tool",
26+
"codemod",
27+
"autotyping.AutotypeCommand",
28+
*args.paths,
29+
"--aggressive",
30+
],
31+
)
32+
sys.exit(output.returncode)
33+
34+
35+
if __name__ == "__main__":
36+
main()

0 commit comments

Comments
 (0)