Util#

Project helpers, and associated functionality which have no home.

gordo.utils.join_json_paths(element: str, json_path: str | None = None) str[source]#

Join two JSON paths

Examples

>>> join_json_paths("machines[0]", "spec.config")
'spec.config.machines[0]'
>>> join_json_paths("dataset")
'dataset'
Parameters:
  • element (str) – Element name

  • json_path (str) – Root JSON path

gordo.utils.normalize_sensor_tags(build_dataset_metadata: dict, tag_list: List[Dict | List | str | SensorTag], **kwargs: str | None) List[SensorTag][source]#

Load tag information from the metadata

Parameters:
  • build_dataset_metadata (dict) – build_metadata.dataset part of the metadata

  • tag_list (TagsList) – Tag list that needs to be loaded

  • kwargs (Optional[str]) – Additional fields for normalize_sensor_tag()

Return type:

List[SensorTag]

gordo.util.utils.capture_args(method: Callable)[source]#

Decorator that captures args and kwargs passed to a given method. This assumes the decorated method has a self, which has a dict of kwargs assigned as an attribute named _params.

Parameters:

method – Some method of an object, with ‘self’ as the first parameter.

Return type:

Returns whatever the original method would return

gordo.util.text.replace_all_non_ascii_chars(s: str, replace_with: str = '') str[source]#
class gordo.util.version.GordoPR(number: int)[source]#

Bases: Version

get_version()[source]#
number: int#
class gordo.util.version.GordoRelease(major: int, minor: int | None = None, patch: int | None = None, suffix: str | None = None)[source]#

Bases: Version

get_version()[source]#
major: int#
minor: int | None = None#
only_major() bool[source]#
only_major_minor() bool[source]#
patch: int | None = None#
suffix: str | None = None#
without_patch() bool[source]#
class gordo.util.version.GordoSHA(sha: str)[source]#

Bases: Version

get_version()[source]#
sha: str#
class gordo.util.version.GordoSpecial(special: gordo.util.version.Special)[source]#

Bases: Version

get_version()[source]#
special: Special#
class gordo.util.version.Special(value)[source]#

Bases: Enum

An enumeration.

LATEST = 'latest'#
STABLE = 'stable'#
classmethod find(version: str) Special | None[source]#
class gordo.util.version.Version[source]#

Bases: object

abstract get_version()[source]#
gordo.util.version.parse_version(gordo_version: str) GordoRelease | GordoSpecial | GordoPR | GordoSHA[source]#

Parsing gordo version. Also supported gordo docker images tags

Parameters:

gordo_version

Example

>>> parse_version('2.3.5')
GordoRelease(major=2, minor=3, patch=5, suffix=None)
>>> parse_version('latest')
GordoSpecial(special=<Special.LATEST: 'latest'>)
gordo.util.disk_registry.delete_value(registry_dir: PathLike | str, key: str) bool[source]#

Deletes the value with key reg_key from the registry, and returns True if it existed.

Parameters:
  • registry_dir – Path to the registry. Does not need to exist

  • key – Key to look up in the registry.

Return type:

True if the key existed, false otherwise

gordo.util.disk_registry.get_value(registry_dir: PathLike | str, key: str) AnyStr | None[source]#

Retrieves the value with key reg_key from the registry, None if it does not exists.

Parameters:
  • registry_dir – Path to the registry. If it does not exist we return None

  • key – Key to look up in the registry.

Returns:

  • The value of key in the registry, None if no value is registered with that key

  • in the registry.

gordo.util.disk_registry.logger = <Logger gordo.util.disk_registry (DEBUG)>#

A simple file-based key/value registry. Each key gets a file with filename = key, and the content of the file is the value. No fancy. Why? Simple, and there is no problems with concurrent writes to different keys. Concurrent writes to the same key will break stuff.

gordo.util.disk_registry.write_key(registry_dir: PathLike | str, key: str, val: AnyStr)[source]#

Registers a key-value combination into the register. Key must valid as a filename.

Parameters:
  • registry_dir – Path to the registry. If it does not exists it will be created, including any missing folders in the path.

  • key – Key to use for the key/value. Must be valid as a filename.

  • val – Value to write to the registry.

Examples

In the following example we use the temp directory as the registry >>> import tempfile >>> with tempfile.TemporaryDirectory() as tmpdir: … write_key(tmpdir, “akey”, “aval”) … get_value(tmpdir, “akey”) ‘aval’