module

biopipen.core.config

Provides the envs from configuration files

Classes
  • ConfigItems Provides the envs from configuration files and defaults thenon-existing values to None. </>
class

biopipen.core.config.ConfigItems(*args, **kwargs)

Bases
diot.diot.Diot dict

Provides the envs from configuration files and defaults thenon-existing values to None.

Parameters
  • *args Anything that can be sent to dict construct
  • **kwargs keyword argument that can be sent to dict constructSome diot configurations can also be passed, including: diot_nest: Types to nestly convert values diot_transform: The transforms for keys diot_frozen: Whether to generate a frozen diot. True: freeze the object recursively if there are Diot objects in descendants False: Don'f freeze 'shallow': Only freeze at depth = 1
Methods
  • __contains__(name) (bool) True if the dictionary has the specified key, else False.</>
  • __delitem__(name) Delete self[key].</>
  • __getitem__(name) (Any) x.getitem(y) <==> x[y]</>
  • __ior__(other) (Diot) Return self|=value.</>
  • __setitem__(name, value) Set self[key] to value.</>
  • accessible_keys() (Iterable) Get the converted keys</>
  • clear() Clear the object</>
  • copy() (Diot) Shallow copy the object</>
  • freeze(frozen) Freeze the diot object</>
  • from_namespace(namespace, recursive, diot_nest, diot_transform, diot_frozen) (Diot) Get a Diot object from an argparse namespace</>
  • get(name, value) (Any) Get the value of a key name</>
  • pop(name, *value) (Any) Pop a key from the object and return the value. If key does notexist, return the given default value </>
  • popitem() (Tuple) Pop last item from the object</>
  • setdefault(name, value) (Any) Set a default value to a key</>
  • thaw(recursive) A context manager for temporarily change the diot</>
  • to_dict() (Dict) Turn the Box and sub Boxes back into a nativepython dictionary. </>
  • to_json(filename, encoding, errors, **json_kwargs) (Optional) Convert to a json string or save it to json file</>
  • to_toml(filename, encoding, errors) (Optional) Convert to a toml string or save it to toml file</>
  • to_yaml(filename, default_flow_style, encoding, errors, **yaml_kwargs) (Optional) Convert to a yaml string or save it to yaml file</>
  • unfreeze(recursive) Unfreeze the diot object</>
  • update(*value, **kwargs) Update the object. Shortcut: |=</>
  • update_recursively(*value, **kwargs) Update the object. Shortcut: |=</>
classmethod

from_namespace(namespace, recursive=True, diot_nest=True, diot_transform='safe', diot_frozen=False)

Get a Diot object from an argparse namespace

Example
>>> from argparse import Namespace>>> Diot.from_namespace(Namespace(a=1, b=2))
Parameters
  • namespace (Namespace) The namespace object
  • recursive (bool, optional) Do it recursively?
  • diot_nest (Union, optional) Types to nestly convert values
  • diot_transform (Union, optional) The transforms for keys
  • diot_frozen (Union, optional) Whether to generate a frozen diot.
    • - True: freeze the object recursively if there are Diot objects
    in descendants
    • - False: Don'f freeze
    • - shallow: Only freeze at depth = 1
  • diot_missing How to deal with missing keys when accessing them
    • - An exception class or object to raise
    • - None to return None
    • - A custom function with first argument the key and second
        the diot object.
Returns (Diot)

The converted diot object.

method

__setitem__(name, value)

Set self[key] to value.

method

pop(name, *value)

Pop a key from the object and return the value. If key does notexist, return the given default value

Parameters
  • name (str) The key
Returns (Any)

The value corresponding to the name or the default value

Raises
  • DiotFrozenError when try to pop from a frozen diot
method

popitem()

Pop last item from the object

Returns (Tuple)

A tuple of key and value

Raises
  • DiotFrozenError when try to pop from a frozen diot
method

update(*value, **kwargs)

Update the object. Shortcut: |=

Raises
  • DiotFrozenError when try to update a frozen diot
method

update_recursively(*value, **kwargs)

Update the object. Shortcut: |=

Raises
  • DiotFrozenError when try to update a frozen diot
method

__ior__(other) → Diot

Return self|=value.

method

__delitem__(name)

Delete self[key].

method

freeze(frozen='shallow')

Freeze the diot object

Parameters
  • frozen (Union, optional) The frozen argument indicating how to freeze:shallow: only freeze at depth=1 True: freeze recursively if there are diot objects in children False: Disable freezing
method

unfreeze(recursive=False)

Unfreeze the diot object

Parameters
  • recursive (bool, optional) Whether unfreeze all diot objects recursively
generator

thaw(recursive=False)

A context manager for temporarily change the diot

Parameters
  • recursive (bool, optional) Whether unfreeze all diot objects recursively
Yields

self, the reference to this diot.

method

setdefault(name, value)

Set a default value to a key

Parameters
  • name (str) The key name
  • value (Any) The default value
Returns (Any)

The existing value or the value passed in

Raises
  • DiotFrozenError when try to set default to a frozen diot
method

accessible_keys()

Get the converted keys

Returns (Iterable)

The accessible (transformed) keys

method

get(name, value=None)

Get the value of a key name

Parameters
  • name (str) The key name
  • value (Any, optional) The value to return if the key does not exist
Returns (Any)

The corresponding value or the value passed in if the key doesnot exist

method

__contains__(name) → bool

True if the dictionary has the specified key, else False.

method

clear()

Clear the object

method

copy()

Shallow copy the object

Returns (Diot)

The copied object

method

to_dict()

Turn the Box and sub Boxes back into a nativepython dictionary.

Returns (Dict)

The converted python dictionary

method

to_json(filename=None, encoding='utf-8', errors='strict', **json_kwargs)

Convert to a json string or save it to json file

Parameters
  • filename (Union, optional) The filename to save the json to, if not given a jsonstring will be returned
  • encoding (str, optional) The encoding for saving to file
  • errors (str, optional) The errors handling for saveing to fileSee python's open function
  • **json_kwargs Other kwargs for json.dumps
Returns (Optional)

The json string with filename is not given

method

to_yaml(filename=None, default_flow_style=False, encoding='utf-8', errors='strict', **yaml_kwargs)

Convert to a yaml string or save it to yaml file

Parameters
  • filename (Union, optional) The filename to save the yaml to, if not given a yamlstring will be returned
  • default_flow_style (bool, optional) The default flow style for yaml dumpingSee yaml.dump
  • encoding (str, optional) The encoding for saving to file
  • errors (str, optional) The errors handling for saveing to fileSee python's open function
  • **yaml_kwargs Other kwargs for yaml.dump
Returns (Optional)

The yaml string with filename is not given

method

to_toml(filename=None, encoding='utf-8', errors='strict')

Convert to a toml string or save it to toml file

Parameters
  • filename (Union, optional) The filename to save the toml to, if not given a tomlstring will be returned
  • encoding (str, optional) The encoding for saving to file
  • errors (str, optional) The errors handling for saveing to fileSee python's open function
Returns (Optional)

The toml string with filename is not given

method

__getitem__(name) → Any

x.getitem(y) <==> x[y]