Skip to content

Commit a385078

Browse files
MarcoGorelliMarcoGorelli
authored and
MarcoGorelli
committed
Backport PR pandas-dev#48814: STYLE,BUG: autotyping hook fails if run on no files
1 parent 2e3a40a commit a385078

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

.pre-commit-config.yaml

+11
Original file line numberDiff line numberDiff line change
@@ -252,3 +252,14 @@ repos:
252252
/(__init__\.py)|(api\.py)|(_version\.py)|(testing\.py)|(conftest\.py)$
253253
|/tests/
254254
|/_testing/
255+
- id: autotyping
256+
name: autotyping
257+
entry: python -m scripts.run_autotyping
258+
types_or: [python, pyi]
259+
files: ^pandas
260+
exclude: ^(pandas/tests|pandas/_version.py|pandas/io/clipboard)
261+
language: python
262+
additional_dependencies:
263+
- autotyping==22.9.0
264+
- black==22.6.0
265+
- libcst==0.4.7

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)