Skip to content

Commit ab48205

Browse files
committed
Fix font subset failure handling
Correct font subsetting flow and tidy imports. planner.py: import FontSubsetIntent and move subset-failure handling to use config.font.subset_failure_action (ensures fallback-full falls back to full fonts instead of skipping video); remove duplicated/incorrect code path. muxer.py: small import cleanup and add module logger. Tests: adjust import ordering in test_ass_font_embedder, test_font_subset, and test_muxer to match refactors. This fixes a bug where subsetting failures could incorrectly block muxing.
1 parent 1ee110a commit ab48205

5 files changed

Lines changed: 15 additions & 19 deletions

File tree

plexmuxy/muxer.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from __future__ import annotations
22

33
import json
4+
import logging
45
import os
56
import re
67
import subprocess
@@ -9,9 +10,7 @@
910
from collections import Counter
1011
from dataclasses import replace
1112
from pathlib import Path
12-
from typing import Any, Iterable
13-
14-
import logging
13+
from typing import Any
1514

1615
from .ass_font_embedder import embed_fonts_into_ass
1716
from .dependencies import resolve_mkvmerge
@@ -28,7 +27,6 @@
2827
font_mime_type_for_suffix,
2928
)
3029

31-
3230
logger = logging.getLogger(__name__)
3331

3432

plexmuxy/planner.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
AttachmentPlan,
1717
AudioTrackPlan,
1818
FontResult,
19+
FontSubsetIntent,
1920
FontUsage,
2021
MuxPlan,
2122
PlanBuildResult,
@@ -205,6 +206,15 @@ def plan_font_subsets(
205206
# paths are display-only here; the muxer ignores them in the subset-success
206207
# path and only uses ``plan.attachments`` for the fallback-full policy.
207208
return _subset_preview_fonts(intent), intent, warnings, None
209+
# Subset failures are governed by subset_failure_action (default "fallback-full"),
210+
# NOT missing_font_action (which only applies to the "referenced" font mode). Using
211+
# the wrong field here meant subsetting always skipped the video instead of falling
212+
# back to the full fonts, even with the default fallback policy.
213+
warnings.extend(f"{issue.code}:{issue.message}" for issue in intent.issues)
214+
if config.font.subset_failure_action == "fallback-full":
215+
return fonts, intent, [*warnings, "font_subset_fallback_all"], None
216+
reason = "font_subset_blocked"
217+
return [], intent, warnings, reason
208218

209219

210220
def _subset_preview_fonts(intent: FontSubsetIntent) -> list[Path]:
@@ -225,16 +235,6 @@ def _subset_preview_fonts(intent: FontSubsetIntent) -> list[Path]:
225235
paths.append(resolved)
226236
return paths
227237

228-
warnings.extend(f"{issue.code}:{issue.message}" for issue in intent.issues)
229-
# Subset failures are governed by subset_failure_action (default "fallback-full"),
230-
# NOT missing_font_action (which only applies to the "referenced" font mode). Using
231-
# the wrong field here meant subsetting always skipped the video instead of falling
232-
# back to the full fonts, even with the default fallback policy.
233-
if config.font.subset_failure_action == "fallback-full":
234-
return fonts, intent, [*warnings, "font_subset_fallback_all"], None
235-
reason = "font_subset_blocked"
236-
return [], intent, warnings, reason
237-
238238

239239
def build_output_path(video: Path, input_dir: Path, config: AppConfig) -> Path:
240240
output_dir = resolve_output_dir(video, input_dir, config)

tests/test_ass_font_embedder.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
from __future__ import annotations
22

33
import re
4+
from pathlib import Path
45

56
from fontTools.ttLib import TTFont
6-
from pathlib import Path
77

88
from plexmuxy.ass_font_embedder import embed_fonts_into_ass
9-
109
from tests.font_test_utils import build_test_ttf
1110

1211

tests/test_font_subset.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from fontTools.ttLib import TTCollection, TTFont
88

99
from plexmuxy.font_catalog import build_font_catalog
10-
from plexmuxy.font_subset import FontSubsetError, validate_subset_font, subset_font_face
10+
from plexmuxy.font_subset import FontSubsetError, subset_font_face, validate_subset_font
1111
from tests.font_test_utils import build_test_ttf
1212

1313

tests/test_muxer.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
from pathlib import Path
22

33
from plexmuxy.config import default_config
4-
from plexmuxy.models import AttachmentPlan, MuxPlan, MuxResult, SubtitleTrackPlan
4+
from plexmuxy.models import AttachmentPlan, MuxPlan, MuxResult, PreparedMuxPlan, SubtitleTrackPlan
55
from plexmuxy.muxer import execute_mux_plan, execute_prepared_mux_plan
6-
from plexmuxy.models import PreparedMuxPlan
76
from tests.font_test_utils import build_test_ttf
87

98

0 commit comments

Comments
 (0)