photon_platform.clerk.viewer.files

High-speed media file discovery, stdin parsing, and repo CSS detection.

Attributes

SKIP_DIRS

Functions

classify_extension(path) → photon_platform.clerk.viewer.models.MediaKind | None

Classify a file path by supported media extension.

find_paired_raster(svg_path) → pathlib.Path | None

Locate a sibling raster image matching an SVG's stem (e.g. facsimile PNG).

find_repo_css(item_path, *[, cache]) → pathlib.Path | None

Walk upward from item_path to discover repo-local custom.css.

parse_stdin_paths(stream) → list[str]

Parse newline-delimited (or NUL-delimited) file paths from a stream.

discover_items([paths, recursive, from_stdin, ...]) → list[photon_platform.clerk.viewer.models.MediaItem]

Discover and index supported SVG and raster media files.

build_items_from_paths(resolved_paths, *[, base_dir]) → list[photon_platform.clerk.viewer.models.MediaItem]

Construct indexed MediaItem objects from pre-resolved paths.

Module Contents

photon_platform.clerk.viewer.files.SKIP_DIRS: frozenset[str]
photon_platform.clerk.viewer.files.classify_extension(path: pathlib.Path) → photon_platform.clerk.viewer.models.MediaKind | None

Classify a file path by supported media extension.

Parameters:

path – Filesystem path to inspect.

Returns:

"svg", "raster", or None if unsupported.

photon_platform.clerk.viewer.files.find_paired_raster(svg_path: pathlib.Path) → pathlib.Path | None

Locate a sibling raster image matching an SVG’s stem (e.g. facsimile PNG).

Checks the SVG’s own directory first, then falls back to the mirrored resources/ directory for PHOTON/GEOMETOR Book Codex docsrc/ layouts.

Parameters:

svg_path – Path to an .svg or .svgz file.

Returns:

Matching sibling raster Path, or None if none exists.

photon_platform.clerk.viewer.files.find_repo_css(item_path: pathlib.Path, *, cache: dict[pathlib.Path, pathlib.Path | None] | None = None) → pathlib.Path | None

Walk upward from item_path to discover repo-local custom.css.

Looks for docsrc/_static/css/custom.css or _static/css/custom.css up to the nearest repository boundary (.git) or filesystem root.

Parameters:
  • item_path – File or directory path inside a repository.

  • cache – Optional directory-to-CSS cache to avoid repeated stat calls.

Returns:

Path to discovered custom.css, or None.

photon_platform.clerk.viewer.files.parse_stdin_paths(stream: TextIO) → list[str]

Parse newline-delimited (or NUL-delimited) file paths from a stream.

Parameters:

stream – Readable text stream (typically sys.stdin).

Returns:

Ordered list of stripped non-empty path strings.

photon_platform.clerk.viewer.files.discover_items(paths: collections.abc.Sequence[str] = (), *, recursive: bool = False, from_stdin: bool = False, stdin_stream: TextIO | None = None, base_dir: pathlib.Path | None = None) → list[photon_platform.clerk.viewer.models.MediaItem]

Discover and index supported SVG and raster media files.

Preserves explicit file ordering from argv and stdin, naturally sorts directory scans, skips VCS/build directories during recursive traversal, and deduplicates resolved paths.

Parameters:
  • paths – Positional CLI file/directory arguments ("-" triggers stdin).

  • recursive – Whether to descend recursively into directories.

  • from_stdin – Read additional newline-delimited paths from stdin_stream.

  • stdin_stream – Stream to read when from_stdin or "-" is active.

  • base_dir – Base working directory for relative display names.

Returns:

Indexed list of MediaItem entries.

photon_platform.clerk.viewer.files.build_items_from_paths(resolved_paths: collections.abc.Iterable[str | pathlib.Path], *, base_dir: pathlib.Path | None = None) → list[photon_platform.clerk.viewer.models.MediaItem]

Construct indexed MediaItem objects from pre-resolved paths.

Useful for the warm daemon receiving an already-expanded item list.

Parameters:
  • resolved_paths – Iterable of file paths.

  • base_dir – Base directory for relative display strings.

Returns:

Indexed list of MediaItem objects.