ovo.core.utils.formatting¶
Module Contents¶
Functions¶
Returns: 1 day 2 hours and 5 minutes |
|
Generate a unique ID using 3 or more random letters. |
|
Get SHA1 hash string of the given bytes, for example ‘2aae6c35c94fcfb415dbe95f408b9ce91ee846ed’ |
|
Get directory and subdirectory based on SHA1 hash, for example ‘2a/ae6c35c94fcfb415dbe95f408b9ce91ee846ed’ ^ Note the slash here |
|
Parse list of args into a dict |
|
Get a sort key that sorts strings with numbers in an alphanumeric way. |
|
Sort a list of strings in an alphanumeric way. |
|
Join a list truncated to a maximum number of items, adding ellipsis if necessary. |
API¶
- ovo.core.utils.formatting.format_duration(td)¶
Returns: 1 day 2 hours and 5 minutes
- ovo.core.utils.formatting.generate_id(previous_ids: Collection[str]) str¶
Generate a unique ID using 3 or more random letters.
Args: previous_ids: List of existing IDs to avoid.
Returns: str: A unique identifier.
- ovo.core.utils.formatting.get_hash_of_bytes(value: bytes) str¶
Get SHA1 hash string of the given bytes, for example ‘2aae6c35c94fcfb415dbe95f408b9ce91ee846ed’
- ovo.core.utils.formatting.get_hashed_path_for_bytes(value: bytes) str¶
Get directory and subdirectory based on SHA1 hash, for example ‘2a/ae6c35c94fcfb415dbe95f408b9ce91ee846ed’ ^ Note the slash here
This is done similarly to nextflow workdir to avoid exceeding the directory limit of some filesystems.
- ovo.core.utils.formatting.safe_filename(filename)¶
- ovo.core.utils.formatting.parse_args(argv: list[str]) dict¶
Parse list of args into a dict
For example: [’–foo’, ‘bar’, ‘–bar’, ‘baz’, ‘–flag’] into dict {‘foo’: ‘bar’, ‘bar’: ‘baz’, ‘flag’: True}
- ovo.core.utils.formatting.get_alphanumeric_sort_key(value: str) tuple¶
Get a sort key that sorts strings with numbers in an alphanumeric way.
For example, “item2” will come before “item10”.
- Parameters:
value – The string to generate a sort key for.
- Returns:
A tuple that can be used as a sort key.
- ovo.core.utils.formatting.sorted_alphanumeric(values: Collection[str]) list[str]¶
Sort a list of strings in an alphanumeric way.
For example, “item2” will come before “item10”.
- Parameters:
values – The list of strings to sort.
- Returns:
The sorted list of strings.
- ovo.core.utils.formatting.truncated_list(items: Collection[Any], max_items: int, sep: str = ', ') str¶
Join a list truncated to a maximum number of items, adding ellipsis if necessary.