@@ -25,6 +25,108 @@ see https://tox.wiki/en/latest/.
2525pre-commit provides a hook into git commit which runs some of the checks
2626against the changes you are about to commit.
2727
28+ Decision detail
29+ ---------------
30+
31+ There are a number of things that CI needs to run:
32+
33+ - pytest
34+ - black
35+ - mypy
36+ - flake8
37+ - isort
38+ - build documentation
39+
40+ The initial approach this module took was to integrate everything
41+ under pytest that had a plugin, and isort under flake8:
42+
43+ .. digraph :: initial
44+
45+ bgcolor=transparent
46+ graph [fontname="Lato" fontsize=10 style=filled fillcolor="#8BC4E9"]
47+ node [fontname="Lato" fontsize=10 shape=box style=filled fillcolor="#8BC4E9"]
48+
49+ subgraph cluster_0 {
50+ label = "pytest"
51+ "pytest-black"
52+ "pytest-mypy"
53+ subgraph cluster_1 {
54+ label = "pytest-flake8"
55+ "flake8-isort"
56+ }
57+ }
58+
59+ This had the advantage that a ``pytest tests `` run in CI would catch and
60+ report all test failures, but made each run take longer than it needed to. Also,
61+ flake8 states that it `does not have a public, stable, Python API
62+ <https://flake8.pycqa.org/en/latest/user/python-api.html> `_ so did not
63+ recommend the approach taken by pytest-flake8.
64+
65+ To address this, the tree was rearranged:
66+
67+ .. digraph :: rearranged
68+
69+ bgcolor=transparent
70+ graph [fontname="Lato" fontsize=10 style=filled fillcolor="#8BC4E9"]
71+ node [fontname="Lato" fontsize=10 shape=box style=filled fillcolor="#8BC4E9"]
72+
73+ pytest
74+ black
75+ mypy
76+ subgraph cluster_1 {
77+ label = "flake8"
78+ "flake8-isort"
79+ }
80+
81+ If using VSCode, this will still run black, flake8 and mypy on file save, but
82+ for those using other editors and for CI another solution was needed. Enter
83+ `pre-commit <https://pre-commit.com/ >`_. This allows hooks to be run at ``git
84+ commit `` time on just the files that have changed, as well as on all tracked
85+ files by CI. All that is needed is a one time install of the git commit hook::
86+
87+ $ pre-commit install
88+
89+ Finally tox was added to run all of the CI checks including
90+ the documentation build. mypy was moved out of the pre-commit and into tox
91+ because it was quite long running and
92+ therefore intrusive. tox can be invoked to run all the checks in
93+ parallel with::
94+
95+ $ tox -p
96+
97+ The graph now looks like:
98+
99+ .. digraph :: rearranged
100+
101+ bgcolor=transparent
102+ graph [fontname="Lato" fontsize=10 style=filled fillcolor="#8BC4E9"]
103+ node [fontname="Lato" fontsize=10 shape=box style=filled fillcolor="#8BC4E9"]
104+
105+ subgraph cluster_0
106+ {
107+ label = "tox -p"
108+ pytest
109+ mypy
110+ "sphinx-build"
111+ subgraph cluster_1 {
112+ label = "pre-commit"
113+ black
114+ subgraph cluster_2 {
115+ label = "flake8"
116+ "flake8-isort"
117+ }
118+ }
119+ }
120+
121+ Now the workflow looks like this:
122+
123+ - Save file, VSCode runs black, flake8 and mypy on it
124+ - Run 'tox -p' and fix issues until it succeeds
125+ - Commit files and pre-commit runs black and flake8 on them (if the
126+ developer had not run tox then this catches some of the most common issues)
127+ - Push to remote and CI runs black, flake8, mypy once on all files
128+ (using tox), then pytest multiple times in a test matrix
129+
28130
29131Consequences
30132------------
0 commit comments