nik*_*etp 2 python pre-commit-hook pre-commit.com
我有一个简单的 python 项目,目前只有一个文件。它存在于我的项目的 static/cgi-bin 文件夹中。目前,在我的目录的底部,我有一个 .pre-commit-config.yaml 文件,我还没有触及 .git/hooks 文件夹中的文件。我想创建 pre-commit 和 pre-push 钩子,但我似乎无法让它工作。
当我尝试提交时,会发生以下情况:
isort................................................(no files to check)Skipped
flake8...............................................(no files to check)Skipped
black................................................(no files to check)Skipped
当我尝试推送时,出现以下错误:
pytest...................................................................Failed
hookid: pytest
============================= test session starts ==============================
platform darwin -- Python 2.7.15, pytest-4.0.2, py-1.7.0, pluggy-0.8.0
rootdir: /Users/.../deployment, inifile:
collected 0 items
========================= no tests ran in 0.01 seconds =========================
error: failed to push some refs to '...git'
请注意,部署是我正在工作的文件夹。
我在 yaml 文件中的代码是:
repos:
-   repo: local
    hooks:
    - id: isort
      name: isort
      entry: isort
      language: system
      types: [python]
      stages: [commit]
    - id: flake8
      name: flake8
      language: system
      entry: flake8
      types: [python]
      stages: [commit]
    - id: black
      language_version: python3.6
      name: black
      language: system
      entry: black
      types: [python]
      stages: [commit]
    - id: pytest
      name: pytest
      language: system
      entry: pytest
      pass_filenames: false
      always_run: true
      stages: [push]
Ant*_*ile 11
pre-commit将通过的名单,其比赛上演文件types/files向entry上市。
您的提交显示“没有要检查的文件”,因为您的提交中没有 python 文件。你可能想pre-commit run --all-files在第一次引入新钩子时运行
至于你的pytest钩子,pytest 在不运行任何测试时退出非零,因此失败。