refactor: inject download directory dependencies
This commit is contained in:
@@ -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:
|
||||
|
||||
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user