diff --git a/.gitignore b/.gitignore --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,4 @@ dist/ version.txt .tox/ +.mypy_cache/ diff --git a/MANIFEST.in b/MANIFEST.in --- a/MANIFEST.in +++ b/MANIFEST.in @@ -3,3 +3,4 @@ include requirements-swh.txt include version.txt recursive-include swh/loader/debian/tests/resources/ * +recursive-include swh py.typed diff --git a/mypy.ini b/mypy.ini new file mode 100644 --- /dev/null +++ b/mypy.ini @@ -0,0 +1,24 @@ +[mypy] +namespace_packages = True +warn_unused_ignores = True + +# support for sqlalchemy magic: see https://github.com/dropbox/sqlalchemy-stubs +plugins = sqlmypy + + +# 3rd party libraries without stubs (yet) + +[mypy-celery.*] +ignore_missing_imports = True + +[mypy-debian.*] +ignore_missing_imports = True + +[mypy-pkg_resources.*] +ignore_missing_imports = True + +[mypy-pytest.*] +ignore_missing_imports = True + +[mypy-requests_mock.*] +ignore_missing_imports = True diff --git a/requirements-test.txt b/requirements-test.txt --- a/requirements-test.txt +++ b/requirements-test.txt @@ -2,3 +2,4 @@ requests-mock sqlalchemy swh.core[db,http] >= 0.0.61 +sqlalchemy-stubs diff --git a/swh/__init__.py b/swh/__init__.py --- a/swh/__init__.py +++ b/swh/__init__.py @@ -1 +1,4 @@ -__path__ = __import__('pkgutil').extend_path(__path__, __name__) +from pkgutil import extend_path +from typing import Iterable + +__path__ = extend_path(__path__, __name__) # type: Iterable[str] diff --git a/swh/loader/__init__.py b/swh/loader/__init__.py --- a/swh/loader/__init__.py +++ b/swh/loader/__init__.py @@ -1 +1,4 @@ -__path__ = __import__('pkgutil').extend_path(__path__, __name__) +from pkgutil import extend_path +from typing import Iterable + +__path__ = extend_path(__path__, __name__) # type: Iterable[str] diff --git a/swh/loader/debian/py.typed b/swh/loader/debian/py.typed new file mode 100644 --- /dev/null +++ b/swh/loader/debian/py.typed @@ -0,0 +1 @@ +# Marker file for PEP 561. diff --git a/swh/loader/debian/tests/test_loader.py b/swh/loader/debian/tests/test_loader.py --- a/swh/loader/debian/tests/test_loader.py +++ b/swh/loader/debian/tests/test_loader.py @@ -9,6 +9,8 @@ import pytest import requests_mock +from typing import Iterable + from swh.core.db.tests.db_testing import SingleDbTestFixture from swh.model.hashutil import hash_to_bytes from swh.storage.schemata.distribution import SQLBase @@ -48,7 +50,7 @@ @pytest.mark.fs class TestDebianLoader(SingleDbTestFixture, BaseLoaderTest): TEST_DB_NAME = 'test-lister-debian' - TEST_DB_DUMP = [] + TEST_DB_DUMP = [] # type: Iterable[str] def setUp(self): super().setUp(archive_name='', diff --git a/tox.ini b/tox.ini --- a/tox.ini +++ b/tox.ini @@ -1,5 +1,5 @@ [tox] -envlist=flake8,py3 +envlist=flake8,mypy,py3 [testenv:py3] deps = @@ -17,3 +17,11 @@ flake8 commands = {envpython} -m flake8 + +[testenv:mypy] +skip_install = true +deps = + .[testing] + mypy +commands = + mypy swh