6

I have a Python project that when I try to commit (through miniconda) with:

$ git add -A && git commit -m `test`

I get the following failure:

(base) D:\machinelearning.com-python>git commit -m 'test'
[WARNING] Unstaged files detected.
[INFO] Stashing unstaged files to C:\Users\anon/.cache\pre-commit\patch1570560215.
Trim Trailing Whitespace.................................................Passed
Check for added large files..............................................Passed
Check python ast.........................................................Passed
Check JSON...........................................(no files to check)Skipped
Check for merge conflicts................................................Passed
Check Xml............................................(no files to check)Skipped
Check Yaml...........................................(no files to check)Skipped
Debug Statements (Python)................................................Passed
Fix End of Files.........................................................Passed
Fix requirements.txt.................................(no files to check)Skipped
Mixed line ending........................................................Passed
Flake8...................................................................Passed
isort....................................................................Failed
hookid: isort

Files were modified by this hook. Additional output:

Fixing D:\machinelearning.com-python\scripts\train_model.py

[INFO] Restored changes from C:\Users\anon/.cache\pre-commit\patch1570560215.

The last line failed.

Any idea on how to solve this issue?

Thanks!

FlyingTeller
  • 17,638
  • 3
  • 38
  • 53
Viewsonic
  • 827
  • 2
  • 15
  • 34

2 Answers2

19

Given the output, it looks like the imports in that file aren't sorted properly -- it should have fixed them automatically for you. If you run git status and/or git diff it'll show what is not staged and what changed

You'll then git add those changes and then commit again

Note that generally when working with isort via pre-commit you'll also want to include seed-isort-config such that third party imports are detected properly

disclosure: I am the author of pre-commit and seed-isort-config

anthony sottile
  • 61,815
  • 15
  • 148
  • 207
  • README says _`isort` when run in isolation is not the best at determining what dependencies are third party_ - can you elaborate please, either here or in README? How is `isort` detecting 3rd party dependencies and why isn't it always working as expected? – Marek Grzenkowicz Apr 27 '20 at 12:36
  • 1
    it ~essentially tries to import them – anthony sottile Apr 27 '20 at 18:18
  • singIt helps - for me just closing and opening the commit window and re-staging solved the pre-commit issues. – Or b Oct 02 '20 at 16:38
0

for me i used the black profile and it worked.

on .pre-commit-config.yaml:

  - repo: https://github.com/PyCQA/isort
    rev: 5.12.0
    hooks:
      - id: isort
        args: ["--profile=black"] # <-- this one
Michael Henry
  • 644
  • 9
  • 12