kiara.utils¶
check_valid_field_names(*field_names)
¶
Check whether the provided field names are all valid.
Returns:
Type | Description |
---|---|
List[str] |
an iterable of strings with invalid field names |
Source code in kiara/utils/__init__.py
def check_valid_field_names(*field_names) -> typing.List[str]:
"""Check whether the provided field names are all valid.
Returns:
an iterable of strings with invalid field names
"""
return [x for x in field_names if x in INVALID_VALUE_NAMES or x.startswith("_")]
find_free_id(stem, current_ids, sep='_')
¶
Find a free var (or other name) based on a stem string, based on a list of provided existing names.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
stem |
str |
the base string to use |
required |
current_ids |
Iterable[str] |
currently existing names |
required |
method |
str |
the method to create new names (allowed: 'count' -- for now) |
required |
method_args |
dict |
prototing_config for the creation method |
required |
Returns:
Type | Description |
---|---|
str |
str: a free name |
Source code in kiara/utils/__init__.py
def find_free_id(
stem: str,
current_ids: typing.Iterable[str],
sep="_",
) -> str:
"""Find a free var (or other name) based on a stem string, based on a list of provided existing names.
Args:
stem (str): the base string to use
current_ids (Iterable[str]): currently existing names
method (str): the method to create new names (allowed: 'count' -- for now)
method_args (dict): prototing_config for the creation method
Returns:
str: a free name
"""
start_count = 1
if stem not in current_ids:
return stem
i = start_count
# new_name = None
while True:
new_name = f"{stem}{sep}{i}"
if new_name in current_ids:
i = i + 1
continue
break
return new_name
get_auto_workflow_alias(module_type, use_incremental_ids=False)
¶
Return an id for a workflow obj of a provided module class.
If 'use_incremental_ids' is set to True, a unique id is returned.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
module_type |
str |
the name of the module type |
required |
use_incremental_ids |
bool |
whether to return a unique (incremental) id |
False |
Returns:
Type | Description |
---|---|
str |
str: a module id |
Source code in kiara/utils/__init__.py
def get_auto_workflow_alias(module_type: str, use_incremental_ids: bool = False) -> str:
"""Return an id for a workflow obj of a provided module class.
If 'use_incremental_ids' is set to True, a unique id is returned.
Args:
module_type (str): the name of the module type
use_incremental_ids (bool): whether to return a unique (incremental) id
Returns:
str: a module id
"""
if not use_incremental_ids:
return module_type
nr = _AUTO_MODULE_ID.setdefault(module_type, 0)
_AUTO_MODULE_ID[module_type] = nr + 1
return f"{module_type}_{nr}"