Skip to content

Commit c8966c2

Browse files
committed
split a big method
1 parent 0a7e577 commit c8966c2

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

pyprland/command.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,8 @@ def __init__(self):
3333
self.plugins: dict[str, Plugin] = {}
3434
self.log = get_logger()
3535

36-
async def load_config(self, init=True):
37-
"""Loads the configuration
38-
39-
if `init` is true, also initializes the plugins"""
36+
async def __open_config(self):
37+
"""Loads config file as self.config"""
4038
if os.path.exists(OLD_CONFIG_FILE) and not os.path.exists(CONFIG_FILE):
4139
self.log.warning("Consider changing your configuration to TOML format.")
4240

@@ -65,8 +63,10 @@ async def load_config(self, init=True):
6563
self.log.critical("No Config file found ! Please create %s", CONFIG_FILE)
6664
raise PyprError()
6765

68-
assert self.config
69-
66+
async def __load_plugins_config(self, init=True):
67+
"""Loads the plugins mentioned in the config.
68+
If init is `True`, call the `init()` method on each plugin.
69+
"""
7070
for name in cast(dict, self.config["pyprland"]["plugins"]):
7171
if name not in self.plugins:
7272
modname = name if "." in name else f"pyprland.plugins.{name}"
@@ -95,6 +95,15 @@ async def load_config(self, init=True):
9595
self.log.error("Error initializing plugin %s:", name, exc_info=True)
9696
raise PyprError() from e
9797

98+
async def load_config(self, init=True):
99+
"""Loads the configuration
100+
101+
if `init` is true, also initializes the plugins"""
102+
103+
await self.__open_config()
104+
assert self.config
105+
await self.__load_plugins_config(init=init)
106+
98107
async def _callHandler(self, full_name, *params):
99108
"Call an event handler with params"
100109

0 commit comments

Comments
 (0)