Int*_*rer 12 pre-commit pre-commit-hook flake8 pre-commit.com
我flake8与一堆插件一起使用(,,flake8-docstrings)。我已将它们全部预安装到.flake8-isortflake8-blackvenv
我的仓库要检查pre-commit:
pyproject.toml(配置black和isort)setup.cfg(配置flake8和pydocstyle)\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 foo\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 pyproject.toml\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 setup.cfg\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 (the package)\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 bar\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 pyproject.toml\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 setup.cfg\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 (the package)\n\xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 venv\nRun Code Online (Sandbox Code Playgroud)\n我想为这两个包调用flake8via 。pre-commit
这是我目前的做法:
\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 foo\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 pyproject.toml\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 setup.cfg\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 (the package)\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 bar\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 pyproject.toml\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 setup.cfg\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 (the package)\n\xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 venv\nRun Code Online (Sandbox Code Playgroud)\n当我运行pre-commit run --all-files并且出现错误时foo,它会多次打印相同的输出:
./path/in/foo/to/file.py:49:1: D401 First line should be in imperative mood\n./path/in/foo/to/file.py:49:1: D401 First line should be in imperative mood\n./path/in/foo/to/file.py:49:1: D401 First line should be in imperative mood\n./path/in/foo/to/file.py:49:1: D401 First line should be in imperative mood\n./path/in/foo/to/file.py:49:1: D401 First line should be in imperative mood\n./path/in/foo/to/file.py:49:1: D401 First line should be in imperative mood\n./path/in/foo/to/file.py:49:1: D401 First line should be in imperative mood\n./path/in/foo/to/file.py:49:1: D401 First line should be in imperative mood\n./path/in/foo/to/file.py:49:1: D401 First line should be in imperative mood\n./path/in/foo/to/file.py:49:1: D401 First line should be in imperative mood\n./path/in/foo/to/file.py:49:1: D401 First line should be in imperative mood\nRun Code Online (Sandbox Code Playgroud)\nAnt*_*ile 25
pre-commit根据设计,它对文件进行操作,它还经过优化,可以将针对文件的 linter 批量运行到多个进程中
这里发生的情况是您的配置正在运行多个调用(每个处理器约 1 个)bash -c "cd bar && flake8" file1 file2 file3等。
幸运的是,您可以使用一个设置来解决此问题:
接着就,随即:
---
repos:
- repo: local
hooks:
- id: flake8-foo
name: Run flake8 in foo package
entry: bash -c "cd foo && flake8"
language: python
pass_filenames: false
files: ^foo/
types: [python]
- id: flake8-bar
name: Run flake8 in bar package
entry: bash -c "cd bar && flake8"
language: python
pass_filenames: false
files: ^bar/
types: [python]
Run Code Online (Sandbox Code Playgroud)
也就是说,如果使用钩子,您将失去该框架的大部分好处repo: local:
对于您的 monorepo 设置,我建议仍然以正常方式调用 flake8,但使用--config它,使其适用于您的子存储库:
repos:
- repo: https://gitlab.com/pycqa/flake8
rev: 3.8.4
hooks:
- id: flake8
name: flake8 ./foo/
alias: flake8-foo
files: ^foo/
args: [--config, foo/setup.cfg]
- id: flake8
name: flake8 ./bar/
alias: flake8-bar
files: ^bar/
args: [--config, bar/setup.cfg]
Run Code Online (Sandbox Code Playgroud)
免责声明:我是 pre-commit 的作者,也是 flake8 的当前维护者
| 归档时间: |
|
| 查看次数: |
7510 次 |
| 最近记录: |