Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pre-commit hook failing for a Python project

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!

like image 338
Viewsonic Avatar asked Dec 10 '22 01:12

Viewsonic


1 Answers

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

like image 106
Anthony Sottile Avatar answered Jan 14 '23 00:01

Anthony Sottile