1414# pre-commit run -av --hook-stage pre-push
1515#
1616default_stages : [commit, push]
17+ default_language_version :
18+ python : python3.11
1719repos :
1820# Recommendation for a minimal git pre-commit hook:
1921# https://github.com/pre-commit/pre-commit-hooks/blob/main/README.md:
@@ -29,6 +31,95 @@ repos:
2931 - id : check-executables-have-shebangs
3032 exclude : ocaml
3133
34+
35+ # Improve Python formatting incrementally:
36+ # https://dev.to/akaihola/improving-python-code-incrementally-3f7a
37+ #
38+ # darker checks if staged python changes are formatted according using
39+ # the PEP8-aligned black formatter. It also checks if the imports are sorted.
40+ #
41+ # It is a good idea to run this before committing, and it is also run in the
42+ # GitHub Workflow.
43+ #
44+ # Note: darker only checks the changes in files ending in .py!
45+ # Python scripts that don't end in .py should be renamed to have the .py extension
46+ # when moving them to python3/bin.
47+ # (remove the .py extension in the Makefile when installing the file)
48+ #
49+ - repo : https://github.com/akaihola/darker
50+ rev : 1.7.3
51+ hooks :
52+ - id : darker
53+ files : python3/
54+ name : check changes in Python3 tree using darker and isort
55+ args : [--diff, --skip-string-normalization, --isort, -tpy36]
56+ additional_dependencies : [isort]
57+
58+ #
59+ # Run pytest and diff-cover to check that the new /python3 test suite in passes.
60+ # This hook uses a local venv containing the required dependencies. When adding
61+ # new dependencies, they should be added to the additional_dependencies below.
62+ #
63+ - repo : local
64+ hooks :
65+ - id : pytest
66+ files : python3/
67+ name : check that the Python3 test suite in passes
68+ entry : env PYTHONDEVMODE=yes sh -c 'coverage run && coverage xml &&
69+ coverage html && coverage report &&
70+ diff-cover --ignore-whitespace --compare-branch=origin/feature/py3
71+ --show-uncovered --html-report .git/coverage-diff.html
72+ --fail-under 50 .git/coverage3.11.xml'
73+ require_serial : true
74+ pass_filenames : false
75+ language : python
76+ types : [python]
77+ additional_dependencies :
78+ - coverage
79+ - diff-cover
80+ - future
81+ - opentelemetry-api
82+ - opentelemetry-exporter-zipkin-json
83+ - opentelemetry-sdk
84+ - pytest-mock
85+ - mock
86+ - wrapt
87+ - XenAPI
88+
89+
90+ - repo : https://github.com/RobertCraigie/pyright-python
91+ rev : v1.1.372
92+ hooks :
93+ - id : pyright
94+ name : check that python3 tree passes pyright/VSCode check
95+ files : python3/
96+ additional_dependencies :
97+ - mock
98+ - opentelemetry-api
99+ - opentelemetry-exporter-zipkin-json
100+ - opentelemetry-sdk
101+ - pytest
102+ - pyudev
103+ - XenAPI
104+
105+
106+ # Check that pylint passes for the changes in new /python3 code.
107+ - repo : local
108+ hooks :
109+ - id : pylint
110+ files : python3/
111+ stages : [push]
112+ name : check that changes to python3 tree pass pylint
113+ entry : diff-quality --violations=pylint
114+ --ignore-whitespace --compare-branch=origin/feature/py3
115+ pass_filenames : false
116+ language : python
117+ types : [python]
118+ additional_dependencies : [diff-cover, pylint, pytest]
119+
120+
121+ # pre-push hook (it only runs if you install pre-commit as a pre-push hook):
122+ # It can be manually tested using: `pre-commit run -av --hook-stage push`
32123# Recommendation for a minimal git pre-push hook:
33124# While using pre-commit yields great results, it
34125# is "not fast". Therefore only run it pre-push,
@@ -53,4 +144,12 @@ repos:
53144 # developers have such version installed, it can be configured here:
54145 # language_version: python3.11
55146 require_serial : true
56- additional_dependencies : [pandas, pytype]
147+ additional_dependencies :
148+ - future
149+ - opentelemetry-api
150+ - opentelemetry-exporter-zipkin-json
151+ - opentelemetry-sdk
152+ - pandas
153+ - pytest
154+ - pytype
155+ files : python3/
0 commit comments