如何配置预先承认的YAML以与诗歌合作?
我在python 3.10.4在这里,并在我的诗歌1.1.13项目中使用.pre-commit-config.yaml文件,该项目使用pyproject.toml
这是我的.pre-commit-config.yaml看起来像
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
# https://stackoverflow.com/questions/64935598/git-pre-commit-get-all-python-files
default_language_version:
python: python3.10
default_stages: [commit, push]
repos:
- repo: local
hooks:
# https://github.com/pre-commit/pre-commit-hooks#check-ast
- id: check-ast
description: Simply checks whether the files parse as valid python.
entry: check-ast
name: Check python syntax
language: system
types: [python]
# https://github.com/pre-commit/pre-commit-hooks#check-added-large-files
- id: check-added-large-files
description: prevents giant files from being committed.
entry: check-added-large-files
name: Check added large files
language: system
# https://github.com/pre-commit/pre-commit-hooks#check-json
- id: check-json
description: Checks json files for parseable syntax.
entry: check-json
name: Check JSON
language: system
types: [json]
# https://github.com/pre-commit/pre-commit-hooks#check-toml
- id: check-toml
description: Checks toml files for parseable syntax.
entry: check-toml
name: Check TOML
language: system
types: [toml]
# https://github.com/pre-commit/pre-commit-hooks#check-yaml
- id: check-yaml
description: Checks yaml files for parseable syntax.
entry: check-yaml
name: Check YAML
language: system
types: [yaml]
# https://github.com/pre-commit/pre-commit-hooks#end-of-file-fixer
- id: end-of-file-fixer
description: Ensures that a file is either empty, or ends with one newline.
entry: end-of-file-fixer
name: End of file fixer
language: system
# https://github.com/pre-commit/pre-commit-hooks#trailing-whitespace
- id: trailing-whitespace
description: Trims trailing whitespace.
entry: trailing-whitespace-fixer
name: Trailing whitespace
language: system
- repo: local
hooks:
- args: ["--verbose"]
id: flake8
description: Command-line utility for enforcing style consistency across Python projects.
entry: flake8
name: flake8
language: python
require_serial: true
types: [python]
- args: ["--verbose"]
id: black
description: The uncompromising Python code formatter
entry: black
name: black
language: python
require_serial: true
types: [python]
- args: ["--verbose"]
id: isort
name: isort
entry: isort
require_serial: true
language: python
types: [python]
- args: ["--verbose"]
exclude: tests/.*$
id: bandit
name: bandit
entry: bandit
language: python
types: [python]
- args: ["--verbose"]
id: mypy
name: mypy
entry: mypy
language: python
require_serial: true
types: [python]
我在我运行一个时 看起来像是什么git commit -m“测试”它失败了以下错误,
Check python syntax......................................................Failed
- hook id: check-ast
- exit code: 1
Executable `check-ast` not found
Check added large files..................................................Failed
- hook id: check-added-large-files
- exit code: 1
Executable `check-added-large-files` not found
Check JSON...........................................(no files to check)Skipped
Check TOML...............................................................Failed
- hook id: check-toml
- exit code: 1
Executable `check-toml` not found
Check YAML...........................................(no files to check)Skipped
End of file fixer........................................................Failed
- hook id: end-of-file-fixer
- exit code: 1
Executable `end-of-file-fixer` not found
Trailing whitespace......................................................Failed
- hook id: trailing-whitespace
- exit code: 1
Executable `trailing-whitespace-fixer` not found
flake8...................................................................Failed
- hook id: flake8
- exit code: 1
Executable `flake8` not found
black....................................................................Failed
- hook id: black
- exit code: 1
Executable `black` not found
isort....................................................................Failed
- hook id: isort
- exit code: 1
Executable `isort` not found
bandit...................................................................Failed
- hook id: bandit
- exit code: 1
Executable `bandit` not found
mypy.....................................................................Failed
- hook id: mypy
- exit code: 1
Executable `mypy` not found
我如何使预订使用诗歌创建的虚拟环境并在本地使用其所有依赖关系?
I am on Python 3.10.4 here and using a .pre-commit-config.yaml file in my Poetry 1.1.13 project that uses pyproject.toml
Here is what my .pre-commit-config.yaml looks like
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
# https://stackoverflow.com/questions/64935598/git-pre-commit-get-all-python-files
default_language_version:
python: python3.10
default_stages: [commit, push]
repos:
- repo: local
hooks:
# https://github.com/pre-commit/pre-commit-hooks#check-ast
- id: check-ast
description: Simply checks whether the files parse as valid python.
entry: check-ast
name: Check python syntax
language: system
types: [python]
# https://github.com/pre-commit/pre-commit-hooks#check-added-large-files
- id: check-added-large-files
description: prevents giant files from being committed.
entry: check-added-large-files
name: Check added large files
language: system
# https://github.com/pre-commit/pre-commit-hooks#check-json
- id: check-json
description: Checks json files for parseable syntax.
entry: check-json
name: Check JSON
language: system
types: [json]
# https://github.com/pre-commit/pre-commit-hooks#check-toml
- id: check-toml
description: Checks toml files for parseable syntax.
entry: check-toml
name: Check TOML
language: system
types: [toml]
# https://github.com/pre-commit/pre-commit-hooks#check-yaml
- id: check-yaml
description: Checks yaml files for parseable syntax.
entry: check-yaml
name: Check YAML
language: system
types: [yaml]
# https://github.com/pre-commit/pre-commit-hooks#end-of-file-fixer
- id: end-of-file-fixer
description: Ensures that a file is either empty, or ends with one newline.
entry: end-of-file-fixer
name: End of file fixer
language: system
# https://github.com/pre-commit/pre-commit-hooks#trailing-whitespace
- id: trailing-whitespace
description: Trims trailing whitespace.
entry: trailing-whitespace-fixer
name: Trailing whitespace
language: system
- repo: local
hooks:
- args: ["--verbose"]
id: flake8
description: Command-line utility for enforcing style consistency across Python projects.
entry: flake8
name: flake8
language: python
require_serial: true
types: [python]
- args: ["--verbose"]
id: black
description: The uncompromising Python code formatter
entry: black
name: black
language: python
require_serial: true
types: [python]
- args: ["--verbose"]
id: isort
name: isort
entry: isort
require_serial: true
language: python
types: [python]
- args: ["--verbose"]
exclude: tests/.*$
id: bandit
name: bandit
entry: bandit
language: python
types: [python]
- args: ["--verbose"]
id: mypy
name: mypy
entry: mypy
language: python
require_serial: true
types: [python]
When I run a git commit -m "test" it fails with the following error
Check python syntax......................................................Failed
- hook id: check-ast
- exit code: 1
Executable `check-ast` not found
Check added large files..................................................Failed
- hook id: check-added-large-files
- exit code: 1
Executable `check-added-large-files` not found
Check JSON...........................................(no files to check)Skipped
Check TOML...............................................................Failed
- hook id: check-toml
- exit code: 1
Executable `check-toml` not found
Check YAML...........................................(no files to check)Skipped
End of file fixer........................................................Failed
- hook id: end-of-file-fixer
- exit code: 1
Executable `end-of-file-fixer` not found
Trailing whitespace......................................................Failed
- hook id: trailing-whitespace
- exit code: 1
Executable `trailing-whitespace-fixer` not found
flake8...................................................................Failed
- hook id: flake8
- exit code: 1
Executable `flake8` not found
black....................................................................Failed
- hook id: black
- exit code: 1
Executable `black` not found
isort....................................................................Failed
- hook id: isort
- exit code: 1
Executable `isort` not found
bandit...................................................................Failed
- hook id: bandit
- exit code: 1
Executable `bandit` not found
mypy.....................................................................Failed
- hook id: mypy
- exit code: 1
Executable `mypy` not found
How do I make pre-commit use the virtual environment created by poetry and use all its dependencies locally?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不建议和不支持您的寻找方式。预先支配的重点是它安装和管理您的工具 - 这样您就不必让贡献者担心在所需版本上安装每个工具。
也就是说,您 can 在使用
语言时逃脱了受支持的路径:system
- 但随后您的贡献者可以正确设置事物,并在适当的版本以及适当的Virtualenv激活并在Virtualenv中安装了适当的版本(这是错误的,通常是不良的体验)。您遇到问题的原因是因为您犯了错误的:)
免责声明:我创建了预先竞争
using pre-commit in the way you're looking for is not recommend and not supported. the point of pre-commit is it installs and manages your tools -- that way you don't have to have your contributors worry about installing each and every tool at the required version.
that said, you can escape the supported path as you're doing with
language: system
-- but then it is on your contributors to have things set up properly and at the proper versions and with the proper virtualenv activated and with the proper versions installed in the virtualenv (which is error prone and generally a bad experience).the reason you're encountering problems is because you're holding it wrong :)
disclaimer: I created pre-commit
首先,配置诗歌在项目内使用虚拟环境。之后,创建一个虚拟环境 Python版本(请参阅
pyproject.toml
)。安装依赖项,然后激活虚拟环境。最后,预先使用准备使用。在此示例中,使用Python> = 3.9.0或用于虚拟环境的4.0.0版本。 使用 config 命令。确保通过
诗歌config -list
命令正确设置它。使用
诗歌安装
安装依赖项。确保其在虚拟环境下安装依赖关系。激活环境后,准备使用预先使用。为了在每次提交之前自动使用预签名。
First, configure poetry to use virtual environments inside the project. After that, create a virtual environment with the appropriate Python version (see in
pyproject.toml
). Install dependencies then activate the virtual environment. Finally, pre-commit is ready to use.In this example use Python >=3.9.0 or <4.0.0 version for the virtual environment. Configure poetry using the config command. Ensure that it is set correctly by
poetry config --list
command.Install dependencies using
poetry install
. Make sure that it installed dependencies under the virtual environment. After activating the environment, pre-commit is ready to used.In order to use pre-commit automatically before every commit.