Skip to content

Commit dccd06c

Browse files
authored
Merge pull request #154 from daniel-montanari/mypy
Added mypy
2 parents b87ed07 + b4901c3 commit dccd06c

4 files changed

Lines changed: 94 additions & 2 deletions

File tree

.github/workflows/test.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,6 @@ jobs:
3535
- name: Check formatting
3636
run: |
3737
tox -e black
38+
- name: Run mypy with tox
39+
run: |
40+
tox -e mypy

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
.idea/
2+
.vscode/
23
*.pyc
34
*.csv
45
!test/core/expect-logs/*.csv
@@ -7,6 +8,7 @@ build/*
78
dist/*
89
src/fixate.egg-info/
910
.pytest_cache
11+
.mypy_cache
1012
.tox/
1113
src/fixate/config/local_config.json
1214
src/fixate/config/local_config.json.bak

mypy.ini

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
# mypy will be incrementally added to the project
2+
# for some reason mypy gives different output if a project is installed in editable mode
3+
# due to how imports are followed
4+
# don't bother with checking tests yet
5+
6+
# the initial goal is to add in as much as possible, without editing any source files
7+
# adding # type: ignore comments everywhere is messy and I'd rather it be used as a last
8+
# resort to suppress a one-off in an otherwise fully typed file
9+
# see https://mypy.readthedocs.io/en/stable/common_issues.html for a list of common fixes
10+
# but preferably edit the config file to filter out broken stuff, rather than per line edits
11+
# the advantage with editing the config rather than suppressing things inline is that there is
12+
# one location to look at in regards to how mypy behaves, and random parts of the code won't be
13+
# ignored and forgotten about due to scattered comments that locally disable type checking
14+
15+
[mypy]
16+
# python_version = # defaults to interpreter version
17+
# tests are severely broken and seem to be confusing the mypy path, so don't include for now
18+
files = scripts,src/fixate/
19+
ignore_missing_imports=true
20+
# here is all the broken stuff to eventually fix up
21+
# this list should not be added to
22+
# delete entries from here as things get worked on
23+
# if things break in the future from turning on new rules,
24+
# then they should be locally disabled for the module they break
25+
# (or fix the actual error)
26+
exclude = (?x)
27+
(
28+
src/fixate/
29+
(
30+
config/
31+
(
32+
__init__.py
33+
|helper.py
34+
)
35+
|core/
36+
(
37+
checks.py
38+
|common.py
39+
|config_util.py
40+
|jig_mapping.py
41+
)
42+
|drivers/
43+
(
44+
dso/
45+
(
46+
helper.py
47+
)
48+
|funcgen/
49+
(
50+
helper.py
51+
|rigol_dg1022.py
52+
)
53+
|pps/
54+
(
55+
__init__.py
56+
|helper.py
57+
)
58+
|__init__.py
59+
|ftdi.py
60+
)
61+
|examples/
62+
(
63+
function_generator.py
64+
|programmable_power_supply.py
65+
|test_script.py
66+
)
67+
)
68+
)
69+
70+
71+
72+
# mypy will also analyse modules if they are imported by a module - even if they are excluded!
73+
# follow_imports=silent prevents this from happening
74+
# create a silent rule for each excluded module, this should match the above exclude list
75+
[mypy-fixate.config,fixate.config.helper]
76+
follow_imports = silent
77+
[mypy-fixate.core.checks,fixate.core.common,fixate.core.config_util,fixate.core.jig_mapping]
78+
follow_imports = silent
79+
[mypy-fixate.drivers,fixate.drivers.dso.helper,fixate.drivers.funcgen.helper,fixate.drivers.funcgen.rigol_dg1022,fixate.drivers.pps,fixate.drivers.pps.helper,fixate.drivers.ftdi]
80+
follow_imports = silent
81+
[mypy-fixate.examples.function_generator,fixate.examples.programmable_power_supply,fixate.examples.test_script]
82+
follow_imports = silent

tox.ini

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[tox]
2-
envlist = py37,py38,py39,py310,black
2+
envlist = py37,py38,py39,py310,black,mypy
33
isolated_build = True
44

55
[testenv]
@@ -36,4 +36,9 @@ addopts = --ignore=test/manual
3636
markers =
3737
drivertest : Fixate driver test
3838

39-
39+
[testenv:mypy]
40+
basepython = python3
41+
deps = mypy==1.3
42+
# mypy gives different results if you actually install the stuff before you check it
43+
# separate cache to stop weirdness around sharing cache with other instances of mypy
44+
commands = mypy --cache-dir="{envdir}/mypy_cache" --config-file=mypy.ini

0 commit comments

Comments
 (0)