Source code for ewoksid22.bin
import sys
from contextlib import contextmanager
from pathlib import Path
from typing import Generator
if sys.version_info < (3, 9):
import importlib_resources
else:
import importlib.resources as importlib_resources
[docs]
@contextmanager
def program_path(program: str) -> Generator[Path, None, None]:
"""Yield the path to a packaged binary, safely handling wheels/zip files."""
source = importlib_resources.files(__name__).joinpath(program)
with importlib_resources.as_file(source) as path:
if not path.is_file():
raise FileNotFoundError(f"Not a packaged resource: '{path}'")
yield path