Skip to content

Runtime helpers

quiltwright.runtime

Process-level defaults shared by more than one backend.

Nothing here knows about quilts, cameras, or a renderer. The courtesy core cap is the one constant both POV-Ray and Cycles need so a quilt does not take every core on the machine; the ffmpeg lookup is shared by the quilt-video encoder and the HLD encoder; require_pyvista and triple are the small helpers more than one module used to copy.

Part of Quiltwright -- https://github.com/Flux-Frontiers/quiltwright Author: Eric G. Suchanek, PhD

find_ffmpeg()

Locate an ffmpeg binary: system PATH first, then imageio-ffmpeg's.

Returns:

Type Description
str

Path to an ffmpeg executable.

Raises:

Type Description
RuntimeError

If no ffmpeg can be found.

Source code in src/quiltwright/runtime.py
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
def find_ffmpeg() -> str:
    """Locate an ffmpeg binary: system PATH first, then imageio-ffmpeg's.

    :return: Path to an ffmpeg executable.
    :raises RuntimeError: If no ffmpeg can be found.
    """
    import shutil

    found = shutil.which("ffmpeg")
    if found:
        return found
    try:
        import imageio_ffmpeg

        return imageio_ffmpeg.get_ffmpeg_exe()
    except ImportError as exc:
        raise RuntimeError(
            "Quilt video encoding requires ffmpeg.\n"
            "Install it system-wide, or:  pip install imageio-ffmpeg"
        ) from exc

require_pyvista(fn_name)

Raise a clear ImportError if pyvista is not installed.

Parameters:

Name Type Description Default
fn_name str

Public function name used in the error message.

required

Raises:

Type Description
ImportError

If the viz extra (pyvista) is not installed.

Source code in src/quiltwright/runtime.py
45
46
47
48
49
50
51
52
53
54
55
56
def require_pyvista(fn_name: str) -> None:
    """Raise a clear ImportError if pyvista is not installed.

    :param fn_name: Public function name used in the error message.
    :raises ImportError: If the ``viz`` extra (pyvista) is not installed.
    """
    try:
        import pyvista  # noqa: F401
    except ImportError as exc:
        raise ImportError(
            f"{fn_name}() requires pyvista.\nInstall with:  poetry install --with viz"
        ) from exc

triple(v)

Coerce a 3-vector -- list, tuple, NumPy array -- to a float 3-tuple.

tuple(v) types as tuple[float, ...], which is not a camera coordinate. Unpacking states the arity and rejects a wrong-length vector here rather than later.

Parameters:

Name Type Description Default
v Iterable[float]

Any iterable of three reals.

required

Returns:

Type Description
tuple[float, float, float]

(x, y, z) as plain floats.

Raises:

Type Description
ValueError

If v does not have exactly three components.

Source code in src/quiltwright/runtime.py
59
60
61
62
63
64
65
66
67
68
69
70
71
def triple(v: Iterable[float]) -> tuple[float, float, float]:
    """Coerce a 3-vector -- list, tuple, NumPy array -- to a float 3-tuple.

    ``tuple(v)`` types as ``tuple[float, ...]``, which is not a camera
    coordinate.  Unpacking states the arity and rejects a wrong-length
    vector here rather than later.

    :param v: Any iterable of three reals.
    :return: ``(x, y, z)`` as plain floats.
    :raises ValueError: If *v* does not have exactly three components.
    """
    x, y, z = (float(c) for c in v)
    return (x, y, z)