Miscellaneous Classes

Repr - Convenience class for default printing

class hypergol.Repr[source]

Convencience class to automatically add standard __repr__() and __str__() functions to class.

Uses __dict__ property.

NameString - Convert string between cases

class hypergol.name_string.NameString(name, plural=None)[source]

Class to generate strings of various cases

NameString stores the input string in components. The components are detected by splitting up the input name by single capital letters and underscores.

An irregular plural version can be supplied; otherwise an ‘es’ or ‘s’ will be attached to the end to get plural form.

__init__(name, plural=None)[source]
Parameters
  • name (string) – String in any case

  • plural (string (default=None)) – If the plural form of a word is irregular, it can be provided here the same style as the name

property asFileName

Returns the standard python filename

e.g.: HelloWorld -> hello_world.py

property asSnake

Returns the string as snakecase

e.g.: HelloWorld -> hello_world

property asClass

Returns the string as a class name (PascalCase)

e.g.: HelloWorld -> HelloWorld

property asVariable

Returns the string as a variable name (camelCase)

e.g.: HelloWorld -> helloWorld

property asPluralVariable

Returns the string as a plural variable name

e.g.: HelloWorld -> helloWorlds

Used for autogenerating dataset variable names

property asPluralSnake

Returns the string as a plural snakecase name

e.g.: HelloWorld -> hello_worlds

Used for autogenerating dataset file names

HypergolProject - Class to manage information about the project

class hypergol.hypergol_project.HypergolProject(projectDirectory=None, dataDirectory='.', chunkCount=16, dryrun=None, force=None, repoManager=None)[source]

Owner of all information about the project

CLI functions define what needs to be created, and this class creates them. It also consistently handles the mode flags (normal/dryrun/force)

It also verifies if a requested class exists in the respective directory (data_models, tasks) and identifies its type, e.g.: for HelloWorld it checks if data_models/hello_world.py or tasks/hello_world.py exists and assumes its role from that. Used in create_data_model() and create_pipeline()

__init__(projectDirectory=None, dataDirectory='.', chunkCount=16, dryrun=None, force=None, repoManager=None)[source]
Parameters
  • projectDirectory (string) – location of the project: e.g.: ~/repo_name, models will be in ~/repo_name/models

  • projectDirectory – location of the data for the project project: e.g.: ~/data, files will be stored in ~/data/repo_name

  • dryrun (bool (default=None)) – If set to True it returns the generated code as a string

  • force (bool (default=None)) – If set to True it overwrites the target file

property isDryRun
property modeMessage
cli_final_message(creationType, name, content)[source]
create_model_directory(modelName)[source]
create_project_directory()[source]
create_data_models_directory()[source]
create_tasks_directory()[source]
create_pipelines_directory()[source]
create_blocks_directory()[source]
create_models_directory()[source]
create_tests_directory()[source]
is_data_model_class(value: hypergol.name_string.NameString)[source]

Checks if a name is a data_model class (based on if the snakecase .py file exists)

is_task_class(value: hypergol.name_string.NameString)[source]

Checks if a name is in tasks class (based on if the snakecase .py file exists)

is_model_block_class(value: hypergol.name_string.NameString)[source]

Checks if a name is in blocks class (based on if the snakecase .py file exists)

check_dependencies(dependencies)[source]

Raises an error if any dependency is unknown

create_text_file(filePath, content)[source]
render(templateName, templateData, filePath)[source]

Creates a file from a template using jinja2

Parameters
  • templateName (string) – filename of the template

  • templateData (dict) – data to fill the template with

  • filePath (Path) – full path of the destination file (ignored if self.mode != Mode.DRY_RUN)

make_file_executable(filePath)[source]
render_executable(templateName, templateData, filePath)[source]
render_simple(templateName, filePath)[source]
list_datasets(pattern=None, asCode=False)[source]

Convenience function to list datasets for a project

Returns a list of data loaded from the .def files in the directory

Parameters
  • pattern (string (None)) – Regex pattern to filter on dataset names, if unspecified, defaults to .*

  • asCode (bool (False)) – If True prints a code snippet that allows the dataset to be loaded (with imports and path updates)

diff_data_model(commit, *args)[source]

Convenience function to compare old data model class definitions to the current one

Prints the diffs from the specified commit to the current commit

Parameters
  • commit (string) – The git commit from where the comparison starts

  • *args (List[string]) – List of class names to compare, if empty it compares all

create_old_data_model(commit, *args)[source]

Convenience function to generate data model classes at an old commit to be able to load datasets created then

Full commit hash required.

project.create_old_data_model(commit='fbd8110b7194425e2323f68ef54dac15bb01ee7b', 'OneClass', 'TwoClass')

Will create data_models/one_class_fbd8110.py and data_models/two_class_fbd8110.py and replaces all occurences of OneClass and TwoClass to OneClassFBD8110 and TwoClassFBD8110 in each file.

Parameters
  • commit (string) – git commit to retrieve classes from

  • args (List[string]) – List of class names to generate, if empty it generates all

RepoManager - Helper class for storing Repository information

class hypergol.hypergol_project.RepoManager(repoDirectory=None, raiseIfDirty=True)[source]

Wrapper class around git that provides all information about the repo connected to the project.

__init__(repoDirectory=None, raiseIfDirty=True)[source]
Parameters
  • repoDirectory (string) – directory where the the .git directory is located

  • raiseIfDirty (bool) – if set and the repo contains uncommitted code, it raises an error

RepoData - Data class for storing Repository informations

class hypergol.dataset.RepoData(branchName, commitHash, commitMessage, comitterName, comitterEmail)[source]

Stores the information about the repository in the dataset

__init__(branchName, commitHash, commitMessage, comitterName, comitterEmail)[source]
Parameters
  • branchName (str) –

  • commitHash (str) –

  • commitMessage (str) –

  • comitterName (str) –

  • comitterEmail (str) –

classmethod get_dummy()[source]

Creates an empty RepoData if the Dataset was created outside a git repository

Logger - Class for logging

class hypergol.logger.Logger(path=None, level=20, overWrite=False, enabled=True)[source]

Helper class to manage file-based and screen-based logging

CRITICAL = 50
ERROR = 40
WARNING = 30
INFO = 20
DEBUG = 10
NOTSET = 0
__init__(path=None, level=20, overWrite=False, enabled=True)[source]
Parameters
  • path (str (default=None)) – Optional path to save logs into a file

  • level (int (default=Logger.INFO)) – Log level of this logger

  • overWrite (bool (default=False)) – Indicate if an existing log file should be overwritten or appended

disable()[source]
enable()[source]
log(message)[source]

Convenience method for Logger.INFO level

critical(message)[source]
error(message)[source]
exception(message)[source]
warning(message)[source]
info(message)[source]
debug(message)[source]