qualia_core.utils.path module
Path utilities.
- qualia_core.utils.path.resources_to_path(resources: Path | MultiplexedPath | Traversable) Path [source]
Convert a (static type) Traversable to a Path if the underlying dynamic type is MultiplexedPath.
This is useful when using
importlib.resources.files()
since with Python >= 3.10 it returns aimportlib.readers.MultiplexedPath
whenimportlib.readers.NamespaceReader
is used as a reader, e.g. when used on a package available as a plain directory (not zip file). This allows getting a standardpathlib.Path
out of it. Any other situation will probably fail with ValueError.- Parameters:
resources – An object returned by
importlib.resources.files()
- Returns:
A standard Path object pointing to the
resources
path on the filesystem- Raises:
ValueError – When conversion fails because
resources
was not aimportlib.readers.MultiplexedPath
on Python >= 3.10 or apathlib.Path