Skip to content

Commit 94dc1df

Browse files
committed
Add type hints to new code
1 parent 9dfea4b commit 94dc1df

File tree

2 files changed

+15
-11
lines changed

2 files changed

+15
-11
lines changed

aw_qt/config.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from configparser import ConfigParser
2+
from typing import ClassVar, List
23

34
from aw_core.config import load_config
45
import json
@@ -25,5 +26,5 @@ class AwQtSettings:
2526
def __init__(self, testing: bool):
2627
config_section = qt_config["aw-qt" if not testing else "aw-qt-testing"]
2728

28-
self.possible_modules = json.loads(config_section["possible_modules"])
29-
self.autostart_modules = json.loads(config_section["autostart_modules"])
29+
self.possible_modules: List[str] = json.loads(config_section["possible_modules"])
30+
self.autostart_modules: List[str] = json.loads(config_section["autostart_modules"])

aw_qt/manager.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from time import sleep
44
import logging
55
import subprocess
6-
from typing import Optional, List
6+
from typing import Optional, List, Dict, Set
77

88
import aw_core
99

@@ -129,27 +129,30 @@ def read_log(self) -> str:
129129

130130
class Manager:
131131
def __init__(self, testing: bool = False) -> None:
132-
self.settings = AwQtSettings(testing)
133-
self.modules = {}
132+
self.settings: AwQtSettings = AwQtSettings(testing)
133+
self.modules: Dict[str, Module] = {}
134+
self.autostart_modules: Set[str] = set(self.settings.autostart_modules)
135+
134136
for name in self.settings.possible_modules:
135137
if _locate_executable(name):
136138
self.modules[name] = Module(name, testing=testing)
137139
else:
138-
logger.warning("Module '{}' not found".format(name))
140+
logger.warning("Module '{}' not found but was in possible modules".format(name))
139141

140142
def get_unexpected_stops(self):
141-
return list(filter(lambda x: x.started and not x.is_alive(), self.modules))
143+
return list(filter(lambda x: x.started and not x.is_alive(), self.modules.values()))
142144

143145
def start(self, module_name):
144-
if module_name in self.modules:
146+
if module_name in self.modules.keys():
145147
self.modules[module_name].start()
146148

147149
def autostart(self, autostart_modules):
148-
149150
if autostart_modules is None:
150-
# Modules to start are not specified. Fallback on configuration.
151+
logger.info("Modules to start weren't specified in CLI arguments. Falling back to configuration.")
151152
autostart_modules = self.settings.autostart_modules
152153

154+
# We only want to autostart modules that are both in found modules and are asked to autostart.
155+
autostart_modules = autostart_modules.intersection(set(self.modules.keys()))
153156
# Always start aw-server first
154157
if "aw-server" in autostart_modules:
155158
self.start("aw-server")
@@ -161,7 +164,7 @@ def autostart(self, autostart_modules):
161164
self.start(module_name)
162165

163166
def stop_all(self):
164-
for module in filter(lambda m: m.is_alive(), self.modules):
167+
for module in filter(lambda m: m.is_alive(), self.modules.values()):
165168
module.stop()
166169

167170

0 commit comments

Comments
 (0)