beacon-biosignals / StableHashTraits.jl

Compute hashes over any Julia object simply and reproducibly
MIT License
9 stars 3 forks source link

Avoid reading package files at runtime #32

Closed KristofferC closed 1 year ago

KristofferC commented 1 year ago

This package tries to read its readme at initialization time:

https://github.com/beacon-biosignals/StableHashTraits.jl/blob/9def8095355de77f2942a7ddd1592d3dd267ea6c/src/StableHashTraits.jl#L62

This is an issue when using e.g. PackageCompiler with this package because the markdown file might not exist. Also, the pkgdir computation will refer to where the package was loaded which won't work if one creates a sysimage on one machine and transfers it to another.

I would suggest either reading this file at precompile time or alternatively having a graceful fallback in case the file does not exist.

ericphanson commented 1 year ago

One note is if we read it at precompilation time, we could use Base.include_dependency to invalidate the precompilation cache if the readme changes. (Although that could be annoying to wait for precompilation just to update some docstrings)

haberdashPI commented 1 year ago

Happy to fix.

@ericphanson if I understand, with that trick, I could do this outside of __init__. I had done that originally, but it got kind of annoying because of the issues around the compilation cache not invalidating when I revised the readme. (Though in practice, for users, this wouldn't be too much of an issue since rarely would the README change without the code changing; it's just annoying for evaluating changes to the README while developing).

Is using joinpath(@__DIR__, "..", "README.md") any more reliable?

haberdashPI commented 1 year ago

I guess a more germane question than my last point: does moving this code outside init mean that the README.md will always exist?

KristofferC commented 1 year ago

Yes because at precompile time we are sure that the files exist.