diff --git a/lint b/lint index a936041..b126cfb 100755 --- a/lint +++ b/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)): diff --git a/mypy.ini b/mypy.ini index dd90c33..b08156c 100644 --- a/mypy.ini +++ b/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] diff --git a/setup.py b/setup.py index 233829a..d22559b 100644 --- a/setup.py +++ b/setup.py @@ -48,8 +48,8 @@ def main(): extras_require={ 'testing': [ 'pytest', - 'pytz', 'pylint', + 'mypy', ], }, ) diff --git a/tests/commits.py b/tests/commits.py index 5473beb..f49a34f 100644 --- a/tests/commits.py +++ b/tests/commits.py @@ -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 diff --git a/tox.ini b/tox.ini index fdecedf..037e85c 100644 --- a/tox.ini +++ b/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