id_translation.dio#
Insertion and extraction of IDs and translations.
See Translation IO for help.
Module Attributes
Group used to discover |
Functions
|
Returns known |
|
Return IO implementation registration status. |
Discover, load, and register entrypoint integrations. |
|
|
Pretty-print IO name. |
|
Register a new IO implementation. |
|
Get an IO instance for arg. |
Classes
Insertion and extraction of IDs and translations. |
- class DataStructureIO[source]#
Bases:
Generic[TranslatableT,NameType,SourceType,IdType]Insertion and extraction of IDs and translations.
- abstractmethod extract(translatable, names)[source]#
Extract IDs from translatable.
- Parameters:
translatable – Data to extract IDs from.
names – List of names in translatable to extract IDs for.
- Returns:
A dict
{name: ids}.
- classmethod get_rank()[source]#
Return the rank of this implementation.
See
dio.get_resolution_order()for details. The highest possible rank is 0.- Returns:
Implementation rank.
- Raises:
ValueError – If the implementation is not registered.
- abstractmethod classmethod handles_type(arg)[source]#
Return
Trueif the implementation handles data for the type of arg.
- abstractmethod insert(translatable, names, tmap, copy)[source]#
Insert translations into translatable.
- Parameters:
translatable – Data to translate. Modified iff
copy=False.names – Names in translatable to translate.
tmap – Translations for IDs in translatable.
copy – If
True, modify contents of the original translatable. Otherwise, returns a copy.
- Returns:
A copy of translatable if
copy=True,Noneotherwise.- Raises:
NotInplaceTranslatableError – If
copy=Falsefor a type which is not translatable in-place.
- classmethod is_registered()[source]#
Returns registration status for this implementation.
See
dio.is_registered()for details.
- names(translatable)[source]#
Extract names from translatable.
- Parameters:
translatable – Data to extract names from.
- Returns:
A list of names to translate. Returns
Noneif names cannot be extracted.
- priority = 10000#
Determines order in which IOs are considered (higher = earlier).
Set priority < 0 to disable.
- classmethod register()[source]#
Register this implementation for all
Translatorinstances.See
dio.register_io()for details.
- ENTRYPOINT_GROUP = 'id_translation.dio'#
Group used to discover
DataStructureIOintegrations.See
load_integrations()andimportlib.metadata.entry_points()for details.
- get_resolution_order(*, real=False)[source]#
Returns known
DataStructureIOimplementations in the correct resolution order.- Parameters:
real – If
True, return the actual list instead of a copy.- Returns:
A list of IO implementations sorted by rank.
- is_registered(io)[source]#
Return IO implementation registration status.
Implementations should register themselves using
DataStructureIO.register().- Parameters:
io – A
DataStructureIOtype.
- load_integrations()[source]#
Discover, load, and register entrypoint integrations.
Reset the registry, then load entrypoints in the
'id_translation.dio'entrypoint group (seeimportlib.metadata.entry_points()for details).Will skip integrations that raise
ImportErrorwhen loaded (except circular imports).- Raises:
TypeError – If an integration does not inherit from
DataStructureIO.
Notes
Called automatically when
id_translationis imported.
- register_io(io)[source]#
Register a new IO implementation.
Classes are polled through
DataStructureIO.handles_type()in based onDataStructureIO.priority.- Parameters:
io – A
DataStructureIOtype
- resolve_io(arg, *, io_kwargs=None, task_id=None)[source]#
Get an IO instance for arg.
- Parameters:
arg – An argument to get IO for.
io_kwargs – Keyword arguments for the IO class (e.g.
PandasIO).task_id – Used for logging.
- Returns:
A data structure IO instance for arg.
- Raises:
UntranslatableTypeError – If no suitable IO implementation could be found.
See also
The
register_io()function.
Modules
Default |
|
Data structure IO exceptions. |
|
Integration modules. |