module

headfake.util

Utility methods used by other parts of Headfake

Functions
  • calculate_age(start_date, end_date) Calculate age in years when given start date and end date :param start_date: Date object for start :param end_date: Date object for end :return:
  • create_class_tree(name, params) Create recursive class tree given parameters.
  • create_package_class(package_name) Utility method which loads and returns the class corresponding to the provided package name. :param package_name: Fully qualified package name. :return:
  • handle_missing_keyword(ex, class_name, params) Used to provides more informative error when a keyword is missing from parameters. :param ex: Original exception :param class_name: Full name of the class that headfake attempted to create :param: params: Parameters passed to the class constructor :return:
  • locate_file(file) Locates a file either from the given path or in the package resources
function

headfake.util.create_package_class(package_name)

Utility method which loads and returns the class corresponding to the provided package name. :param package_name: Fully qualified package name. :return:

function

headfake.util.create_class_tree(name, params)

Create recursive class tree given parameters.

The name is only given if the original source had a key/value structure, otherwise None is supplied.

Parameters
  • name Name of the current class/object in the tree
  • params A dictionary or list of parameters used to build the class
  • constant_cls A class to wrap constant scalars (e.g. ints, strings, dates etc.)
Returns

A class tree containing recursive classes, lists and dictionaries.

function

headfake.util.calculate_age(start_date, end_date)

Calculate age in years when given start date and end date :param start_date: Date object for start :param end_date: Date object for end :return:

function

headfake.util.locate_file(file)

Locates a file either from the given path or in the package resources

:param file: The file to locate. It can either be an absolute or relative path in the filesystem or in the package resources :return: a PosixPath of the file if found. If the file is not found then an exception is raised

function

headfake.util.handle_missing_keyword(ex, class_name, params)

Used to provides more informative error when a keyword is missing from parameters. :param ex: Original exception :param class_name: Full name of the class that headfake attempted to create :param: params: Parameters passed to the class constructor :return: