diff --git a/.github/workflows/tox.yml b/.github/workflows/tox.yml index e0e95e66..e6edf851 100644 --- a/.github/workflows/tox.yml +++ b/.github/workflows/tox.yml @@ -44,3 +44,5 @@ jobs: pip install tox tox-gh-actions - name: Linter run: tox -e py37-invalidcode + - name: Mypy + run: tox -e py37-mypy diff --git a/moulinette/actionsmap.py b/moulinette/actionsmap.py index b465f33d..386018ec 100644 --- a/moulinette/actionsmap.py +++ b/moulinette/actionsmap.py @@ -6,6 +6,7 @@ import logging import glob import pickle as pickle +from typing import List, Optional from time import time from collections import OrderedDict from importlib import import_module @@ -30,7 +31,6 @@ logger = logging.getLogger("moulinette.actionsmap") class _ExtraParameter(object): - """ Argument parser for an extra parameter. @@ -39,21 +39,14 @@ class _ExtraParameter(object): """ + name: Optional[str] = None + + """A list of interface for which the parameter doesn't apply to""" + skipped_iface: List[str] = [] + def __init__(self, iface): self.iface = iface - # Required variables - # Each extra parameters classes must overwrite these variables. - - """The extra parameter name""" - name = None - - # Optional variables - # Each extra parameters classes can overwrite these variables. - - """A list of interface for which the parameter doesn't apply""" - skipped_iface = [] - # Virtual methods # Each extra parameters classes can implement these methods. @@ -621,7 +614,7 @@ class ActionsMap(object): # This var is ['*'] by default but could be set for example to # ['yunohost', 'yml_*'] - NAMESPACE_PATTERNS = env["NAMESPACES"] + NAMESPACE_PATTERNS = env["NAMESPACES"].split() # Look for all files that match the given patterns in the actionsmap dir for namespace_pattern in NAMESPACE_PATTERNS: diff --git a/moulinette/core.py b/moulinette/core.py index 3aa024ec..4c0bdcf8 100644 --- a/moulinette/core.py +++ b/moulinette/core.py @@ -22,8 +22,6 @@ for key in env.keys(): if value_from_environ: env[key] = value_from_environ -env["NAMESPACES"] = env["NAMESPACES"].split() - def during_unittests_run(): return "TESTS_RUN" in os.environ diff --git a/moulinette/interfaces/__init__.py b/moulinette/interfaces/__init__.py index a5d32cac..d8bed853 100644 --- a/moulinette/interfaces/__init__.py +++ b/moulinette/interfaces/__init__.py @@ -7,6 +7,7 @@ import copy import datetime from collections import deque, OrderedDict from json.encoder import JSONEncoder +from typing import Optional from moulinette import m18n from moulinette.core import MoulinetteError @@ -44,7 +45,7 @@ class BaseActionsMapParser(object): # Each parser classes must implement these properties. """The name of the interface for which it is the parser""" - interface = None + interface: Optional[str] = None # Virtual methods # Each parser classes must implement these methods. diff --git a/moulinette/interfaces/api.py b/moulinette/interfaces/api.py index 2b57c3c4..9350c76e 100644 --- a/moulinette/interfaces/api.py +++ b/moulinette/interfaces/api.py @@ -268,6 +268,7 @@ class Session: return infos + @staticmethod def delete_infos(): response.set_cookie(f"session.{Session.actionsmap_name}", "", max_age=-1) diff --git a/tox.ini b/tox.ini index 3ffa1342..7fa1cf6a 100644 --- a/tox.ini +++ b/tox.ini @@ -1,6 +1,6 @@ [tox] envlist = - py37-{pytest,lint,invalidcode} + py37-{pytest,lint,invalidcode,mypy} format format-check docs @@ -14,10 +14,12 @@ deps = py37-pytest: .[tests] py37-lint: flake8 py37-invalidcode: flake8 + py37-mypy: mypy >= 0.761 commands = py37-pytest: pytest {posargs} -c pytest.ini py37-lint: flake8 moulinette test py37-invalidcode: flake8 moulinette test --select F + py37-mypy: mypy --ignore-missing-imports --install-types --non-interactive moulinette/ [gh-actions] python =