In this case, `open()` or <https://docs.python.org...
# plugins
e
In this case,
open()
or https://docs.python.org/3/library/importlib.html#importlib.resources.read_binary or just embedding the script code in platform.py as a string are your likeliest options and they're all fine. The code Tom pointed to earlier has an example of creating a Digest given bytes (a string literal is the source in this case, but you can read in the bytes with
open()
or
importlib.resources
or ... however): https://github.com/pantsbuild/pants/blob/4f39186f780310e73a708b3b589635dfa2e09696/src/python/pants/engine/process.py#L511-L530 The reason
open()
and
importlib.resources
are OK here is they are reading content whose content changes Pants will be aware of. This is for two reasons: 1. Any path you add to
[GLOBAL] pythonpath
is watched by pantsd for changes and, upon change, pantsd willl restart itself to pick up the change. 2. Rule code is always re-run when Pants starts afresh. To explain 2 a bit more, the only long term caching Pants does is of
Process
executions done in rule code. Once those are executed successfully for a given set of inputs, they are never executed again - ever... unless you wipe out the pants database stored under in ~/.cache/pants (if you use remote caching you'd also have to invalidate that cache).
👍 1