From a1362a0c1aa12161f1563469d707a8f07964efcf Mon Sep 17 00:00:00 2001 From: Dariusz L Date: Sun, 2 Aug 2026 18:06:28 +0200 Subject: [PATCH] refactor: inject download directory dependencies --- core/download/directories.py | 15 +++++++++------ core/downloader.py | 15 +++++++++++++++ 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/core/download/directories.py b/core/download/directories.py index aa79242..ea8a904 100644 --- a/core/download/directories.py +++ b/core/download/directories.py @@ -1,21 +1,24 @@ """Download directory resolution used by the downloader facade.""" -import importlib import os -from typing import List, Optional +from typing import Any, List, Optional -def _downloader_module(): - """Return the facade so runtime patches remain effective.""" - return importlib.import_module("core.downloader") +def _require_dependencies(dependencies: Any) -> Any: + """Return explicitly supplied services for directory resolution.""" + if dependencies is None: + raise RuntimeError("download directory dependencies were not provided") + return dependencies def get_download_directory( category: str, preferred_base_directory: str = "", + *, + dependencies: Any = None, ) -> Optional[str]: """Get the appropriate download directory for a model category.""" - facade = _downloader_module() + facade = _require_dependencies(dependencies) folder_paths = facade.folder_paths if folder_paths is None: diff --git a/core/downloader.py b/core/downloader.py index 6734d56..df27d90 100644 --- a/core/downloader.py +++ b/core/downloader.py @@ -252,6 +252,15 @@ def _bind_aria2_dependencies(function): return bound +def _bind_download_dependencies(function): + """Bind the downloader facade as explicit download-module dependencies.""" + def bound(*args: Any, **kwargs: Any): + kwargs.setdefault("dependencies", sys.modules[__name__]) + return function(*args, **kwargs) + + return bound + + for _aria2_dependency_name in ( "download_file_with_aria2", "get_aria2_status", @@ -284,6 +293,12 @@ for _aria2_dependency_name in ( ) +for _download_dependency_name in ("get_download_directory",): + globals()[_download_dependency_name] = _bind_download_dependencies( + globals()[_download_dependency_name] + ) + + def _state_dependencies() -> DownloadStateDependencies: """Build state dependencies from the current facade patchpoints.""" return DownloadStateDependencies(