httk.core.loading¶
Dispatch file readers and optional domain adapters.
load retains the neutral reader result when no domain adapter owns its
format, while installed capability modules can register adapters to provide a
one-call domain-loading experience. Callers that need the neutral payload can
use raw=True.
Functions¶
|
Return whether |
|
Apply a registered format adapter unless |
|
Load |
|
Load |
|
Load multiple sources lazily, preserving input order. |
Module Contents¶
- httk.core.loading.reader_uses_extension(name)[source]¶
Return whether
nameis claimed by an extension rather than a basename.
- httk.core.loading.adapt_result(result, raw)[source]¶
Apply a registered format adapter unless
rawis requested.- Parameters:
result (Any) – Neutral reader result to inspect for a format tag.
raw (bool) – Whether to return the neutral result without adaptation.
- Returns:
The adapted domain value or the unchanged reader result.
- Return type:
Any
- httk.core.loading.load_source(source, name, *, raw=False, **kwargs)[source]¶
Load
sourceusing the reader selected byname.- Parameters:
- Returns:
The reader result, optionally adapted to a domain value.
- Raises:
ValueError – If no reader matches the name; the error lists known extensions and basenames.
- Return type:
Any
- httk.core.loading.load(filename, *, raw=False, **kwargs)[source]¶
Load
filenameand adapt its neutral payload to a domain object.Dispatch strips at most one recognized compression suffix (
.gz,.bz2, …) to obtain an inner name, then selects a reader by that inner name’s extension (.cif,.poscar, …) or, failing that, by its exact basename (POSCAR,CONTCAR; case-insensitive). The selected reader always receives the originalfilename; readers open it through the datastream layer, which transparently decompresses. By default, a mapping with a string"format"tag is passed to the registered domain adapter for that format.raw=Trueis the neutral-payload escape hatch. Payloads with unknown formats, and non-mapping reader results, pass through unchanged.- Parameters:
- Returns:
The loaded and optionally adapted value.
- Raises:
ValueError – If
filenameis a URL or no reader matches it.- Return type:
Any
- httk.core.loading.load_many(sources, *, processes=None, errors='raise', **kwargs)[source]¶
Load multiple sources lazily, preserving input order.
processes=Noneuses the process-pool default.processes=0orprocesses=1loads in the current process, which is also the guaranteed path for readers registered at runtime. Parallel workers rediscover installed registration packages, but runtime registrations are not guaranteed to be present in a fresh worker. Parallel work uses bounded ordered futures rather thanmap()so worker failures and result-pickling failures can be returned per source.- Parameters:
sources (collections.abc.Iterable[Any]) – Sources accepted by
load().processes (int | None) – Number of worker processes, or
Nonefor the default.errors (Literal['raise', 'return']) – Whether to raise failures or yield them as exception values.
**kwargs (Any) – Options forwarded to every
load()call.
- Returns:
A lazy iterator of
(source, result)pairs in input order.- Raises:
ValueError – If
errorsis not"raise"or"return", or ifprocessesis negative.TypeError – If
processesis not an integer orNone.
- Return type:
collections.abc.Generator[tuple[Any, Any], None, None]