Utils#

Utility functions used internally across the library

Exceptions:

AmbiguityError

Exception type for when onice_conversion.spec modules give ambiguous results

Classes:

IntrospectionMixin()

Mixin to allow objects to become aware of all the arguments they were called with on initialization

Functions:

_recurse_subclasses(cls[, leaves_only])

Given some class, find its subclasses recursively

_recursive_import(module_name)

Given some path in a python package, import all modules beneath it

_gather_list_of_dicts(a_list)

Gather a list of dictionaries like.

_recursive_dedupe_dicts(a_dict[, raise_on_dupes])

Deduplicate a list of dicts.

exception onice_conversion.utils.AmbiguityError#

Bases: Exception

Exception type for when onice_conversion.spec modules give ambiguous results

class onice_conversion.utils.IntrospectionMixin#

Bases: object

Mixin to allow objects to become aware of all the arguments they were called with on initialization

Call _get_init_args() in the __init__ method of any object that inherits from this mixin :)

Methods:

_get_init_args()

introspect object and get all arguments passed on __init__

_full_name()

Returns the full module and class name of an object, eg.

_get_init_args()#

introspect object and get all arguments passed on __init__

depends on introspecting up frames so should only be called during the top-level __init__ of the base class :)

Return type

dict of argument names and params

_full_name()#

Returns the full module and class name of an object, eg. nwb_conversion_tools.spec.external_file.JSON

Return type

str

onice_conversion.utils._recurse_subclasses(cls, leaves_only=True) list#

Given some class, find its subclasses recursively

See: https://stackoverflow.com/a/17246726/13113166

Parameters
  • leave_only (bool) – If True, only include classes that have no further subclasses,

  • if False, return all subclasses.

Returns

list of subclasses

onice_conversion.utils._recursive_import(module_name: str) List[str]#

Given some path in a python package, import all modules beneath it

Parameters

module_name (str) – name of module to recursively import

Returns

list of all modules that were imported

onice_conversion.utils._gather_list_of_dicts(a_list: list) Dict[str, list]#

Gather a list of dictionaries like:

[{'key1':'val1'}, {'key1':'val2'}, {'key1':'val3'}]

to a dict of lists like:

{‘key1’: [‘val1’, ‘val2’, ‘val3’]}

onice_conversion.utils._recursive_dedupe_dicts(a_dict, raise_on_dupes=True)#

Deduplicate a list of dicts.

Optionally raise an exception if duplicates are found, otherwise call set and unwrap singletons and return

Parameters

a_dict (of dicts)

Returns

dict

Return type

deduplicated dictionary