Verfun is a util for generating a checksum for a python function
Project description
Verfun
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
- Version an algorithm that did something to your data
- Rerun said algorithm on affected data if the algorithm changes
- 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 details)
File details
Details for the file verfun-0.2.1.tar.gz.
File metadata
- Download URL: verfun-0.2.1.tar.gz
- Upload date:
- Size: 2.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/43.0.0 requests-toolbelt/0.9.1 tqdm/4.41.1 CPython/3.6.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4e6b49a90b2e65ff26c13d6502f2ab102cc719e492cb31d963aec3f7a62f5c29
|
|
| MD5 |
6ef8b5189204c4e3262ffe06fa413f5f
|
|
| BLAKE2b-256 |
95a5158b7dd16e8b224a885caae17da8a2d05f6feedd3b133547a370a1d9a603
|