Skip to content
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

isort pre-commit hook does not skip text files #3750

Closed
mathause opened this issue Feb 4, 2020 · 4 comments · Fixed by #3911
Closed

isort pre-commit hook does not skip text files #3750

mathause opened this issue Feb 4, 2020 · 4 comments · Fixed by #3911

Comments

@mathause
Copy link
Collaborator

mathause commented Feb 4, 2020

MCVE Code Sample

Add arbitrary change to the file doc/pandas.rst

git add doc/pandas.rst
git commit -m "test"

The pre-commit hook will fail.

Expected Output

the pre-commit hook to pass

Problem Description

running isort -rc doc/* will change the following files:

        modified:   contributing.rst
        modified:   howdoi.rst
        modified:   internals.rst
        modified:   io.rst
        modified:   pandas.rst
        modified:   quick-overview.rst

unfortunately it does not behave properly and deletes/ changes arbitrary lines. Can the pre-commit hook be told to only run on *.py files? On the command line this would be isort -rc *.py

@mathause mathause changed the title isort does not skip text files isort pre-commit hook does not skip text files Feb 4, 2020
@keewis
Copy link
Collaborator

keewis commented Feb 4, 2020

pre-commit allows filtering the files passed to a hook using regular expressions:

   - repo: https://github.com/timothycrosley/isort
     rev: 4.3.21-2
     hooks:
       - id: isort
+        files: ".+[.]py"
   # https://github.com/python/black#version-control-integration
   - repo: https://github.com/python/black

Not sure if this regex is the one we should use, but it does seem to work.

@mathause
Copy link
Collaborator Author

mathause commented Feb 5, 2020

You can tell isort to skip files in the setup.cfg but this seems to be ignored when doing isort file (which is what happens in the pre-commit hook) - see pre-commit/mirrors-isort#9 (comment)

So I think adapting .pre-commit-config.yaml is the way to go at the moment. (Maybe adapt setup.cfg anyway to ensure it does not happen when isort is called with isort -rc .).

@keewis
Copy link
Collaborator

keewis commented Feb 5, 2020

actually, isort does support filtering using --filter-files -sg '*.rst' which would blacklist rst files. Since we don't have just rst files, I think that whitelisting is a better approach. Maybe we should use files: .\.py$?

@asottile
Copy link

asottile commented May 6, 2020

fwiw, the problem here is the -2 tag of isort is broken -- you want 4.3.21 which properly specifies types: [python]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants