Skip to content

STYLE,BUG: autotyping hook fails if run on no files #48808

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
MarcoGorelli opened this issue Sep 27, 2022 · 4 comments · Fixed by #48814
Closed

STYLE,BUG: autotyping hook fails if run on no files #48808

MarcoGorelli opened this issue Sep 27, 2022 · 4 comments · Fixed by #48814
Labels
Code Style Code style, linting, code_checks

Comments

@MarcoGorelli
Copy link
Member

MarcoGorelli commented Sep 27, 2022

Not sure why yet, but here's what I got after a commit:

(pandas-dev) marcogorelli@DESKTOP-U8OKFP3:~/pandas-dev/doc$ git commit -a -m 'doc'
absolufy-imports........................................................................................Passed
vulture.................................................................................................Passed
black...................................................................................................Passed
codespell...............................................................................................Passed
cython-lint.........................................................................(no files to check)Skipped
debug statements (python)...............................................................................Passed
fix end of files........................................................................................Passed
trim trailing whitespace................................................................................Passed
cpplint.............................................................................(no files to check)Skipped
flake8..................................................................................................Passed
isort...................................................................................................Passed
pyupgrade...............................................................................................Passed
rst ``code`` is two backticks.......................................................(no files to check)Skipped
rst directives end with two colons......................................................................Passed
rst ``inline code`` next to normal text.................................................................Passed
Sphinx lint.........................................................................(no files to check)Skipped
Strip unnecessary `# noqa`s.............................................................................Passed
flake8-rst..........................................................................(no files to check)Skipped
Unwanted patterns.......................................................................................Passed
Check Cython casting is `<type>obj`, not `<type> obj`...............................(no files to check)Skipped
Check for backticks incorrectly rendering because of missing spaces.................(no files to check)Skipped
Check for unnecessary random seeds in asv benchmarks................................(no files to check)Skipped
Check for usage of numpy testing or array_equal.....................................(no files to check)Skipped
Check for invalid EA testing........................................................(no files to check)Skipped
Generate pip dependency from conda..................................................(no files to check)Skipped
Check flake8 version is synced across flake8, yesqa, and environment.yml............(no files to check)Skipped
Validate correct capitalization among titles in documentation.......................(no files to check)Skipped
Import pandas.array as pd_array in core.................................................................Passed
Use pandas.io.common.urlopen instead of urllib.request.urlopen..........................................Passed
Use bool_t instead of bool in pandas/core/generic.py................................(no files to check)Skipped
Ensure pandas errors are documented in doc/source/reference/testing.rst.............(no files to check)Skipped
Check for pg8000 not installed on CI for test_pg8000_sqlalchemy_passthrough_error...(no files to check)Skipped
Check minimum version of dependencies are aligned...................................(no files to check)Skipped
Validate errors locations...............................................................................Passed
flake8-pyi..........................................................................(no files to check)Skipped
import annotations from __future__......................................................................Passed
autotyping..............................................................................................Failed
- hook id: autotyping
- exit code: 2


usage: libcst.tool codemod
       [-h]
       [-j JOBS]
       [-p VERSION]
       [-u [CONTEXT]]
       [--include-generated]
       [--include-stubs]
       [--no-format]
       [--show-successes]
       [--hide-generated-warnings]
       [--hide-blacklisted-warnings]
       [--hide-progress]
       [--annotate-optional [ANNOTATE_OPTIONAL [ANNOTATE_OPTIONAL ...]]]
       [--annotate-named-param [ANNOTATE_NAMED_PARAM [ANNOTATE_NAMED_PARAM ...]]]
       [--none-return]
       [--scalar-return]
       [--bool-param]
       [--int-param]
       [--float-param]
       [--str-param]
       [--bytes-param]
       [--annotate-magics]
       [--annotate-imprecise-magics]
       [--pyanalyze-report PYANALYZE_REPORT]
       [--only-without-imports]
       [--safe [SAFE]]
       [--aggressive [AGGRESSIVE]]
       COMMAND
       PATH
       [PATH ...]
libcst.tool codemod: error: the following arguments are required: PATH

This hook was added in #48191
cc @twoertwein in case you've come across this before (I'll have a look later anyway, just opening an issue for now)

@MarcoGorelli MarcoGorelli added the Code Style Code style, linting, code_checks label Sep 27, 2022
@twoertwein
Copy link
Member

twoertwein commented Sep 27, 2022

Could it be that pre-commit runs autotyping even though no py/pyi files were changed?

edit:
If pre-commit has no option to skip a test when no matching files changed, we could either go for such a workaround evilmartians/lefthook#228 (comment) or create a small python script that exists early if no arguments are provided.

@twoertwein
Copy link
Member

@JelleZijlstra I assume it would be out of your control to allow no paths as autotyping is wrapped inside LibCST?

@JelleZijlstra
Copy link

Yes, the current setup makes it hard. I think it should be possible to change autotyping so that it's invoked as python -m autotyping instead, which would allow us more control over how the codemod is invoked.

@MarcoGorelli
Copy link
Member Author

I think the issue's just that autotyping wants files and then --aggressive

(pandas-dev) marcogorelli@DESKTOP-U8OKFP3:~/pandas-dev$ python -m libcst.tool codemod autotyping.AutotypeCommand pandas/compat/pickle_compat.py --aggressive
Calculating full-repo metadata...
Executing codemod...
All done! ✨ 🍰 ✨
1 file left unchanged.
Finished codemodding 1 files!
 - Transformed 1 files successfully.
 - Skipped 0 files.
 - Failed to codemod 0 files.
 - 0 warnings were generated.
(pandas-dev) marcogorelli@DESKTOP-U8OKFP3:~/pandas-dev$ python -m libcst.tool codemod autotyping.AutotypeCommand --aggressive pandas/compat/pickle_compat.py 
usage: libcst.tool codemod [-h] [-j JOBS] [-p VERSION] [-u [CONTEXT]] [--include-generated] [--include-stubs] [--no-format] [--show-successes]
                           [--hide-generated-warnings] [--hide-blacklisted-warnings] [--hide-progress]
                           [--annotate-optional [ANNOTATE_OPTIONAL [ANNOTATE_OPTIONAL ...]]]
                           [--annotate-named-param [ANNOTATE_NAMED_PARAM [ANNOTATE_NAMED_PARAM ...]]] [--none-return] [--scalar-return] [--bool-param]
                           [--int-param] [--float-param] [--str-param] [--bytes-param] [--annotate-magics] [--annotate-imprecise-magics]
                           [--pyanalyze-report PYANALYZE_REPORT] [--only-without-imports] [--safe [SAFE]] [--aggressive [AGGRESSIVE]]
                           COMMAND PATH [PATH ...]
libcst.tool codemod: error: the following arguments are required: PATH

IMO simplest thing would be to just have a local script that runs it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Code Style Code style, linting, code_checks
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants