refactor(release): move detect_media_type & enrich_from_probe to application/release

Both helpers are inspection-pipeline pieces, not filesystem use cases —
they belong next to inspect_release, not next to move_media /
resolve_destination / list_folder.

The move also kills the lazy import that was hiding inside
_resolve_parsed: alfred.application.filesystem.resolve_destination
no longer triggers a cycle through alfred.application.filesystem
__init__ when loading inspect_release. Top-level import restored.

Call sites updated: inspect.py, test_detect_media_type.py,
test_enrich_from_probe.py, testing/recognize_folders_in_downloads.py.
Module docstrings + test-file docstrings updated to match the new
location.
This commit is contained in:
2026-05-20 09:29:58 +02:00
parent 0fb59a4581
commit a0d1846ff2
8 changed files with 22 additions and 13 deletions
+13
View File
@@ -15,6 +15,19 @@ callers).
## [Unreleased]
### Internal
- **Moved `detect_media_type` and `enrich_from_probe` from
`alfred.application.filesystem` to `alfred.application.release`**.
They are inspection-pipeline helpers — their natural home is next to
`inspect_release`, not next to the filesystem use cases. The move
also eliminates a circular-import workaround in
`resolve_destination.py`: `inspect_release` can now be imported at
module top instead of lazily inside `_resolve_parsed`. Public
surface is unchanged for callers that imported the helpers from
their full module paths (the only call sites — `inspect.py`, two
tests, one testing script — were updated in this commit).
### Added
- **`resolve_*_destination` use cases now consume `inspect_release`**.
@@ -22,6 +22,7 @@ import logging
from dataclasses import dataclass
from pathlib import Path
from alfred.application.release import inspect_release
from alfred.domain.release import parse_release
from alfred.domain.release.ports import ReleaseKnowledge
from alfred.domain.release.value_objects import ParsedRelease
@@ -51,11 +52,6 @@ def _resolve_parsed(release_name: str, source_path: str | None) -> ParsedRelease
if source_path:
path = Path(source_path)
if path.exists():
# Lazy import: ``alfred.application.release`` indirectly depends
# on this module (via :mod:`detect_media_type` / :mod:`enrich_from_probe`),
# so the import has to happen at call time, not at module load.
from alfred.application.release import inspect_release # noqa: PLC0415
return inspect_release(release_name, path, _KB, _PROBER).parsed
parsed, _ = parse_release(release_name, _KB)
return parsed
+2 -2
View File
@@ -48,8 +48,8 @@ from __future__ import annotations
from dataclasses import dataclass
from pathlib import Path
from alfred.application.filesystem.detect_media_type import detect_media_type
from alfred.application.filesystem.enrich_from_probe import enrich_from_probe
from alfred.application.release.detect_media_type import detect_media_type
from alfred.application.release.enrich_from_probe import enrich_from_probe
from alfred.application.release.supported_media import find_main_video
from alfred.domain.release.ports import ReleaseKnowledge
from alfred.domain.release.services import parse_release
+2 -2
View File
@@ -100,8 +100,8 @@ def main() -> None:
print(c(f"Error: {downloads} does not exist", RED), file=sys.stderr)
sys.exit(1)
from alfred.application.filesystem.detect_media_type import detect_media_type
from alfred.application.filesystem.enrich_from_probe import enrich_from_probe
from alfred.application.release.detect_media_type import detect_media_type
from alfred.application.release.enrich_from_probe import enrich_from_probe
from alfred.domain.release.services import parse_release
from alfred.infrastructure.filesystem.find_video import find_video_file
from alfred.infrastructure.probe import FfprobeMediaProber
+2 -2
View File
@@ -1,4 +1,4 @@
"""Tests for ``alfred.application.filesystem.detect_media_type``.
"""Tests for ``alfred.application.release.detect_media_type``.
The function refines a ``ParsedRelease.media_type`` using filesystem evidence.
@@ -18,7 +18,7 @@ from pathlib import Path
import pytest
from alfred.application.filesystem.detect_media_type import detect_media_type
from alfred.application.release.detect_media_type import detect_media_type
from alfred.domain.release.services import parse_release
from alfred.infrastructure.knowledge.release_kb import YamlReleaseKnowledge
+2 -2
View File
@@ -1,4 +1,4 @@
"""Tests for ``alfred.application.filesystem.enrich_from_probe``.
"""Tests for ``alfred.application.release.enrich_from_probe``.
The function mutates a ``ParsedRelease`` in place using ffprobe ``MediaInfo``.
Token-level values from the release name always win — only ``None`` fields
@@ -18,7 +18,7 @@ Uses real ``ParsedRelease`` / ``MediaInfo`` instances — no mocking needed.
from __future__ import annotations
from alfred.application.filesystem.enrich_from_probe import enrich_from_probe
from alfred.application.release.enrich_from_probe import enrich_from_probe
from alfred.domain.release.value_objects import ParsedRelease
from alfred.domain.shared.media import AudioTrack, MediaInfo, VideoTrack