Cache and change detection #24
Replies: 1 comment 3 replies
-
Hi, thanks a lot for starting off this discussion. I find the idea of having a change detection quite appealing. As you already explain, there are various ways to realize a detection mechanism, e.g. as part of PyLuaTeX alone or via external tools like git. A first estimation from my side is: implementing it in PyLuaTeX alone involves either a lot of work or lots of hard coded decisions (how to hash, what to hash, when to reset) (or possibly both). Also, I want PyLuaTeX to be rather lean and flexible. This is, by the way, why I leave the acutual logic of code typesetting to the user. For the change detection, I'd suggest something similar: A possible (simple) implementation could be like this: \documentclass{article}
\usepackage{pyluatex}
\directlua{
hash = ""
function hash_handler(info)
text = info.session .. table.concat(info.code) .. table.concat(info.output)
% update MD5 hash with executed Python code and output
hash = md5.sumhexa(hash .. text)
end
pyluatex.register_event_handler("post_execute", "hash", hash_handler)
}
% write final hash to *.pyluatex_log file
\AtEndDocument{\directlua{io.savedata("\jobname.pyluatex_log", hash)}}
\begin{document}
\py{1 + 1}
\end{document} Content of document.pyluatex_log after running the above TeX file:
In this example, the actual change detection would be done with git by checking in What do you think about this idea? Would that be helpful for you? Merry Christmas :) |
Beta Was this translation helpful? Give feedback.
-
Hello, first of all - you have a very interesting project. I'm starting to work on a new textbook. My previous book was using SageTeX, I'm looking around now, because I need something for generic Python this time. Would love to have a change detection:
If something changes in Python (version of some library, API, format of returned value, etc), and the results are no longer like they were before, I'd like to see a warning that I have to rework part of already written book. That way, I will be able to catch changes early.
The way I imagine it could be implemented (purly on python side) is something like this:
This way we have a few separate strings of HASH values, starting at the start of new interpreter session, and they are equal if both current code and execution history within given session does not change. As a side product (although this is not my intention), a cache mode would be possible, where all output could be read from sqlite, if no input changed (might be useful for some longer Monte Carlo simulations that take a long time to run). The cache itself could be implemented in lua, which could make running python not needed at all, but change detection need to execute all code anyway for comparison, so this is why I imagined it like this.
This would be a killer feature for me. Without it, I'm sticking to other systems, which store temporary files, because then I can store temporary files in git and analyse changes that way. Anyway, having this integrated into single run and displayed directly in editor trough LSP, in my opinion would be really useful.
What do you think?
Beta Was this translation helpful? Give feedback.
All reactions