refactor(server): register loaded module in sys.modules, add __all__
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -4,6 +4,7 @@ between the REST API and the CLI; musicfetch itself is unchanged."""
|
|||||||
import importlib.machinery
|
import importlib.machinery
|
||||||
import importlib.util
|
import importlib.util
|
||||||
import os
|
import os
|
||||||
|
import sys
|
||||||
|
|
||||||
_HERE = os.path.dirname(os.path.abspath(__file__))
|
_HERE = os.path.dirname(os.path.abspath(__file__))
|
||||||
_MF_PATH = os.environ.get("MUSICFETCH_BIN", os.path.join(_HERE, "..", "musicfetch"))
|
_MF_PATH = os.environ.get("MUSICFETCH_BIN", os.path.join(_HERE, "..", "musicfetch"))
|
||||||
@@ -14,6 +15,7 @@ _loader = importlib.machinery.SourceFileLoader("musicfetch_core", _MF_PATH)
|
|||||||
_spec = importlib.util.spec_from_loader("musicfetch_core", _loader)
|
_spec = importlib.util.spec_from_loader("musicfetch_core", _loader)
|
||||||
_mod = importlib.util.module_from_spec(_spec)
|
_mod = importlib.util.module_from_spec(_spec)
|
||||||
_spec.loader.exec_module(_mod) # safe: musicfetch guards main() behind __main__
|
_spec.loader.exec_module(_mod) # safe: musicfetch guards main() behind __main__
|
||||||
|
sys.modules["musicfetch_core"] = _mod
|
||||||
|
|
||||||
Hit = _mod.Hit
|
Hit = _mod.Hit
|
||||||
build_combined_hits = _mod.build_combined_hits
|
build_combined_hits = _mod.build_combined_hits
|
||||||
@@ -22,3 +24,6 @@ act_youtube = _mod.act_youtube
|
|||||||
act_lidarr_album = _mod.act_lidarr_album
|
act_lidarr_album = _mod.act_lidarr_album
|
||||||
act_lidarr_artist = _mod.act_lidarr_artist
|
act_lidarr_artist = _mod.act_lidarr_artist
|
||||||
QUALITY_CHOICES = _mod.QUALITY_CHOICES
|
QUALITY_CHOICES = _mod.QUALITY_CHOICES
|
||||||
|
|
||||||
|
__all__ = ["Hit", "build_combined_hits", "pick", "act_youtube",
|
||||||
|
"act_lidarr_album", "act_lidarr_artist", "QUALITY_CHOICES"]
|
||||||
|
|||||||
@@ -1,3 +1,6 @@
|
|||||||
|
"""Tests for the server.mf loader."""
|
||||||
|
|
||||||
|
|
||||||
def test_mf_reexports_musicfetch_symbols():
|
def test_mf_reexports_musicfetch_symbols():
|
||||||
from server import mf
|
from server import mf
|
||||||
assert hasattr(mf, "Hit")
|
assert hasattr(mf, "Hit")
|
||||||
@@ -6,6 +9,7 @@ def test_mf_reexports_musicfetch_symbols():
|
|||||||
assert callable(mf.act_youtube)
|
assert callable(mf.act_youtube)
|
||||||
assert callable(mf.act_lidarr_album)
|
assert callable(mf.act_lidarr_album)
|
||||||
assert callable(mf.act_lidarr_artist)
|
assert callable(mf.act_lidarr_artist)
|
||||||
|
assert isinstance(mf.QUALITY_CHOICES, list)
|
||||||
|
|
||||||
|
|
||||||
def test_mf_hit_constructs():
|
def test_mf_hit_constructs():
|
||||||
|
|||||||
Reference in New Issue
Block a user