Files
Medios-Macina/tool/__init__.py
T

43 lines
1.3 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""Tool helpers.
This package contains wrappers around external tools (e.g. yt-dlp) so cmdlets can share
common defaults (cookies, timeouts, format selectors) and users can override them via
`config.conf`.
"""
from __future__ import annotations
# Lazy-loaded to avoid pulling in yt_dlp, playwright, and their heavy transitive
# dependencies (~12 s) at package import time. Each submodule is loaded only when
# a name from it is first accessed through this package namespace.
__all__ = [
"YtDlpTool",
"YtDlpDefaults",
"PlaywrightTool",
"PlaywrightDefaults",
"FlorenceVisionTool",
"FlorenceVisionDefaults",
]
_MODULE_ATTRS = {
"YtDlpTool": ".ytdlp",
"YtDlpDefaults": ".ytdlp",
"PlaywrightTool": ".playwright",
"PlaywrightDefaults": ".playwright",
"FlorenceVisionTool": ".florencevision",
"FlorenceVisionDefaults": ".florencevision",
}
def __getattr__(name: str) -> object:
submod = _MODULE_ATTRS.get(name)
if submod is None:
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
from importlib import import_module
mod = import_module(submod, package=__name__)
obj = getattr(mod, name)
# Cache on this module so subsequent accesses bypass __getattr__.
globals()[name] = obj
return obj