[INFO] Installing environment for https://github.com/pycqa/isort.
[INFO] Once installed this environment will be reused.
[INFO] This may take a few minutes...
An unexpected error has occurred: CalledProcessError: command: ('/builds/.../.cache/pre-commit/repo0_h0f938/py_env-python3.8/bin/python', '-mpip', 'install', '.')
return code: 1
expected return code: 0
[...]
stderr:
ERROR: Command errored out with exit status 1:
[...]
File "/tmp/pip-build-env-_3j1398p/overlay/lib/python3.8/site-packages/poetry/core/masonry/api.py", line 40, in prepare_metadata_for_build_wheel
poetry = Factory().create_poetry(Path(".").resolve(), with_groups=False)
File "/tmp/pip-build-env-_3j1398p/overlay/lib/python3.8/site-packages/poetry/core/factory.py", line 57, in create_poetry
raise RuntimeError("The Poetry configuration is invalid:\n" + message)
RuntimeError: The Poetry configuration is invalid:
- …Run Code Online (Sandbox Code Playgroud) 有些钩子可能需要一段时间才能运行,我想在推送之前运行它们,但不是在每次特定提交之前运行(例如,pylint 可能有点慢)。
我见过以下内容:
但目前还不清楚我应该如何设置它。
这是我尝试过的:
default_stages: [commit]
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.1.0
hooks:
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/psf/black
rev: 19.10b0
hooks:
- id: black
stages: [push]
Run Code Online (Sandbox Code Playgroud)
由此,我期望前几个钩子在提交之前运行(它们确实如此),但我期望黑色在推送之前运行,但事实并非如此。
为了测试我是否创建了以下文件:
"""This is a docstring."""
print('this should be formatted')
Run Code Online (Sandbox Code Playgroud)
这肯定不是被黑色格式化的。
假设git status给出了这个:
# On branch X
# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
#
# modified: file1.cc
# modified: file1.h
# modified: file1_test.cc
# modified: SConscript
#
# Changes not staged for commit:
# (use "git add <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
# (commit or discard the untracked or modified content in submodules)
#
# modified: file1.cc
# …Run Code Online (Sandbox Code Playgroud) 我正在尝试实现一个流程,以便管理员可以在开发人员签入TFS 2013之前查看所有开发人员的代码.
是否有任何过程需要人工在将代码添加到实际项目之前对其进行审核?
我正在使用TFS 2013和Visual Studio 2013.
互联网上充斥着对这个问题的不正确和不理想的答案.这是不幸的,因为你会认为这将是你想做的常见事情.
问题:当pre-commit钩子运行时,存储库可能不干净.因此,如果你天真地进行测试,他们就不会反对你提交的内容,而是你的工作树中发生的任何污垢.
最明显的事情是git stash --keep-index --include-untracked在的开始pre-commit,并git pop在出口处.这样你就可以测试(纯)索引,这就是我们想要的.
不幸的是,如果你使用它git add --patch,会生成合并冲突标记(特别是如果你编辑了),因为stash@{0}提交后内容可能与工作树不匹配.
另一个常见的解决方案是克隆存储库并在新的临时存储库中运行测试.这有两个问题:一个是我们还没有提交,所以我们不能轻易地获得我们即将提交的状态的存储库副本(我确信有一种方法可以做到这一点) ,但我不感兴趣,因为:).其次,我的测试可能对当前工作目录的位置敏感.例如,由于本地环境配置.
那么:如何在git stash --keep-index --include-untracked不引入合并冲突标记的情况下将我的工作树恢复到它所处的状态,并且不修改提交后的内容HEAD?
我想在预提交中配置黑色并从检查任何迁移文件夹中排除预提交。
我的 pyproject.toml 看起来像这样
[tool.black]
line-length = 79
target-version = ['py37']
include = '\.pyi?$'
exclude = '''
(
/(
\.eggs
| \.git
| \.hg
| \.mypy_cache
| \.tox
| \.venv
| _build
| buck-out
| build
| dist
)/
| ^migrations/
'''
Run Code Online (Sandbox Code Playgroud)
我还配置了预提交。但是在运行pre-commit run --all-files
黑色格式迁移文件夹时,我如何配置黑色
我的计划是使用git来跟踪/ etc中的更改但是在提交时我希望让进行更改的人通过在命令行上添加--author选项将自己指定为作者.
所以我想以root身份停止意外提交.
我尝试创建这个预提交钩子但它不起作用 - 即使我在提交行上指定了作者,git var仍然会返回root.
AUTHOR=`git var GIT_AUTHOR_IDENT | sed -n 's/^\(.*>\).*$/\1/p'`
if [ "$AUTHOR" == "root <root@localhost>" ];
then
echo "Please commit under your own user name instead of \"$AUTHOR\":"
echo 'git commit --author="Adrian"'
echo "or if your name is not already in logs use full ident"
echo 'git commit --author="Adrian Cornish <a@localhost>"'
exit 1
fi
exit 0
Run Code Online (Sandbox Code Playgroud) 我的项目结构如下所示:
project/
app/
main.py
venv/
.pylintrc
.pre-commit-config.yaml
Run Code Online (Sandbox Code Playgroud)
当我尝试编辑project/app/main.py但失败时
Unable to import 'psycopg2' (import-error)
Run Code Online (Sandbox Code Playgroud)
但是当我试图直接对这个文件进行 pylint 时,它可以工作。
.pre-commit-config.yaml 看起来像这样:
- repo: https://github.com/PyCQA/pylint
rev: pylint-2.4.2
hooks:
- id: pylint
Run Code Online (Sandbox Code Playgroud) 我尝试使用赫斯基pre-commit和lint-staged.
安装了这些:
"husky": "^5.1.3",
"lint-staged": "^10.5.4",
Run Code Online (Sandbox Code Playgroud)
在 package.json 我有:
"scripts": {
"build": "gatsby build",
"develop": "gatsby develop",
"format": "prettier --write \"**/*.{js,jsx,ts,tsx,json,md}\"",
"start": "npm run develop",
"serve": "gatsby serve",
"clean": "gatsby clean",
"test": "echo \"Write tests! -> https://gatsby.dev/unit-testing\" && exit 1",
"lint": "eslint --ext .js,.jsx,.ts,.tsx src --color",
"isready": "npm run format && npm run lint && npm run build"
},
"husky": {
"hooks": {
"pre-commit": "lint-staged",
"pre-push": "npm test",
}
},
"lint-staged": {
"./src/*.{js,jsx,ts,tsx}": [
"npm run …Run Code Online (Sandbox Code Playgroud) 我的团队在我们的存储库中使用预提交来运行各种代码检查和格式化程序。我的大多数队友都使用它,但有些人通过使用git commit --no-verify. 无论如何,是否可以在 CI/CD 中运行某些内容以确保所有预提交挂钩都通过(我们正在使用 GitHub 操作)。如果至少有一个钩子失败,则抛出一个错误。
pre-commit ×10
git ×4
python ×2
checkin ×1
eslint ×1
git-index ×1
githooks ×1
hook ×1
husky ×1
isort ×1
lint-staged ×1
pylint ×1
python-black ×1
tfs2013 ×1