finesse.compilation_hash module
This module is only meant for Finesse users with editable (developer) installs of Finesse, meaning they install the git repository directly. While switching branches or updating code files, it can happen that your compiled cython extension modules are no longer compatible with your python modules or vice versa. For instance, when checking out a new branch with Cython changes and forgetting to compile before running your Finesse code.
This module helps solve that in two steps:
setup.py uses this module to calculate a hash of the contents of all cython files
it saves this file in the ‘HASH_FILE’ path
the root __init__.py of Finesse calculates the hash again and compares it to the contents of HASH_FILE
if the contents are different, it emits a warning suggesting to re-compile
The hashing of all cython file only takes a 1 ms (on my machine), so it is negligible to both the compilation time and the startup time of the Python kernel.
- Caveats:
This does not catch issues with dependencies differing at compile-time vs runtime, e.g. Numpy or Scipy version
This will fire false positives for meaningless changes to Cython files, like formatting
This does not tell you which Cython file has changed since the last time you compiled and associated Git information
I considered using modification times of the files, but it would unnecessarily complex. I also considered just writing the git commit hash in the file, but that wouldn’t work with ‘dirty’ working directories.
- finesse.compilation_hash.calculate_hash() str[source]
Calculate a hash of all Cython files in the Finesse directory.
- finesse.compilation_hash.custom_formatwarning(message, category, filename, lineno, line=None) str[source]
Custom warning formatter excluding the source line.
- finesse.compilation_hash.get_cython_files() Iterable[Path][source]
Get all Cython files in the Finesse directory.