idiap_devtools.utils#

Functions

human_time(seconds[, granularity])

Returns a human readable time string like "1 day, 2 hours".

run_cmdline(cmd, logger, **kwargs)

Runs a command on a environment, logs output and reports status.

set_environment(name, value[, env])

Function to setup the environment variable and print debug message.

uniq(seq[, idfun])

Very fast, order preserving uniq function.

idiap_devtools.utils.set_environment(name, value, env=environ({'READTHEDOCS_VIRTUALENV_PATH': '/home/docs/checkouts/readthedocs.org/user_builds/idiap-devtools/envs/stable', 'READTHEDOCS_CANONICAL_URL': 'https://idiap-devtools.readthedocs.io/en/stable/', 'HOSTNAME': 'build-21081235-project-1009748-idiap-devtools', 'READTHEDOCS_GIT_CLONE_URL': 'https://gitlab.idiap.ch/software/idiap-devtools.git', 'HOME': '/home/docs', 'NO_COLOR': '1', 'READTHEDOCS': 'True', 'READTHEDOCS_PROJECT': 'idiap-devtools', 'READTHEDOCS_OUTPUT': '/home/docs/checkouts/readthedocs.org/user_builds/idiap-devtools/checkouts/stable/_readthedocs/', 'PATH': '/home/docs/checkouts/readthedocs.org/user_builds/idiap-devtools/envs/stable/bin:/home/docs/.asdf/shims:/home/docs/.asdf/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin', 'READTHEDOCS_VERSION_TYPE': 'tag', 'LANG': 'C.UTF-8', 'READTHEDOCS_LANGUAGE': 'en', 'DEBIAN_FRONTEND': 'noninteractive', 'READTHEDOCS_GIT_COMMIT_HASH': '65890ee6c5c3dc4ec743d8ceab24d43ca205eb63', 'READTHEDOCS_VERSION_NAME': 'stable', 'READTHEDOCS_VERSION': 'stable', 'PWD': '/home/docs/checkouts/readthedocs.org/user_builds/idiap-devtools/checkouts/stable/doc', 'READTHEDOCS_GIT_IDENTIFIER': '65890ee6c5c3dc4ec743d8ceab24d43ca205eb63', 'DOCUTILSCONFIG': '/home/docs/checkouts/readthedocs.org/user_builds/idiap-devtools/checkouts/stable/doc/docutils.conf'}))[source]#

Function to setup the environment variable and print debug message.

Parameters:
  • name (str) – The name of the environment variable to set

  • value (str) – The value to set the environment variable to

  • env (dict[str, str] | _Environ[str]) – Optional environment (dictionary) where to set the variable at

Return type:

str

Returns:

The value just set.

idiap_devtools.utils.human_time(seconds, granularity=2)[source]#

Returns a human readable time string like “1 day, 2 hours”.

This function will convert the provided time in seconds into weeks, days, hours, minutes and seconds.

Parameters:
  • seconds (int | float) – The number of seconds to convert

  • granularity (int) – The granularity corresponds to how many elements will output. For a granularity of 2, only the first two non-zero entries are output.

Return type:

str

Returns:

A string, that contains the human readable time.

idiap_devtools.utils.run_cmdline(cmd, logger, **kwargs)[source]#

Runs a command on a environment, logs output and reports status.

Parameters:
  • cmd (list[str]) – The command to run, with parameters separated on a list of strings

  • logger (Logger) – A logger to log messages to console

  • kwargs – Further kwargs to be set on the call to subprocess.Popen.

Return type:

int

Returns:

idiap_devtools.utils.uniq(seq, idfun=None)[source]#

Very fast, order preserving uniq function.

Return type:

list[Any]