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 a importlib.readers.MultiplexedPath when importlib.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 standard pathlib.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 a importlib.readers.MultiplexedPath on Python >= 3.10 or a pathlib.Path