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 @@ -4,3 +4,4 @@ include version.txt include README.md recursive-include swh/loader/package/tests/ *.tar.gz +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,27 @@ +[mypy] +namespace_packages = True +warn_unused_ignores = True + + +# 3rd party libraries without stubs (yet) + +[mypy-celery.*] +ignore_missing_imports = True + +[mypy-pkg_resources.*] +ignore_missing_imports = True + +[mypy-psutil.*] +ignore_missing_imports = True + +[mypy-psycopg2.*] +ignore_missing_imports = True + +[mypy-pytest.*] +ignore_missing_imports = True + +[mypy-requests_mock.*] +ignore_missing_imports = True + +[mypy-retrying.*] +ignore_missing_imports = True 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/core/loader.py b/swh/loader/core/loader.py --- a/swh/loader/core/loader.py +++ b/swh/loader/core/loader.py @@ -14,6 +14,7 @@ from abc import ABCMeta, abstractmethod from retrying import retry +from typing import Any, Dict, Optional, Tuple from . import converters @@ -112,7 +113,7 @@ - :class:`DebianLoader` """ - CONFIG_BASE_FILENAME = None + CONFIG_BASE_FILENAME = None # type: Optional[str] DEFAULT_CONFIG = { 'storage': ('dict', { @@ -139,9 +140,9 @@ 'revision_packet_size': ('int', 100000), 'release_packet_size': ('int', 100000), 'occurrence_packet_size': ('int', 100000), - } + } # type: Dict[str, Tuple[str, Any]] - ADDITIONAL_CONFIG = {} + ADDITIONAL_CONFIG = {} # type: Dict[str, Tuple[str, Any]] def __init__(self, logging_class=None, config=None): if config: @@ -906,7 +907,7 @@ inherit directly from :class:`BufferedLoader`. """ - ADDITIONAL_CONFIG = {} + ADDITIONAL_CONFIG = {} # type: Dict[str, Tuple[str, Any]] def __init__(self, logging_class=None, config=None): super().__init__(logging_class=logging_class, config=config) diff --git a/swh/loader/core/py.typed b/swh/loader/core/py.typed new file mode 100644 --- /dev/null +++ b/swh/loader/core/py.typed @@ -0,0 +1 @@ +# Marker file for PEP 561. diff --git a/swh/loader/core/tests/test_loader.py b/swh/loader/core/tests/test_loader.py --- a/swh/loader/core/tests/test_loader.py +++ b/swh/loader/core/tests/test_loader.py @@ -19,7 +19,7 @@ def cleanup(self): pass - def prepare(self): + def prepare(self, *args, **kwargs): pass def fetch_data(self): @@ -28,7 +28,7 @@ def store_data(self): pass - def prepare_origin_visit(self): + def prepare_origin_visit(self, *args, **kwargs): origin = self.storage.origin_get( self._test_prepare_origin_visit_data['origin']) self.origin = origin diff --git a/swh/loader/package/loader.py b/swh/loader/package/loader.py --- a/swh/loader/package/loader.py +++ b/swh/loader/package/loader.py @@ -8,7 +8,7 @@ import requests try: - from _version import __version__ + from _version import __version__ # type: ignore except ImportError: __version__ = 'devel' diff --git a/swh/loader/package/tests/test_loader.py b/swh/loader/package/tests/test_loader.py --- a/swh/loader/package/tests/test_loader.py +++ b/swh/loader/package/tests/test_loader.py @@ -6,6 +6,9 @@ import unittest import os import requests_mock + +from typing import List + from swh.loader.package.loader import GNULoader from swh.loader.core.tests import BaseLoaderStorageTest from swh.loader.package.tests.common import ( @@ -98,8 +101,8 @@ } _expected_new_snapshot_first_visit = '2ae491bbaeef7351641997d1b9193aa2a67d26bc' # noqa - _expected_new_contents_invalid_origin = [] - _expected_new_directories_invalid_origin = [] + _expected_new_contents_invalid_origin = [] # type: List[str] + _expected_new_directories_invalid_origin = [] # type: List[str] @classmethod def setUpClass(cls): 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 = @@ -14,3 +14,11 @@ flake8 commands = {envpython} -m flake8 + +[testenv:mypy] +skip_install = true +deps = + .[testing] + mypy +commands = + mypy swh