Skip to main content

Module materialize

Module materialize 

Source
Expand description

Bundled plugins on disk: a bundled plugin’s files live in the binary, but a backend or a script tool needs them as files a process can run. materialize writes them once to a versioned cache folder, <root>/<id>-<byob version>-<content hash>/, and returns it.

  • The folder name changes whenever the files or byob’s version do, so a folder that exists is complete and current: it is written under a temporary name and renamed into place (two byob processes racing both end up with the same folder).
  • Its files are made read-only: edits belong in a fork (keep_plugin), not here. Python may still add __pycache__.
  • Older folders of the same plugin are removed when a new one is made, once nothing has used them for PRUNE_AFTER (another byob, of another version, may be running from one): every use stamps the folder (USED).

Constants§

MARKER
What marks a materialized folder (and holds its hash).
PRUNE_AFTER
An older folder unused this long is removed.
USED
Touched whenever a byob uses the folder.

Functions§

content_hash
FNV-1a over the files (path, NUL, text, NUL), stable across runs.
folder
The folder id’s files go to under root for this byob version.
materialize
Write plugin id’s files under root (if not there yet) and return the folder.