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