idiap_devtools.utils

Functions

human_time(seconds[, granularity])

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

run_cmdline(cmd, logger, **kwargs)

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

set_environment(name, value[, env])

Set up 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/latest', 'READTHEDOCS_CANONICAL_URL': 'https://idiap-devtools.readthedocs.io/en/latest/', 'HOSTNAME': 'build-24377909-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/latest/_readthedocs/', 'PATH': '/home/docs/checkouts/readthedocs.org/user_builds/idiap-devtools/envs/latest/bin:/home/docs/.asdf/shims:/home/docs/.asdf/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin', 'READTHEDOCS_VERSION_TYPE': 'branch', 'LANG': 'C.UTF-8', 'READTHEDOCS_LANGUAGE': 'en', 'DEBIAN_FRONTEND': 'noninteractive', 'READTHEDOCS_GIT_COMMIT_HASH': '7ee23f7e887685bfdb6c33b3edc081889f8b5b71', 'READTHEDOCS_VERSION_NAME': 'latest', 'READTHEDOCS_VERSION': 'latest', 'PWD': '/home/docs/checkouts/readthedocs.org/user_builds/idiap-devtools/checkouts/latest/doc', 'READTHEDOCS_GIT_IDENTIFIER': 'main', 'DOCUTILSCONFIG': '/home/docs/checkouts/readthedocs.org/user_builds/idiap-devtools/checkouts/latest/doc/docutils.conf'}))[source]

Set up 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]

Return 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]

Run 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:

The exit status of the command.

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

Very fast, order preserving uniq function.

Return type:

list[Any]