enable mypy on CI for core stuff
This commit is contained in:
parent
3912ef2460
commit
1f07e1a2a8
5 changed files with 42 additions and 21 deletions
28
lint
28
lint
|
@ -4,12 +4,14 @@ from pprint import pprint
|
|||
from itertools import chain
|
||||
from subprocess import check_call, run, PIPE
|
||||
import sys
|
||||
import os
|
||||
from typing import List, Optional, Iterable
|
||||
|
||||
|
||||
def log(*args):
|
||||
print(*args, file=sys.stderr)
|
||||
|
||||
CI = 'CI' in os.environ
|
||||
|
||||
DIR = Path(__file__).absolute().parent
|
||||
|
||||
|
@ -29,11 +31,26 @@ def package_name(p: Path) -> str:
|
|||
else:
|
||||
return mname(p)
|
||||
|
||||
# TODO meh.. think how to check _everything_ on CI
|
||||
def core_modules() -> Iterable[str]:
|
||||
return [
|
||||
'my.common',
|
||||
'my.core',
|
||||
'my.cfg',
|
||||
'my.error',
|
||||
'my.init',
|
||||
'tests/misc.py',
|
||||
'tests/get_files.py',
|
||||
]
|
||||
|
||||
def packages() -> Iterable[str]:
|
||||
|
||||
def all_modules() -> Iterable[str]:
|
||||
yield from sorted(set(
|
||||
package_name(p.relative_to(DIR)) for p in (DIR / 'my').rglob('*.py')
|
||||
))
|
||||
yield from sorted(
|
||||
str(f.relative_to(DIR)) for f in (DIR / 'tests').rglob('*.py')
|
||||
)
|
||||
|
||||
|
||||
def pylint():
|
||||
|
@ -42,18 +59,19 @@ def pylint():
|
|||
pass
|
||||
|
||||
|
||||
def mypy(package: str):
|
||||
def mypy(thing: str):
|
||||
is_package = Path(thing).suffix != '.py'
|
||||
return run([
|
||||
'mypy',
|
||||
'--color-output', # TODO eh? doesn't work..
|
||||
'--namespace-packages',
|
||||
'-p', package,
|
||||
*(['-p'] if is_package else []), thing,
|
||||
], stdout=PIPE, stderr=PIPE)
|
||||
|
||||
|
||||
def mypy_all() -> Iterable[Exception]:
|
||||
from concurrent.futures import ThreadPoolExecutor
|
||||
pkgs = list(packages())
|
||||
|
||||
pkgs = list(core_modules() if CI else all_modules())
|
||||
log(f"Checking {pkgs}")
|
||||
with ThreadPoolExecutor() as pool:
|
||||
for p, res in zip(pkgs, pool.map(mypy, pkgs)):
|
||||
|
|
3
mypy.ini
3
mypy.ini
|
@ -2,8 +2,9 @@
|
|||
mypy_path=~/.config/my
|
||||
pretty = True
|
||||
show_error_context = True
|
||||
show_error_codes = True
|
||||
show_error_codes = True
|
||||
check_untyped_defs = True
|
||||
namespace_packages = True
|
||||
|
||||
# it's not controled by me, so for now just ignore..
|
||||
[mypy-my.config.repos.pdfannots.pdfannots]
|
||||
|
|
2
setup.py
2
setup.py
|
@ -48,8 +48,8 @@ def main():
|
|||
extras_require={
|
||||
'testing': [
|
||||
'pytest',
|
||||
'pytz',
|
||||
'pylint',
|
||||
'mypy',
|
||||
],
|
||||
},
|
||||
)
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
from my.coding.commits import get_all_commits
|
||||
from more_itertools import ilen
|
||||
from my.coding.commits import commits
|
||||
|
||||
|
||||
def test():
|
||||
commits = get_all_commits()
|
||||
assert len(commits) > 10
|
||||
all_commits = commits()
|
||||
assert ilen(all_commits) > 10
|
||||
|
|
23
tox.ini
23
tox.ini
|
@ -1,6 +1,6 @@
|
|||
[tox]
|
||||
minversion = 3.5
|
||||
envlist = py3 # ,pylint,mypy
|
||||
envlist = py3,mypy # pylint
|
||||
|
||||
# TODO ugh. unclear how to reuse setup.cfg deps in tox
|
||||
[testenv]
|
||||
|
@ -27,19 +27,20 @@ skip_install = true
|
|||
commands = ./demo.py
|
||||
|
||||
|
||||
# [testenv:mypy]
|
||||
# skip_install = true
|
||||
# commands =
|
||||
# pip install -e .[testing]
|
||||
# python -m mypy --check-untyped src/cachew
|
||||
|
||||
|
||||
[testenv:pylint]
|
||||
# TODO wtf????
|
||||
changedir = {toxworkdir}/{envname}/../..
|
||||
[testenv:mypy]
|
||||
skip_install = true
|
||||
commands =
|
||||
pip install -e .[testing]
|
||||
./lint
|
||||
|
||||
|
||||
# TODO fix it
|
||||
# [testenv:pylint]
|
||||
# # TODO wtf????
|
||||
# changedir = {toxworkdir}/{envname}/../..
|
||||
# skip_install = true
|
||||
# commands =
|
||||
# pip install -e .[testing]
|
||||
# for now ignore import errors until I figure out how to import everything for CI checking..
|
||||
# TODO FIXME ugh. fix later, after properly switched to my.config
|
||||
# python -m pylint -E -d import-error my
|
||||
|
|
Loading…
Add table
Reference in a new issue