Migrate imports to SYS package (pipeline/result_table) and update related imports
Some checks failed
smoke-mm / Install & smoke test mm --help (push) Has been cancelled

This commit is contained in:
2025-12-29 23:28:15 -08:00
parent 30d3bf480b
commit ef01ca03a0
60 changed files with 162 additions and 149 deletions

View File

@@ -11,7 +11,7 @@ from SYS.logger import log
from pathlib import Path
from typing import Any, Callable, Dict, Iterable, List, Optional, Sequence, Set
from dataclasses import dataclass, field
import models
from SYS import models
@dataclass
@@ -1519,13 +1519,13 @@ def _unique_destination_path(dest: Path) -> Path:
def _print_live_safe_stderr(message: str) -> None:
"""Print to stderr without breaking Rich Live progress output."""
try:
from rich_display import stderr_console # type: ignore
from SYS.rich_display import stderr_console # type: ignore
except Exception:
return
cm = None
try:
import pipeline as _pipeline_ctx # type: ignore
from SYS import pipeline as _pipeline_ctx # type: ignore
suspend = getattr(_pipeline_ctx, "suspend_live_progress", None)
cm = suspend() if callable(suspend) else None
@@ -1714,14 +1714,14 @@ def _print_saved_output_panel(item: Any, final_path: Path) -> None:
try:
from rich.panel import Panel # type: ignore
from rich.table import Table # type: ignore
from rich_display import stderr_console # type: ignore
from SYS.rich_display import stderr_console # type: ignore
except Exception:
return
# If Rich Live progress is active, pause it while printing so the panel
# doesn't get overwritten/truncated by Live's cursor control.
try:
import pipeline as _pipeline_ctx # type: ignore
from SYS import pipeline as _pipeline_ctx # type: ignore
suspend = getattr(_pipeline_ctx, "suspend_live_progress", None)
cm = suspend() if callable(suspend) else None
@@ -2255,7 +2255,7 @@ def coerce_to_pipe_object(
}
# Extract URL: prefer direct url field, then url list
from metadata import normalize_urls
from SYS.metadata import normalize_urls
url_list = normalize_urls(value.get("url"))
url_val = url_list[0] if url_list else None

View File

@@ -8,15 +8,15 @@ import tempfile
import re
from urllib.parse import urlsplit, parse_qs
import models
import pipeline as ctx
from SYS import models
from SYS import pipeline as ctx
from API import HydrusNetwork as hydrus_wrapper
from SYS.logger import log, debug
from SYS.pipeline_progress import PipelineProgress
from SYS.utils_constant import ALL_SUPPORTED_EXTENSIONS
from Store import Store
from . import _shared as sh
from result_table import ResultTable
from SYS.result_table import ResultTable
Cmdlet = sh.Cmdlet
CmdletArg = sh.CmdletArg
@@ -32,7 +32,7 @@ coerce_to_pipe_object = sh.coerce_to_pipe_object
collapse_namespace_tag = sh.collapse_namespace_tag
from API.folder import read_sidecar, find_sidecar, write_sidecar, API_folder_store
from SYS.utils import sha256_file, unique_path
from metadata import write_metadata
from SYS.metadata import write_metadata
# Canonical supported filetypes for all stores/cmdlets
SUPPORTED_MEDIA_EXTENSIONS = ALL_SUPPORTED_EXTENSIONS
@@ -266,7 +266,7 @@ class Add_File(Cmdlet):
# The user then runs @N (optionally piped), which replays add-file with selected paths.
if dir_scan_mode:
try:
from result_table import ResultTable
from SYS.result_table import ResultTable
from pathlib import Path as _Path
# Build base args to replay: keep everything except the directory -path.
@@ -1071,7 +1071,7 @@ class Add_File(Cmdlet):
)
if not refreshed_items:
# Fallback: at least show the add-file payloads as a display overlay
from result_table import ResultTable
from SYS.result_table import ResultTable
table = ResultTable("Result")
for payload in collected_payloads:
@@ -1578,7 +1578,7 @@ class Add_File(Cmdlet):
# If first item is a PipeObject object
try:
# models.PipeObject is an actual class; check attribute presence
import models as _models
from SYS import models as _models
if isinstance(first_item, _models.PipeObject):
path_candidate = getattr(first_item, "path", None)
@@ -1929,7 +1929,7 @@ class Add_File(Cmdlet):
@staticmethod
def _get_url(result: Any, pipe_obj: models.PipeObject) -> List[str]:
from metadata import normalize_urls
from SYS.metadata import normalize_urls
# Prefer explicit PipeObject.url if present
urls: List[str] = []
@@ -2092,7 +2092,7 @@ class Add_File(Cmdlet):
@staticmethod
def _emit_pipe_object(pipe_obj: models.PipeObject) -> None:
from result_table import format_result
from SYS.result_table import format_result
log(format_result(pipe_obj, title="Result"), file=sys.stderr)
ctx.emit(pipe_obj.to_dict())
@@ -2125,7 +2125,7 @@ class Add_File(Cmdlet):
return
try:
from result_table import ResultTable
from SYS.result_table import ResultTable
table = ResultTable("Result")
table.add_result(payload)
@@ -2518,7 +2518,7 @@ class Add_File(Cmdlet):
_best_subtitle_sidecar,
_read_text_file,
)
from models import DownloadOptions
from SYS.models import DownloadOptions
from tool.ytdlp import YtDlpTool
except Exception:
return []
@@ -2681,7 +2681,7 @@ class Add_File(Cmdlet):
paths = getattr(result_obj, "paths", None)
if isinstance(paths, list) and paths:
# Section downloads: create one result per file.
from models import DownloadMediaResult
from SYS.models import DownloadMediaResult
results = []
for p in paths:
@@ -3012,7 +3012,7 @@ class Add_File(Cmdlet):
ctx.set_current_stage_table(table)
print()
from rich_display import stdout_console
from SYS.rich_display import stdout_console
stdout_console().print(table)
print(
@@ -3142,7 +3142,7 @@ class Add_File(Cmdlet):
# If we're moving/copying from one store to another, also copy the source store's
# existing associated URLs so they aren't lost.
try:
from metadata import normalize_urls
from SYS.metadata import normalize_urls
source_store = None
source_hash = None

View File

@@ -7,7 +7,7 @@ import re
from SYS.logger import log
import pipeline as ctx
from SYS import pipeline as ctx
from . import _shared as sh
Cmdlet = sh.Cmdlet

View File

@@ -9,7 +9,7 @@ import sys
from SYS.logger import log
import pipeline as ctx
from SYS import pipeline as ctx
from API import HydrusNetwork as hydrus_wrapper
from . import _shared as sh

View File

@@ -7,8 +7,8 @@ import re
from SYS.logger import log
import models
import pipeline as ctx
from SYS import models
from SYS import pipeline as ctx
from . import _shared as sh
normalize_result_input = sh.normalize_result_input

View File

@@ -3,7 +3,7 @@ from __future__ import annotations
from typing import Any, Dict, List, Optional, Sequence, Tuple
import sys
import pipeline as ctx
from SYS import pipeline as ctx
from . import _shared as sh
from SYS.logger import log
from Store import Store

View File

@@ -14,7 +14,7 @@ from urllib.parse import parse_qs, urlparse
from SYS.logger import log
import pipeline as ctx
from SYS import pipeline as ctx
from SYS.config import resolve_output_dir
from . import _shared as sh

View File

@@ -12,9 +12,9 @@ from Store.Folder import Folder
from Store import Store
from . import _shared as sh
from API import HydrusNetwork as hydrus_wrapper
import pipeline as ctx
from result_table import ResultTable, _format_size
from rich_display import stdout_console
from SYS import pipeline as ctx
from SYS.result_table import ResultTable, _format_size
from SYS.rich_display import stdout_console
class Delete_File(sh.Cmdlet):

View File

@@ -6,7 +6,7 @@ import sys
from SYS.logger import log
import pipeline as ctx
from SYS import pipeline as ctx
from . import _shared as sh
Cmdlet = sh.Cmdlet

View File

@@ -9,7 +9,7 @@ import sys
from SYS.logger import log
import pipeline as ctx
from SYS import pipeline as ctx
from . import _shared as sh
Cmdlet = sh.Cmdlet

View File

@@ -5,8 +5,8 @@ from pathlib import Path
import json
import sys
import models
import pipeline as ctx
from SYS import models
from SYS import pipeline as ctx
from . import _shared as sh
Cmdlet = sh.Cmdlet

View File

@@ -3,7 +3,7 @@ from __future__ import annotations
from typing import Any, Dict, List, Optional, Sequence, Tuple
import sys
import pipeline as ctx
from SYS import pipeline as ctx
from . import _shared as sh
Cmdlet, CmdletArg, SharedArgs, parse_cmdlet_args, get_field, normalize_hash = (
@@ -91,7 +91,7 @@ class Delete_Url(Cmdlet):
log("Error: Invalid hash format")
return 1
from metadata import normalize_urls
from SYS.metadata import normalize_urls
def _urls_from_arg(raw: Any) -> List[str]:
if raw is None:

View File

@@ -17,7 +17,7 @@ from urllib.parse import urlparse
from SYS.download import DownloadError, _download_direct_file
from SYS.logger import log, debug
from SYS.pipeline_progress import PipelineProgress
import pipeline as pipeline_context
from SYS import pipeline as pipeline_context
from . import _shared as sh
@@ -243,7 +243,7 @@ class Download_File(Cmdlet):
)
try:
from result_table import ResultTable
from SYS.result_table import ResultTable
except Exception as exc:
log(f"download-file: ResultTable unavailable: {exc}", file=sys.stderr)
return 1

View File

@@ -30,11 +30,11 @@ from urllib.parse import urlparse
from SYS.logger import log, debug
from SYS.pipeline_progress import PipelineProgress
from SYS.utils import sha256_file
from models import DownloadError, DownloadOptions, DownloadMediaResult, DebugLogger, ProgressBar
import pipeline as pipeline_context
from result_table import ResultTable
from SYS.models import DownloadError, DownloadOptions, DownloadMediaResult, DebugLogger, ProgressBar
from SYS import pipeline as pipeline_context
from SYS.result_table import ResultTable
from rich.prompt import Confirm
from rich_display import stderr_console as get_stderr_console
from SYS.rich_display import stderr_console as get_stderr_console
from . import _shared as sh
QueryArg = sh.QueryArg
@@ -150,7 +150,7 @@ else:
YTDLP_IMPORT_ERROR = None
try:
from metadata import extract_ytdlp_tags
from SYS.metadata import extract_ytdlp_tags
except ImportError:
extract_ytdlp_tags = None
@@ -1718,7 +1718,7 @@ class Download_Media(Cmdlet):
debug(f"Preflight URL check: candidate={candidate_url}")
try:
from metadata import normalize_urls
from SYS.metadata import normalize_urls
except Exception:
normalize_urls = None # type: ignore[assignment]
@@ -1879,7 +1879,7 @@ class Download_Media(Cmdlet):
# Keep the full payload for history/inspection, but display a focused table.
# Use shared extractors so Ext/Size/Store/Hash remain consistent everywhere.
try:
from result_table import build_display_row
from SYS.result_table import build_display_row
except Exception:
build_display_row = None # type: ignore
@@ -2032,7 +2032,7 @@ class Download_Media(Cmdlet):
return True
try:
from metadata import normalize_urls
from SYS.metadata import normalize_urls
except Exception:
normalize_urls = None # type: ignore[assignment]
@@ -2236,7 +2236,7 @@ class Download_Media(Cmdlet):
) or hit.get("sha256") or ""
try:
from result_table import build_display_row
from SYS.result_table import build_display_row
except Exception:
build_display_row = None # type: ignore

View File

@@ -15,7 +15,7 @@ import webbrowser
from urllib.parse import urljoin
from urllib.request import pathname2url
import pipeline as ctx
from SYS import pipeline as ctx
from . import _shared as sh
from SYS.logger import log, debug
from Store import Store

View File

@@ -14,8 +14,8 @@ CmdletArg = sh.CmdletArg
SharedArgs = sh.SharedArgs
parse_cmdlet_args = sh.parse_cmdlet_args
get_field = sh.get_field
import pipeline as ctx
from result_table import ResultTable
from SYS import pipeline as ctx
from SYS.result_table import ResultTable
class Get_Metadata(Cmdlet):

View File

@@ -6,7 +6,7 @@ import sys
from SYS.logger import log
import pipeline as ctx
from SYS import pipeline as ctx
from . import _shared as sh
Cmdlet = sh.Cmdlet

View File

@@ -7,8 +7,8 @@ from pathlib import Path
from SYS.logger import log
import models
import pipeline as ctx
from SYS import models
from SYS import pipeline as ctx
from API import HydrusNetwork as hydrus_wrapper
from . import _shared as sh
@@ -23,7 +23,7 @@ should_show_help = sh.should_show_help
get_field = sh.get_field
from API.folder import API_folder_store
from SYS.config import get_local_storage_path
from result_table import ResultTable
from SYS.result_table import ResultTable
from Store import Store
CMDLET = Cmdlet(
@@ -502,7 +502,7 @@ def _run(result: Any, _args: Sequence[str], config: Dict[str, Any]) -> int:
if not found_relationships:
try:
from rich.panel import Panel
from rich_display import stdout_console
from SYS.rich_display import stdout_console
title = source_title or (hash_hex[:16] + "..." if hash_hex else "Item")
stdout_console().print(
@@ -569,7 +569,7 @@ def _run(result: Any, _args: Sequence[str], config: Dict[str, Any]) -> int:
)
ctx.set_last_result_table(table, pipeline_results)
from rich_display import stdout_console
from SYS.rich_display import stdout_console
stdout_console().print(table)

View File

@@ -27,7 +27,7 @@ import subprocess
from pathlib import Path
from typing import Any, Dict, List, Optional, Sequence, Tuple
import pipeline as ctx
from SYS import pipeline as ctx
from API import HydrusNetwork
from API.folder import read_sidecar, write_sidecar, find_sidecar, API_folder_store
from . import _shared as sh
@@ -42,7 +42,7 @@ get_field = sh.get_field
from SYS.config import get_local_storage_path
try:
from metadata import extract_title
from SYS.metadata import extract_title
except ImportError:
extract_title = None
@@ -152,7 +152,7 @@ def _resolve_candidate_urls_for_item(
) -> List[str]:
"""Get candidate URLs from backend and/or piped result."""
try:
from metadata import normalize_urls
from SYS.metadata import normalize_urls
except Exception:
normalize_urls = None # type: ignore[assignment]
@@ -328,7 +328,7 @@ def _emit_tags_as_table(
This replaces _print_tag_list to make tags pipe-able.
Stores the table in ctx._LAST_RESULT_TABLE for downstream @ selection.
"""
from result_table import ResultTable
from SYS.result_table import ResultTable
# Create ResultTable with just tag column (no title)
# Keep the title stable and avoid including hash fragments.
@@ -776,7 +776,7 @@ def _scrape_url_metadata(
import json as json_module
try:
from metadata import extract_ytdlp_tags
from SYS.metadata import extract_ytdlp_tags
except ImportError:
extract_ytdlp_tags = None
@@ -956,7 +956,7 @@ def _scrape_url_metadata(
# Deduplicate tags by namespace to prevent duplicate title:, artist:, etc.
try:
from metadata import dedup_tags_by_namespace as _dedup
from SYS.metadata import dedup_tags_by_namespace as _dedup
if _dedup:
tags = _dedup(tags, keep_first=True)
@@ -1265,7 +1265,7 @@ def _run(result: Any, args: Sequence[str], config: Dict[str, Any]) -> int:
return 1
try:
from metadata import extract_ytdlp_tags
from SYS.metadata import extract_ytdlp_tags
except Exception:
extract_ytdlp_tags = None # type: ignore[assignment]
@@ -1554,7 +1554,7 @@ def _run(result: Any, args: Sequence[str], config: Dict[str, Any]) -> int:
)
return 0
from result_table import ResultTable
from SYS.result_table import ResultTable
table = ResultTable(f"Metadata: {provider.name}")
table.set_source_command("get-tag", [])

View File

@@ -6,8 +6,6 @@ import sys
import re
from fnmatch import fnmatch
from urllib.parse import urlparse
import pipeline as ctx
from . import _shared as sh
Cmdlet, SharedArgs, parse_cmdlet_args, get_field, normalize_hash = (
@@ -19,6 +17,7 @@ Cmdlet, SharedArgs, parse_cmdlet_args, get_field, normalize_hash = (
)
from SYS.logger import log
from Store import Store
from SYS import pipeline as ctx
@dataclass
@@ -172,7 +171,7 @@ class Get_Url(Cmdlet):
return 1
# Create result table
from result_table import ResultTable
from SYS.result_table import ResultTable
table = (
ResultTable(
@@ -244,7 +243,7 @@ class Get_Url(Cmdlet):
urls = backend.get_url(file_hash)
from result_table import ResultTable
from SYS.result_table import ResultTable
title = str(get_field(result, "title") or "").strip()
table_title = "Title"

View File

@@ -26,7 +26,7 @@ normalize_result_input = sh.normalize_result_input
parse_cmdlet_args = sh.parse_cmdlet_args
should_show_help = sh.should_show_help
import pipeline as ctx
from SYS import pipeline as ctx
try:
from pypdf import PdfWriter, PdfReader
@@ -38,7 +38,7 @@ except ImportError:
PdfReader = None
try:
from metadata import (
from SYS.metadata import (
read_tags_from_file,
merge_multiple_tag_lists,
)

View File

@@ -30,7 +30,7 @@ normalize_result_input = sh.normalize_result_input
should_show_help = sh.should_show_help
get_field = sh.get_field
parse_cmdlet_args = sh.parse_cmdlet_args
import pipeline as pipeline_context
from SYS import pipeline as pipeline_context
# ============================================================================
# CMDLET Metadata Declaration

View File

@@ -18,7 +18,7 @@ Cmdlet, CmdletArg, should_show_help = (
sh.CmdletArg,
sh.should_show_help,
)
import pipeline as ctx
from SYS import pipeline as ctx
# Optional dependencies
try:
@@ -226,7 +226,7 @@ class Search_Provider(Cmdlet):
import result_table
importlib.reload(result_table)
from result_table import ResultTable
from SYS.result_table import ResultTable
provider_text = str(provider_name or "").strip()
provider_lower = provider_text.lower()

View File

@@ -32,7 +32,7 @@ from . import _shared as sh
sh.first_title_tag,
sh.parse_hash_query,
)
import pipeline as ctx
from SYS import pipeline as ctx
STORAGE_ORIGINS = {"local",
"hydrus",
@@ -257,7 +257,7 @@ class Search_Store(Cmdlet):
import importlib
importlib.reload(result_table)
from result_table import ResultTable
from SYS.result_table import ResultTable
table = ResultTable(command_title)
try:

View File

@@ -23,7 +23,7 @@ normalize_result_input = sh.normalize_result_input
extract_title_from_result = sh.extract_title_from_result
extract_url_from_result = sh.extract_url_from_result
get_field = sh.get_field
import pipeline as ctx
from SYS import pipeline as ctx
CMDLET = Cmdlet(
name="trim-file",