mirror of
https://github.com/unshackle-dl/unshackle.git
synced 2025-10-23 15:11:08 +00:00
fix(cfg): 🐛 Update services directory handling
* Updated the `services` directory assignment to ensure it is always treated as a list, improving consistency in configuration handling. Allows to provide multiple different service folders.
This commit is contained in:
@@ -65,7 +65,7 @@ def cfg(ctx: click.Context, key: str, value: str, unset: bool, list_: bool) -> N
|
|||||||
|
|
||||||
if not is_write and not is_delete:
|
if not is_write and not is_delete:
|
||||||
data = data.mlget(key_items, default=KeyError)
|
data = data.mlget(key_items, default=KeyError)
|
||||||
if data == KeyError:
|
if data is KeyError:
|
||||||
raise click.ClickException(f"Key '{key}' does not exist in the config.")
|
raise click.ClickException(f"Key '{key}' does not exist in the config.")
|
||||||
yaml.dump(data, sys.stdout)
|
yaml.dump(data, sys.stdout)
|
||||||
else:
|
else:
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ class Config:
|
|||||||
core_dir = Path(__file__).resolve().parent
|
core_dir = Path(__file__).resolve().parent
|
||||||
namespace_dir = core_dir.parent
|
namespace_dir = core_dir.parent
|
||||||
commands = namespace_dir / "commands"
|
commands = namespace_dir / "commands"
|
||||||
services = namespace_dir / "services"
|
services = [namespace_dir / "services"]
|
||||||
vaults = namespace_dir / "vaults"
|
vaults = namespace_dir / "vaults"
|
||||||
fonts = namespace_dir / "fonts"
|
fonts = namespace_dir / "fonts"
|
||||||
user_configs = core_dir.parent
|
user_configs = core_dir.parent
|
||||||
@@ -51,7 +51,10 @@ class Config:
|
|||||||
if name.lower() in ("app_dirs", "core_dir", "namespace_dir", "user_configs", "data"):
|
if name.lower() in ("app_dirs", "core_dir", "namespace_dir", "user_configs", "data"):
|
||||||
# these must not be modified by the user
|
# these must not be modified by the user
|
||||||
continue
|
continue
|
||||||
setattr(self.directories, name, Path(path).expanduser())
|
if name == "services" and isinstance(path, list):
|
||||||
|
setattr(self.directories, name, [Path(p).expanduser() for p in path])
|
||||||
|
else:
|
||||||
|
setattr(self.directories, name, Path(path).expanduser())
|
||||||
|
|
||||||
downloader_cfg = kwargs.get("downloader") or "requests"
|
downloader_cfg = kwargs.get("downloader") or "requests"
|
||||||
if isinstance(downloader_cfg, dict):
|
if isinstance(downloader_cfg, dict):
|
||||||
|
|||||||
@@ -6,7 +6,14 @@ from unshackle.core.config import config
|
|||||||
from unshackle.core.service import Service
|
from unshackle.core.service import Service
|
||||||
from unshackle.core.utilities import import_module_by_path
|
from unshackle.core.utilities import import_module_by_path
|
||||||
|
|
||||||
_SERVICES = sorted((path for path in config.directories.services.glob("*/__init__.py")), key=lambda x: x.parent.stem)
|
_service_dirs = config.directories.services
|
||||||
|
if not isinstance(_service_dirs, list):
|
||||||
|
_service_dirs = [_service_dirs]
|
||||||
|
|
||||||
|
_SERVICES = sorted(
|
||||||
|
(path for service_dir in _service_dirs for path in service_dir.glob("*/__init__.py")),
|
||||||
|
key=lambda x: x.parent.stem,
|
||||||
|
)
|
||||||
|
|
||||||
_MODULES = {path.parent.stem: getattr(import_module_by_path(path), path.parent.stem) for path in _SERVICES}
|
_MODULES = {path.parent.stem: getattr(import_module_by_path(path), path.parent.stem) for path in _SERVICES}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user