@@ -48,12 +48,14 @@ def _locate_executable(name: str) -> Optional[str]:
4848 elif _is_system_module (name ): # Check if it's in PATH
4949 return name
5050 else :
51- logger .warning ("Could not find module '{}' in installation directory or PATH" .format (name ))
51+ logger .warning (
52+ "Could not find module '{}' in installation directory or PATH" .format (name )
53+ )
5254 return None
5355
5456
55- """ Look for modules in given directory path and recursively in subdirs matching aw-* """
5657def _discover_modules_in_directory (modules : List [str ], search_path : str ) -> None :
58+ """Look for modules in given directory path and recursively in subdirs matching aw-*"""
5759 matches = glob (os .path .join (search_path , "aw-*" ))
5860 for match in matches :
5961 if os .path .isfile (match ) and os .access (match , os .X_OK ):
@@ -62,10 +64,13 @@ def _discover_modules_in_directory(modules: List[str], search_path: str) -> None
6264 elif os .path .isdir (match ) and os .access (match , os .X_OK ):
6365 _discover_modules_in_directory (modules , match )
6466 else :
65- logger .warning ("Found matching file but was not executable: {}" .format (match ))
67+ logger .warning (
68+ "Found matching file but was not executable: {}" .format (match )
69+ )
70+
6671
67- """ Use _discover_modules_in_directory to find all bundled modules """
6872def _discover_modules_bundled () -> List [str ]:
73+ """Use ``_discover_modules_in_directory`` to find all bundled modules """
6974 modules : List [str ] = []
7075 cwd = os .getcwd ()
7176 _discover_modules_in_directory (modules , cwd )
@@ -76,8 +81,9 @@ def _discover_modules_bundled() -> List[str]:
7681 logger .info ("Found no bundles modules" )
7782 return modules
7883
79- """ Find all aw- modules in PATH """
84+
8085def _discover_modules_system () -> List [str ]:
86+ """Find all aw- modules in PATH"""
8187 search_paths = os .get_exec_path ()
8288 modules = []
8389 for path in search_paths :
@@ -94,7 +100,9 @@ def _discover_modules_system() -> List[str]:
94100class Module :
95101 def __init__ (self , name : str , testing : bool = False ) -> None :
96102 self .name = name
97- self .started = False # Should be True if module is supposed to be running, else False
103+ self .started = (
104+ False # Should be True if module is supposed to be running, else False
105+ )
98106 self .testing = testing
99107 self .location = "system" if _is_system_module (name ) else "bundled"
100108 self ._process : Optional [subprocess .Popen [str ]] = None
@@ -121,16 +129,19 @@ def start(self) -> None:
121129 # See: https://github.com/ActivityWatch/activitywatch/issues/212
122130 startupinfo = None
123131 if platform .system () == "Windows" :
124- startupinfo = subprocess .STARTUPINFO () # type: ignore
125- startupinfo .dwFlags |= subprocess .STARTF_USESHOWWINDOW # type: ignore
132+ startupinfo = subprocess .STARTUPINFO () # type: ignore
133+ startupinfo .dwFlags |= subprocess .STARTF_USESHOWWINDOW # type: ignore
126134 elif platform .system () == "Darwin" :
127135 logger .info ("Macos: Disable dock icon" )
128136 import AppKit
137+
129138 AppKit .NSBundle .mainBundle ().infoDictionary ()["LSBackgroundOnly" ] = "1"
130139
131140 # There is a very good reason stdout and stderr is not PIPE here
132141 # See: https://github.com/ActivityWatch/aw-server/issues/27
133- self ._process = subprocess .Popen (exec_cmd , universal_newlines = True , startupinfo = startupinfo )
142+ self ._process = subprocess .Popen (
143+ exec_cmd , universal_newlines = True , startupinfo = startupinfo
144+ )
134145 self .started = True
135146
136147 def stop (self ) -> None :
@@ -139,13 +150,17 @@ def stop(self) -> None:
139150 """
140151 # TODO: What if a module doesn't stop? Add timeout to p.wait() and then do a p.kill() if timeout is hit
141152 if not self .started :
142- logger .warning ("Tried to stop module {}, but it hasn't been started" .format (self .name ))
153+ logger .warning (
154+ "Tried to stop module {}, but it hasn't been started" .format (self .name )
155+ )
143156 return
144157 elif not self .is_alive ():
145- logger .warning ("Tried to stop module {}, but it wasn't running" .format (self .name ))
158+ logger .warning (
159+ "Tried to stop module {}, but it wasn't running" .format (self .name )
160+ )
146161 else :
147162 if not self ._process :
148- logger .error ("" )
163+ logger .error ("No reference to process object " )
149164 logger .debug ("Stopping module {}" .format (self .name ))
150165 if self ._process :
151166 self ._process .terminate ()
@@ -203,19 +218,25 @@ def discover_modules(self) -> None:
203218 self .modules [m_name ] = Module (m_name , testing = self .testing )
204219
205220 def get_unexpected_stops (self ) -> List [Module ]:
206- return list (filter (lambda x : x .started and not x .is_alive (), self .modules .values ()))
221+ return list (
222+ filter (lambda x : x .started and not x .is_alive (), self .modules .values ())
223+ )
207224
208225 def start (self , module_name : str ) -> None :
209226 if module_name in self .modules .keys ():
210227 self .modules [module_name ].start ()
211228 else :
212- logger .debug ("Manager tried to start nonexistent module {}" .format (module_name ))
229+ logger .debug (
230+ "Manager tried to start nonexistent module {}" .format (module_name )
231+ )
213232
214233 def autostart (self , autostart_modules : Optional [List [str ]]) -> None :
215234 if autostart_modules is None :
216235 autostart_modules = []
217236 if len (autostart_modules ) > 0 :
218- logger .info ("Modules to start weren't specified in CLI arguments. Falling back to configuration." )
237+ logger .info (
238+ "Modules to start weren't specified in CLI arguments. Falling back to configuration."
239+ )
219240 autostart_modules = self .settings .autostart_modules
220241 # We only want to autostart modules that are both in found modules and are asked to autostart.
221242 modules_to_start = set (autostart_modules ).intersection (set (self .modules .keys ()))
0 commit comments