20
20
21
21
22
22
def _log_modules (modules : List ["Module" ]) -> None :
23
- for module in modules :
24
- logger .info (" - {} at {}" . format ( module . name , module . path ) )
23
+ for m in modules :
24
+ logger .info (f " - { m . name } at { m . path } " )
25
25
26
26
27
27
def is_executable (path : str , filename : str ) -> bool :
@@ -53,7 +53,7 @@ def _discover_modules_in_directory(path: str) -> List["Module"]:
53
53
modules .extend (_discover_modules_in_directory (path ))
54
54
else :
55
55
logger .warning (
56
- "Found matching file but was not executable: {}" . format ( path )
56
+ f "Found matching file but was not executable: { path } "
57
57
)
58
58
return modules
59
59
@@ -68,7 +68,7 @@ def _discover_modules_bundled() -> List["Module"]:
68
68
if platform .system () == "Darwin" :
69
69
macos_dir = os .path .abspath (os .path .join (_parent_dir , os .pardir , "MacOS" ))
70
70
search_paths .append (macos_dir )
71
- logger .info ("Searching for bundled modules in: {}" . format ( search_paths ) )
71
+ logger .info (f "Searching for bundled modules in: { search_paths } " )
72
72
73
73
modules : List [Module ] = []
74
74
for path in search_paths :
@@ -87,7 +87,7 @@ def _discover_modules_system() -> List["Module"]:
87
87
if _parent_dir in search_paths :
88
88
search_paths .remove (_parent_dir )
89
89
90
- logger .debug ("Searching for system modules in PATH: {}" . format ( search_paths ) )
90
+ logger .debug (f "Searching for system modules in PATH: { search_paths } " )
91
91
modules : List ["Module" ] = []
92
92
paths = [p for p in search_paths if os .path .isdir (p )]
93
93
for path in paths :
@@ -133,21 +133,10 @@ def __eq__(self, other: Hashable) -> bool:
133
133
return hash (self ) == hash (other )
134
134
135
135
def __repr__ (self ) -> str :
136
- return "<Module {} at {}>" . format ( self .name , self . path )
136
+ return f "<Module { self . name } at { self .path } >"
137
137
138
138
def start (self , testing : bool ) -> None :
139
- logger .info ("Starting module {}" .format (self .name ))
140
-
141
- # Create a process group, become its leader
142
- # TODO: This shouldn't go here
143
- if sys .platform != "win32" :
144
- # Running setpgrp when the python process is a session leader fails,
145
- # such as in a systemd service. See:
146
- # https://stackoverflow.com/a/51005084/1014208
147
- try :
148
- os .setpgrp ()
149
- except PermissionError :
150
- pass
139
+ logger .info (f"Starting module { self .name } " )
151
140
152
141
exec_cmd = [str (self .path )]
153
142
if testing :
@@ -180,23 +169,21 @@ def stop(self) -> None:
180
169
# TODO: What if a module doesn't stop? Add timeout to p.wait() and then do a p.kill() if timeout is hit
181
170
if not self .started :
182
171
logger .warning (
183
- "Tried to stop module {}, but it hasn't been started" . format ( self . name )
172
+ f "Tried to stop module { self . name } , but it hasn't been started"
184
173
)
185
174
return
186
175
elif not self .is_alive ():
187
- logger .warning (
188
- "Tried to stop module {}, but it wasn't running" .format (self .name )
189
- )
176
+ logger .warning (f"Tried to stop module { self .name } , but it wasn't running" )
190
177
else :
191
178
if not self ._process :
192
179
logger .error ("No reference to process object" )
193
- logger .debug ("Stopping module {}" . format ( self .name ) )
180
+ logger .debug (f "Stopping module { self .name } " )
194
181
if self ._process :
195
182
self ._process .terminate ()
196
- logger .debug ("Waiting for module {} to shut down" . format ( self . name ) )
183
+ logger .debug (f "Waiting for module { self . name } to shut down" )
197
184
if self ._process :
198
185
self ._process .wait ()
199
- logger .info ("Stopped module {}" . format ( self .name ) )
186
+ logger .info (f "Stopped module { self .name } " )
200
187
201
188
assert not self .is_alive ()
202
189
self ._last_process = self ._process
@@ -270,7 +257,7 @@ def start(self, module_name: str) -> None:
270
257
system [0 ].start (self .testing )
271
258
else :
272
259
logger .error (
273
- "Manager tried to start nonexistent module {}" . format ( module_name )
260
+ f "Manager tried to start nonexistent module { module_name } "
274
261
)
275
262
276
263
def autostart (self , autostart_modules : List [str ]) -> None :
0 commit comments