dkutils.validation module¶
- dkutils.validation.ensure_pathlib(path)[source]¶
If provided path is a pathlib.PurePath instance, return it. If it’s a string, convert it to a pathlib.PurePath instance and return it. Otherwise, raise a TypeError.
- Parameters
path (str or pathlib.PurePath) – Path to be returned as a pathlib.PurePath instance.
- Raises
TypeError – If provided path is neither a string nor a pathlib.PurePath instance.
- Return type
pathlib.PurePath
- dkutils.validation.get_globals_config(global_var_names, cur_globals)[source]¶
Load the specified glabal variables from a file named globals_config.json if it exists. This is to facillitate a way of initializing the globals variables when running the code outside of DataKitchen. These global variables would normally be passed from DataKitchen. :param global_var_names: list of global variable names to initialize :param cur_globals: list of currently defined global variables
- dkutils.validation.get_max_concurrency(num_orders, max_concurrent)[source]¶
Given a specified maximum concurrency and the number of orders being created/resumed, return a valid maximum concurrency value (i.e. 1 <= max_concurrent <= num_orders). If max_concurrent is None, return num_orders.
- Parameters
num_orders (int) – Number of orders to be created/resumed.
max_concurrent – Maximum number of orders to process concurrently
- Returns
Valid maximum concurrency (i.e. 1 <= max_concurrent <= num_orders) or num_orders if max_concurrent is None.
- Return type
int
- dkutils.validation.set_logging_level(logging_level=20)[source]¶
Set the logging level for the logger in the global variable LOGGER. If the global variable LOOGER does not exist it will be set to a logger obtained from the logging library. This is to allow code to be run outside of DataKitchen without the need to add code to initialize the global variable LOGGER has is done by DataKitchen.make
- Parameters
logging_level (str, optional) –
- dkutils.validation.skip_token_validation()[source]¶
Determine if the outgoing API request should validate the current auth token and refresh it if invalid.
- Returns
True if current request can skip token validation, False otherwise.
- Return type
boolean
- dkutils.validation.validate_globals(global_var_names)[source]¶
Validate that the list of provided global variable names exist in the global namespace of the calling function.
- Parameters
global_var_names (list) – list of global variable names to test for existence.
- Raises
NameError – If any global variables do not exist in the global namespace of the calling function. If any global variables exist in the global namespace of the calling function with the value ‘[CHANGE_ME]’