The previous v0.19.0 release had a small change in the C bindings to allow importbin
to function, but missing from the release notes was mention of the fact that the Python bindings had also changed in a similar way - to require the content of the file to be provided as a bytes
type instead of a str
. To convert from str
to bytes
, simply call .encode()
on the str
.
In order to write Python code that works for both Jsonnet versions, the Jsonnet version is now provided as a field of the _jsonnet module, which allows writing code like the following:
import _jsonnet
import semver
import_returns_bytes = semver.compare(getattr(_jsonnet, 'version', 'v0.18.0')[1:], '0.18.0') > 0
def no_nl_eof(directory, rel):
if import_returns_bytes:
return "foo.jsonnet", b"42"
else:
return "foo.jsonnet", "42"
_jsonnet.evaluate_snippet("test.jsonnet", "{\nlocal foo = import 'foo.jsonnet',\n \n 'bar': foo\n }\n", import_callback=no_nl_eof)
This release also fixes an off-by-one truncation error in the import callback logic of the Python bindings introduced in the previous release. This was only noticeable if the imported file had no trailing \n, or if you were using importbin
with a Python import callback.