From 467cc8e7cafe2120cb2c55cd6e3cf04613147db1 Mon Sep 17 00:00:00 2001 From: Jorge Florian Date: Wed, 23 Mar 2022 20:50:40 +0100 Subject: [PATCH 1/4] type docker folder --- docker/configure_workers_and_start.py | 11 ++++++----- mypy.ini | 1 + 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/docker/configure_workers_and_start.py b/docker/configure_workers_and_start.py index adbb551cee7f..bd0ce6dd42bb 100755 --- a/docker/configure_workers_and_start.py +++ b/docker/configure_workers_and_start.py @@ -29,6 +29,7 @@ import os import subprocess import sys +from typing import Dict, Set, cast import jinja2 import yaml @@ -339,7 +340,7 @@ def generate_worker_files(environ, config_path: str, data_dir: str): # base shared worker jinja2 template. # # This config file will be passed to all workers, included Synapse's main process. - shared_config = {"listeners": listeners} + shared_config: dict = {"listeners": listeners} # The supervisord config. The contents of which will be inserted into the # base supervisord jinja2 template. @@ -355,7 +356,7 @@ def generate_worker_files(environ, config_path: str, data_dir: str): # worker_type: {1234, 1235, ...}} # } # and will be used to construct 'upstream' nginx directives. - nginx_upstreams = {} + nginx_upstreams: Dict[str, Set[int]] = {} # A map of: {"endpoint": "upstream"}, where "upstream" is a str representing what will be # placed after the proxy_pass directive. The main benefit to representing this data as a @@ -384,7 +385,7 @@ def generate_worker_files(environ, config_path: str, data_dir: str): # A counter of worker_type -> int. Used for determining the name for a given # worker type when generating its config file, as each worker's name is just # worker_type + instance # - worker_type_counter = {} + worker_type_counter: Dict[str, int] = {} # For each worker type specified by the user, create config values for worker_type in worker_types: @@ -404,11 +405,11 @@ def generate_worker_files(environ, config_path: str, data_dir: str): # e.g. federation_reader1 worker_name = worker_type + str(new_worker_count) worker_config.update( - {"name": worker_name, "port": worker_port, "config_path": config_path} + {"name": worker_name, "port": str(worker_port), "config_path": config_path} ) # Update the shared config with any worker-type specific options - shared_config.update(worker_config["shared_extra_conf"]) + shared_config.update(cast(dict, worker_config["shared_extra_config"])) # Check if more than one instance of this worker type has been specified worker_type_total_count = worker_types.count(worker_type) diff --git a/mypy.ini b/mypy.ini index 24d4ba15d452..0f60fbb9b8e0 100644 --- a/mypy.ini +++ b/mypy.ini @@ -11,6 +11,7 @@ local_partial_types = True no_implicit_optional = True files = + docker/, scripts-dev/, setup.py, synapse/, From f4fa3e147dbf0bc111edf4a6fb1d6db4eadb6a68 Mon Sep 17 00:00:00 2001 From: Jorge Florian Date: Thu, 24 Mar 2022 08:32:48 +0100 Subject: [PATCH 2/4] add changelog --- changelog.d/12280.misc | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/12280.misc diff --git a/changelog.d/12280.misc b/changelog.d/12280.misc new file mode 100644 index 000000000000..b7b9c4773f6a --- /dev/null +++ b/changelog.d/12280.misc @@ -0,0 +1 @@ +Add missing type definition for scripts in docker folder. Contributed by Jorge Florian. \ No newline at end of file From 01c0e2b9022456b30d625e1b0cf1c2338ca09a1a Mon Sep 17 00:00:00 2001 From: Jorge Florian Date: Thu, 7 Apr 2022 17:49:59 +0200 Subject: [PATCH 3/4] address code review comments Signed-off-by: Jorge Florian --- changelog.d/12280.misc | 2 +- docker/configure_workers_and_start.py | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/changelog.d/12280.misc b/changelog.d/12280.misc index b7b9c4773f6a..bdc00b821a26 100644 --- a/changelog.d/12280.misc +++ b/changelog.d/12280.misc @@ -1 +1 @@ -Add missing type definition for scripts in docker folder. Contributed by Jorge Florian. \ No newline at end of file +Add missing type definitions for scripts in docker folder. Contributed by Jorge Florian. diff --git a/docker/configure_workers_and_start.py b/docker/configure_workers_and_start.py index bd0ce6dd42bb..0167d7290355 100755 --- a/docker/configure_workers_and_start.py +++ b/docker/configure_workers_and_start.py @@ -29,7 +29,7 @@ import os import subprocess import sys -from typing import Dict, Set, cast +from typing import Any, Dict, Set import jinja2 import yaml @@ -37,7 +37,7 @@ MAIN_PROCESS_HTTP_LISTENER_PORT = 8080 -WORKERS_CONFIG = { +WORKERS_CONFIG: Dict[str, Dict[str, Any]] = { "pusher": { "app": "synapse.app.pusher", "listener_resources": [], @@ -340,7 +340,7 @@ def generate_worker_files(environ, config_path: str, data_dir: str): # base shared worker jinja2 template. # # This config file will be passed to all workers, included Synapse's main process. - shared_config: dict = {"listeners": listeners} + shared_config = {"listeners": listeners} # The supervisord config. The contents of which will be inserted into the # base supervisord jinja2 template. @@ -409,7 +409,7 @@ def generate_worker_files(environ, config_path: str, data_dir: str): ) # Update the shared config with any worker-type specific options - shared_config.update(cast(dict, worker_config["shared_extra_config"])) + shared_config.update(worker_config["shared_extra_config"]) # Check if more than one instance of this worker type has been specified worker_type_total_count = worker_types.count(worker_type) From ea1b8ddc1bc6bc86d3e9b4959db820be8eeb25f1 Mon Sep 17 00:00:00 2001 From: Jorge Florian Date: Fri, 8 Apr 2022 11:32:48 +0200 Subject: [PATCH 4/4] fix typo on key name Signed-off-by: Jorge Florian --- docker/configure_workers_and_start.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker/configure_workers_and_start.py b/docker/configure_workers_and_start.py index 0167d7290355..4d5e94ad6f49 100755 --- a/docker/configure_workers_and_start.py +++ b/docker/configure_workers_and_start.py @@ -409,7 +409,7 @@ def generate_worker_files(environ, config_path: str, data_dir: str): ) # Update the shared config with any worker-type specific options - shared_config.update(worker_config["shared_extra_config"]) + shared_config.update(worker_config["shared_extra_conf"]) # Check if more than one instance of this worker type has been specified worker_type_total_count = worker_types.count(worker_type)