Skip to content

Commit

Permalink
Merge pull request #154 from daniel-montanari/mypy
Browse files Browse the repository at this point in the history
Added mypy
  • Loading branch information
jcollins1983 authored May 22, 2023
2 parents b87ed07 + b4901c3 commit dccd06c
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,6 @@ jobs:
- name: Check formatting
run: |
tox -e black
- name: Run mypy with tox
run: |
tox -e mypy
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.idea/
.vscode/
*.pyc
*.csv
!test/core/expect-logs/*.csv
Expand All @@ -7,6 +8,7 @@ build/*
dist/*
src/fixate.egg-info/
.pytest_cache
.mypy_cache
.tox/
src/fixate/config/local_config.json
src/fixate/config/local_config.json.bak
Expand Down
82 changes: 82 additions & 0 deletions mypy.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
# mypy will be incrementally added to the project
# for some reason mypy gives different output if a project is installed in editable mode
# due to how imports are followed
# don't bother with checking tests yet

# the initial goal is to add in as much as possible, without editing any source files
# adding # type: ignore comments everywhere is messy and I'd rather it be used as a last
# resort to suppress a one-off in an otherwise fully typed file
# see https://mypy.readthedocs.io/en/stable/common_issues.html for a list of common fixes
# but preferably edit the config file to filter out broken stuff, rather than per line edits
# the advantage with editing the config rather than suppressing things inline is that there is
# one location to look at in regards to how mypy behaves, and random parts of the code won't be
# ignored and forgotten about due to scattered comments that locally disable type checking

[mypy]
# python_version = # defaults to interpreter version
# tests are severely broken and seem to be confusing the mypy path, so don't include for now
files = scripts,src/fixate/
ignore_missing_imports=true
# here is all the broken stuff to eventually fix up
# this list should not be added to
# delete entries from here as things get worked on
# if things break in the future from turning on new rules,
# then they should be locally disabled for the module they break
# (or fix the actual error)
exclude = (?x)
(
src/fixate/
(
config/
(
__init__.py
|helper.py
)
|core/
(
checks.py
|common.py
|config_util.py
|jig_mapping.py
)
|drivers/
(
dso/
(
helper.py
)
|funcgen/
(
helper.py
|rigol_dg1022.py
)
|pps/
(
__init__.py
|helper.py
)
|__init__.py
|ftdi.py
)
|examples/
(
function_generator.py
|programmable_power_supply.py
|test_script.py
)
)
)



# mypy will also analyse modules if they are imported by a module - even if they are excluded!
# follow_imports=silent prevents this from happening
# create a silent rule for each excluded module, this should match the above exclude list
[mypy-fixate.config,fixate.config.helper]
follow_imports = silent
[mypy-fixate.core.checks,fixate.core.common,fixate.core.config_util,fixate.core.jig_mapping]
follow_imports = silent
[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]
follow_imports = silent
[mypy-fixate.examples.function_generator,fixate.examples.programmable_power_supply,fixate.examples.test_script]
follow_imports = silent
9 changes: 7 additions & 2 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[tox]
envlist = py37,py38,py39,py310,black
envlist = py37,py38,py39,py310,black,mypy
isolated_build = True

[testenv]
Expand Down Expand Up @@ -36,4 +36,9 @@ addopts = --ignore=test/manual
markers =
drivertest : Fixate driver test


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

0 comments on commit dccd06c

Please sign in to comment.