hip_data_tools.hipages package¶
Submodules¶
hip_data_tools.hipages.version_tracking module¶
This module helps us version track classes by capturing the latest git hash of the file they are written in, and dumping these versions to a json file
The application looks through a package for classes with the registration decorator. The last git commit has for files which contain this decorator are then used to track the current version of the class
Example
The application takes two arguments the name of the package you’re interested in, and the output location for the json file
$ python version-tracker -p transformers -o ./version.json
It also provides transparent functions which can be used as decorators to classes, functions and methods to tag them as requiring tracking by the version control app
Typical usage:
from version_tracking import register_class_for_version_tracking from version_tracking import register_method_for_version_tracking
@register_class_for_version_tracking class Foo:
- def __init__(self):
- self.foo = ‘some value’
@register_method_for_version_tracking def track_this_method(self):
return self.foo
When the version tracking app is executed the latest githash of the files containing registered classes, functions, and methods will be logged to disk in a json file
-
hip_data_tools.hipages.version_tracking.CLASS_DECORATOR_STRING= '@register_class_for_version_tracking'¶ Used to trigger identification of the class by the version tracker
Type: string
-
hip_data_tools.hipages.version_tracking.DEFINITION_MAPPING= {'class': '@register_class_for_version_tracking', 'def': '@register_method_for_version_tracking'}¶ Used to map between the type and their respective decorator
Type: dictionary
-
exception
hip_data_tools.hipages.version_tracking.DecoratorError(declaration, line, line_number)¶ Bases:
ExceptionError raised when there is a problem with the decoration of a class or method
Parameters: - declaration (str) – Declartion the application is looking for
- line (str) – Line where the declaration is made
- line_number (int) – Line number in found of declaration
-
hip_data_tools.hipages.version_tracking.METHOD_DECORATOR_STRING= '@register_method_for_version_tracking'¶ Used to trigger identification of the method by the version tracker
Type: string
-
class
hip_data_tools.hipages.version_tracking.VersionTracker¶ Bases:
objectA class that allows us to track versions through hashes and strings by generating a dictionary. Versions can be loaded from file or can be generated on the fly from object hashes
-
add_dictionary_to_versions(in_dict)¶ Add a Python dictionary to the versioning dictionary :param in_dict: A dictionary to append to the version dictionary :type in_dict: dict
Returns: None
-
add_object_version(dict_key, obj)¶ Adds a hash of an object to the version tracking :param dict_key: Name to be using in the version tracking
dictioanryParameters: obj (Object) – Any hashable object Returns: None
-
add_string_to_version_tracking(dict_key, in_string)¶ Adds a string value to the version tracking. :param dict_key: Name to use as the key in the version tracking
dictionaryParameters: in_string (str) – Value to be stored in the version tracking dictionary Returns: None
-
add_versions_from_json_file(version_file_location)¶ Load a json file from local storage and append these versions to the version tracking dictionary :param version_file_location: Path to the json file :type version_file_location: str
Returns: None
-
get_version_dict()¶ Brings together all of the required versioning information and returns the relevant dictionary Returns (dict): Dictionary which tracks all of the tracked versions
-
-
hip_data_tools.hipages.version_tracking.check_for_decorated_declaration_in_file(path, decorating_string, declaration)¶ Finds any classes in a file with the relevant decorator string :param path: absolute or relative path to the python file :param decorating_string: string of decorator used to identify the
methods, classes and functions which need trackedParameters: declaration (string) – Declaration to look for Returns: list of classes within the file which require version tracking
-
hip_data_tools.hipages.version_tracking.find_and_export_relevant_versions(path, repo_location, output_location)¶ Looks through a package and finds classes which have been decorated as requiring version tagging, and then writes these classes and their versions to a json file :param path: local path to package :param repo_location: location of github repo used to track versions :param output_location: location of version control json report
-
hip_data_tools.hipages.version_tracking.find_any_relevant_decorations_in_file(path)¶ Find any relevant decorations in the provided in tehe :param path: Path to the file being scanned :type path: string
Returns (list(string)): List of decorated definitions found in the file
-
hip_data_tools.hipages.version_tracking.find_relevant_file_versions(package_location, repo_location)¶ Finds all the classes, and versions, for classes with the relevant decorator given the package and the repo location :param package_location: path to package :type package_location: str :param repo_location: path to relevant git repo :type repo_location: str
- Returns: dictionary of classes and the latest git hash of the
- file in which they live
-
hip_data_tools.hipages.version_tracking.find_tracked_modules(file_list)¶ Iterates through a list of python files, and returns the names of classes, methods and functions and their file locations, which require a version to be found :param file_list: list of paths to python files
Returns: list of class names which require version tracking files_with_tag: list of files in which the version tracked files are foundReturn type: definitions_with_tags
-
hip_data_tools.hipages.version_tracking.get_latest_git_hash_of_files_in_repo(repo, files_to_get)¶ Iterates through a files and gets their latest commit hash using the repo object to interface with git :param repo: git Repo object :param files_to_get: list of absolute or relative paths of files which
require the git hashesReturns: list of git hashes for the file paths supplied
-
hip_data_tools.hipages.version_tracking.main()¶ - Main function which takes command line arguments
- and executes the version finder
-
hip_data_tools.hipages.version_tracking.register_class_for_version_tracking(cls)¶ Transparent decorator class used for registering a class with version monitoring.
Parameters: cls – class to decorate Returns: decorated class
-
hip_data_tools.hipages.version_tracking.register_method_for_version_tracking(meth)¶ Transparent decorator method used for registering a class with version monitoring.
Parameters: meth – class to decorate Returns: decorated class
-
hip_data_tools.hipages.version_tracking.write_versions_to_json(version_dict, output_location)¶ Creates a json of the versions dictionary and writes it to file :param version_dict: version dictionary of classes and the latest git :param commit hash of the file in which they live: :param output_location: location to write output json file to