Utils#

Functions & Decorators#

auto_str(cls)[source]#

Annotation that provides a default __str__ method for objects.

Example

Annotating a class with the @auto_str annotation:

>>> @auto_str
    class Dummy(object):
        def __init__(self, a):
            self.a = a

>>> sample = Dummy("test")
>>> print(sample)
Dummy(a=test)
to_dict(obj: Any) Dict[source]#

Utility method for converting any (nested!) object to a dict. This can be conveniently modified and e.g. given to the json parameters of a requests call.

Parameters:

obj – The object that should be encoded.

Returns:

The dict version of the given object.

Return type:

dict

to_json(obj: Any) str[source]#

Utility method for converting an object to a json encoded string.

Parameters:

obj – The object that should be encoded.

Returns:

The encoded version of the given object.

Return type:

str

parse_version(version_element)[source]#

Parses a version number from a given json dictionary from teamscale.

Parameters:

version_element (str | dict) – dictionary of major, minor and patch number

Returns:

a version number

Teamscale Session Management#

class TeamscaleSession(url: str, timestamp: str, message: str, partition: str)[source]#

Bases: object

Syntactic sugar for easier session management with the with clause for uploading external data. This opens a session, returns a session_id and commits the session afterwards. Useful if one wants to upload multiple items in the same session. Otherwise, use ‘auto-create’ rather than this class.

Examples

Use it in combination with the with statement:

>>> with TeamscaleSession(base_url, timestamp, message, partition) as session_id:
>>>     requests.post(...)