simvx.core.resource¶
Package-resource handle.
The :class:Resource class is the canonical Pythonic sugar for an asset that
ships inside a Python package. It stores a (package, name) pair and
resolves lazily through :mod:importlib.resources.
For raw filesystem assets, just pass a path string or :class:pathlib.Path
directly to whichever loader you need (AudioStream, Mesh.from_obj,
ResourceLoader, …). There are no URI schemes.
Examples::
from pathlib import Path
from simvx.core import AudioStream, Resource
AudioStream("music/theme.ogg") # filesystem
AudioStream(Path.home() / "music/theme.ogg") # filesystem (PathLike)
AudioStream(Resource("game.assets", "hero.wav")) # package resource
# The unwrapped importlib form also works:
import importlib.resources
AudioStream(importlib.resources.files("game.assets") / "hero.wav")
Module Contents¶
Classes¶
Lazy handle to a file shipped inside a Python package. |
Data¶
API¶
- simvx.core.resource.log¶
‘getLogger(…)’
- class simvx.core.resource.Resource(package: str, name: str)[source]¶
Lazy handle to a file shipped inside a Python package.
Construction stores the package + filename without touching the filesystem; resolution happens on first access of :attr:
path,- Meth:
read_bytes, or :meth:open.
Example::
>>> r = Resource("pkgres_demo", "marker.bin") >>> r.read_bytes() b'SIMVX_PKGRES_OK\n'Initialization
- __slots__¶
(‘package’, ‘name’)