pythonpre-commit-hookpre-commitpre-commit.comisort

sort recommit ignore python file even if asked to scan specifically


I have:

  - repo: https://github.com/asottile/seed-isort-config
    rev: v2.2.0
    hooks:
    -   id: seed-isort-config
  - repo: https://github.com/timothycrosley/isort
    rev: 5.9.2
    hooks:
      - id: isort
        name: Run isort to sort imports
        types: [python3]

I execute:

pre-commit run --files myproject/draft.py 

What I see in the logs:

seed isort known_third_party.............................................Passed
Run isort to sort imports............................(no files to check)Skipped

I don't understand why it says skip? I gave it direct path to python file how can there be no files to check?


Solution

  • you have set types: [python3] which only matches extensionless scripts specifically with a #!/usr/bin/env python3 shebang

    since your myproject/draft.py file does not match that there are no appropriate files to run for isort and so it is skipped

    remove that line, the default matches python files so you don't need to think about it

    also, you don't need seed-isort-config as of isort>=5 so you can remove that as well


    disclaimer: I created pre-commit, and seed-isort-config