Skip to content

STYLE: use types_or in pre-commit #38457

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

Merged
merged 4 commits into from
Dec 16, 2020
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
minimum_pre_commit_version: '2.9.0'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's make this 2.9.2, as the release note mentions

Fix default value for types_or so symlink and directory can be matched

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed!

repos:
- repo: https://github.com/python/black
rev: 20.8b1
Expand All @@ -21,10 +22,8 @@ repos:
rev: 5.6.4
hooks:
- id: isort
name: isort (python)
- id: isort
name: isort (cython)
types: [cython]
types: [text]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would also be good add a comment here, like

        types: [text]  # overwrite upstream `types: [python]`

I think such comments work in yaml

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added!

types_or: [python, cython]
- repo: https://github.com/asottile/pyupgrade
rev: v2.7.4
hooks:
Expand Down Expand Up @@ -96,17 +95,17 @@ repos:
name: Check for incorrect code block or IPython directives
language: pygrep
entry: (\.\. code-block ::|\.\. ipython ::)
files: \.(py|pyx|rst)$
types_or: [python, cython, rst]
- id: unwanted-patterns-strings-to-concatenate
name: Check for use of not concatenated strings
language: python
entry: python scripts/validate_unwanted_patterns.py --validation-type="strings_to_concatenate"
files: \.(py|pyx|pxd|pxi)$
types_or: [python, file, executable, text]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this will match too many files - it will match anything that is python or file or executable or text.

Instead, we only want \.(py|pyx|pxd|pxi)$ files. .py is Python. .pyx, .pxd and .pxi are all Cython:

(pandas-dev) marco@marco-Predator-PH315-52:~/pandas-dev$ identify-cli pandas/_libs/lib.pxd
["cython", "file", "non-executable", "text"]
(pandas-dev) marco@marco-Predator-PH315-52:~/pandas-dev$ identify-cli pandas/_libs/lib.pyx
["cython", "file", "non-executable", "text"]
(pandas-dev) marco@marco-Predator-PH315-52:~/pandas-dev$ identify-cli ./pandas/_libs/algos_take_helper.pxi
["cython", "executable", "file", "text"]

So here we want

types_or: [python, cython]

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

- id: unwanted-patterns-strings-with-wrong-placed-whitespace
name: Check for strings with wrong placed spaces
language: python
entry: python scripts/validate_unwanted_patterns.py --validation-type="strings_with_wrong_placed_whitespace"
files: \.(py|pyx|pxd|pxi)$
types_or: [python, file, executable, text]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

- id: unwanted-patterns-private-import-across-module
name: Check for import of private attributes across modules
language: python
Expand Down