From d3b2f71bbddc77316736e48b9ec50de807547170 Mon Sep 17 00:00:00 2001 From: John Chilton Date: Mon, 28 Dec 2020 23:39:55 -0500 Subject: [PATCH] mypy typing for galaxy-web-stack. --- lib/galaxy/web_stack/__init__.py | 9 +++++---- lib/galaxy/web_stack/message.py | 19 ++++++++++--------- lib/galaxy/web_stack/transport.py | 3 ++- packages/test.sh | 2 +- packages/web_stack/galaxy/__init__.py | 2 +- 5 files changed, 19 insertions(+), 16 deletions(-) diff --git a/lib/galaxy/web_stack/__init__.py b/lib/galaxy/web_stack/__init__.py index 832327aa6ba..4b358282b1f 100644 --- a/lib/galaxy/web_stack/__init__.py +++ b/lib/galaxy/web_stack/__init__.py @@ -5,6 +5,7 @@ import inspect import json import logging import os +from typing import Callable, Dict, FrozenSet, List, Optional, Tuple, Type from urllib.request import install_opener # The uwsgi module is automatically injected by the parent uwsgi process and only exists that way. If anything works, @@ -43,10 +44,10 @@ class UWSGILogFilter(logging.Filter): class ApplicationStack: - name = None - prohibited_middleware = frozenset() + name: Optional[str] = None + prohibited_middleware: FrozenSet[str] = frozenset() transport_class = ApplicationStackTransport - log_filter_class = ApplicationStackLogFilter + log_filter_class: Type[logging.Filter] = ApplicationStackLogFilter log_format = '%(name)s %(levelname)s %(asctime)s %(message)s' # TODO: this belongs in the pool configuration server_name_template = '{server_name}' @@ -235,7 +236,7 @@ class UWSGIApplicationStack(MessageApplicationStack): log_format = '%(name)s %(levelname)s %(asctime)s [p:%(process)s,w:%(worker_id)s,m:%(mule_id)s] [%(threadName)s] %(message)s' server_name_template = '{server_name}.{pool_name}.{instance_id}' - postfork_functions = [] + postfork_functions: List[Tuple[Callable, List, Dict]] = [] localhost_addrs = ('127.0.0.1', '[::1]') bind_all_addrs = ('', '0.0.0.0', '[::]') diff --git a/lib/galaxy/web_stack/message.py b/lib/galaxy/web_stack/message.py index 032fe69ac25..10194bd0b8f 100644 --- a/lib/galaxy/web_stack/message.py +++ b/lib/galaxy/web_stack/message.py @@ -4,6 +4,7 @@ import json import logging import types +from typing import Optional, Tuple log = logging.getLogger(__name__) @@ -46,7 +47,7 @@ class ApplicationStackMessageDispatcher: class ApplicationStackMessage(dict): - target = None + _target: Optional[str] = None default_handler = None _validate_kwargs = ('target',) @@ -96,17 +97,17 @@ class ApplicationStackMessage(dict): @property def target(self): - return self['target'] + return self['_target'] @target.setter - def set_target(self, target): - self['target'] = target + def target(self, target): + self['_target'] = target class ParamMessage(ApplicationStackMessage): _validate_kwargs = ('params',) - _validate_params = () - _exclude_params = () + _validate_params: Tuple[str, ...] = () + _exclude_params: Tuple[str, ...] = () def __init__(self, target=None, params=None, **kwargs): super().__init__(target=target) @@ -126,7 +127,7 @@ class ParamMessage(ApplicationStackMessage): return d @params.setter - def set_params(self, params): + def params(self, params): self['params'] = params @@ -151,12 +152,12 @@ class TaskMessage(ParamMessage): class JobHandlerMessage(TaskMessage): - target = 'job_handler' + _target = 'job_handler' _validate_params = ('job_id',) class WorkflowSchedulingMessage(TaskMessage): - target = 'workflow_scheduling' + _target = 'workflow_scheduling' _validate_params = ('workflow_invocation_id',) diff --git a/lib/galaxy/web_stack/transport.py b/lib/galaxy/web_stack/transport.py index 375d552ea75..eb99bbef357 100644 --- a/lib/galaxy/web_stack/transport.py +++ b/lib/galaxy/web_stack/transport.py @@ -3,6 +3,7 @@ import logging import threading +from typing import List from galaxy.util import unicodify @@ -70,7 +71,7 @@ class UWSGIFarmMessageTransport(ApplicationStackTransport): """ Communication via uWSGI Mule Farm messages. Communication is unidirectional (workers -> mules). """ # Define any static lock names here, additional locks will be appended for each configured farm's message handler - _locks = [] + _locks: List[str] = [] def init_late_prefork(self): num = int(uwsgi.opt.get('locks', 0)) + 1 diff --git a/packages/test.sh b/packages/test.sh index 807282718ed..b78f7245648 100755 --- a/packages/test.sh +++ b/packages/test.sh @@ -34,7 +34,7 @@ PACKAGE_DIRS=( # tool_util not yet working 100%, # data has many problems quota, tool shed install database, etc.. RUN_TESTS=(1 1 1 1 1 1 1 1 1 1 0 0) -RUN_MYPY=(1 1 1 1 1 1 1 1 0 0 0 0) +RUN_MYPY=(1 1 1 1 1 1 1 1 1 0 0 0) for ((i=0; i<${#PACKAGE_DIRS[@]}; i++)); do package_dir=${PACKAGE_DIRS[$i]} run_tests=${RUN_TESTS[$i]} diff --git a/packages/web_stack/galaxy/__init__.py b/packages/web_stack/galaxy/__init__.py index 69e3be50dac..0d1f7edf5dc 100644 --- a/packages/web_stack/galaxy/__init__.py +++ b/packages/web_stack/galaxy/__init__.py @@ -1 +1 @@ -__path__ = __import__('pkgutil').extend_path(__path__, __name__) +__path__ = __import__('pkgutil').extend_path(__path__, __name__) # type: ignore