Skip to main content

Verfun is a util for generating a checksum for a python function

Project description

Verfun

Build Status

Verfun is a util for generating a checksum for a python function ignoring whitespace, comments, variable names, etc.

Great, why is this useful?

Given a use case where you want to

  1. Version an algorithm that did something to your data
  2. Rerun said algorithm on affected data if the algorithm changes
  3. not rerun if you only add comments, refactor variable names, etc

Features:

Generating a md5 checksum of a given function, ignoring the following:

  • function name
  • docstrings and comments
  • whitespace
  • indentation

Example usage

Example taken from example.py

from verfun import version_hash_for_function, version_hash_for_function_list


def some_strange_looking_function(param1, callback_fn):
    tail = param1[-1]
    return callback_fn(tail)


def same_strange_looking_function(param1, callback_fn):
    """
    This function is documented, but the function is identical to some_strange_looking_function
    and should result in the same hash
    """
    tail = param1[-1]
    # return the callback value from the tail of param whatever that is
    return callback_fn(tail)


def different_function():
    return "this one is different"


# generate checksum for each function
print(version_hash_for_function(some_strange_looking_function))
# c4cb4d2638d790016cbee29a6ed5af8c

print(version_hash_for_function(same_strange_looking_function))
# c4cb4d2638d790016cbee29a6ed5af8c

print(version_hash_for_function(different_function))
# 8515c1678211e93362800b30ef7234cf

# generate a checksum for multiple functions
print(version_hash_for_function_list([some_strange_looking_function, different_function]))
# 1fa4dc521f63cd5a8faac4cc8402d63d

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

verfun-0.2.1.tar.gz (2.3 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page