From 6c70d8a1c7cd6b42983a64fc9fa01ad1e8856e08 Mon Sep 17 00:00:00 2001 From: MarcoGorelli <> Date: Tue, 27 Sep 2022 17:06:47 +0100 Subject: [PATCH 1/3] add run_autotyping script --- .pre-commit-config.yaml | 2 +- scripts/run_autotyping.py | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 scripts/run_autotyping.py diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 8df6d70a3bed4..c64898cf7df09 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -268,7 +268,7 @@ repos: |/_testing/ - id: autotyping name: autotyping - entry: python -m libcst.tool codemod autotyping.AutotypeCommand --aggressive + entry: python -m scripts.run_autotyping types_or: [python, pyi] files: ^pandas exclude: ^(pandas/tests|pandas/_version.py|pandas/io/clipboard) diff --git a/scripts/run_autotyping.py b/scripts/run_autotyping.py new file mode 100644 index 0000000000000..21914d625d7b5 --- /dev/null +++ b/scripts/run_autotyping.py @@ -0,0 +1,38 @@ +""" +Script to run ``autotyping``, to get around the fact that +pre-commit puts ``args`` before the list of files, whereas +``autotyping`` wants the files to come after, see +https://github.com/pandas-dev/pandas/issues/48808#issuecomment-1259711679. +""" +from __future__ import annotations + +import argparse +import subprocess +import sys +from typing import Sequence + + +def main(argv: Sequence[str] | None = None) -> None: + parser = argparse.ArgumentParser() + parser.add_argument("paths", nargs="*") + args = parser.parse_args(argv) + output = subprocess.run( + [ + "python", + "-m", + "libcst.tool", + "codemod", + "autotyping.AutotypeCommand", + *args.paths, + "--aggressive", + ], + capture_output=True, + text=True, + ) + sys.stdout.write(output.stdout) + sys.stdout.write(output.stderr) + sys.exit(output.returncode) + + +if __name__ == "__main__": + main() From 0a69a3f6124c6dbb78635e6cd58343728d7d84b6 Mon Sep 17 00:00:00 2001 From: MarcoGorelli <> Date: Wed, 28 Sep 2022 09:35:11 +0100 Subject: [PATCH 2/3] simplify --- scripts/run_autotyping.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/scripts/run_autotyping.py b/scripts/run_autotyping.py index 21914d625d7b5..30aeba2fd3949 100644 --- a/scripts/run_autotyping.py +++ b/scripts/run_autotyping.py @@ -26,11 +26,7 @@ def main(argv: Sequence[str] | None = None) -> None: *args.paths, "--aggressive", ], - capture_output=True, - text=True, ) - sys.stdout.write(output.stdout) - sys.stdout.write(output.stderr) sys.exit(output.returncode) From daa7558ec20622fc91c2ae86b2509bbc3ca948f3 Mon Sep 17 00:00:00 2001 From: MarcoGorelli <> Date: Wed, 28 Sep 2022 14:18:08 +0100 Subject: [PATCH 3/3] exit 0 if no paths --- scripts/run_autotyping.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/scripts/run_autotyping.py b/scripts/run_autotyping.py index 30aeba2fd3949..f537b8d16c77a 100644 --- a/scripts/run_autotyping.py +++ b/scripts/run_autotyping.py @@ -16,6 +16,8 @@ def main(argv: Sequence[str] | None = None) -> None: parser = argparse.ArgumentParser() parser.add_argument("paths", nargs="*") args = parser.parse_args(argv) + if not args.paths: + sys.exit(0) output = subprocess.run( [ "python",