python-3.x - Python 项目的预提交 Hook 失败

标签 python-3.x anaconda githooks miniconda pre-commit.com

我有一个 Python当我尝试提交(通过 miniconda)时的项目:

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

我得到以下失败:
(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.

最后一行失败。

关于如何解决这个问题的任何想法?

谢谢!

最佳答案

鉴于输出,该文件中的导入似乎没有正确排序——它应该为您自动修复它们。如果您运行 git status和/或 git diff它会显示什么没有上演,什么改变了

然后你会git add这些更改然后再次提交

请注意,通常在使用 isort 时来自 pre-commit您还需要包含 seed-isort-config 以便正确检测第三方进口

披露:我是pre-commit的作者和 seed-isort-config

关于python-3.x - Python 项目的预提交 Hook 失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58295748/

相关文章:

python - 从嵌套列表转换为分隔字符串

anaconda - Jupyter 有 0 个事件内核(Anaconda with Python 2.7)

python - sys.argv[0] 没有在 python 中显示文件名

github api 不返回我的 post-receive web hook

git - 当我使用 rebase 执行 git pull 时,如何禁用 rebase Hook ?

python-3.x - Python中的一组常量

python - 如何根据匹配的子字符串从一个列表创建多个列表?

python - 为什么变量在赋值之前必须声明为全局变量?

python-3.x - 无法在 Spyder 中调整编辑器窗口的大小

bash - Git Hook : '.git/hooks/pre-commit' : Operation not permitted