Jsonnet

Latest version: v0.20.0

Safety actively analyzes 629052 Python packages for vulnerabilities to keep your Python projects secure.

Scan your dependencies

Page 5 of 7

0.8.6

Aside from minor improvements and bug fixes, this release has one change to the language that is not compatible with previous versions.

Some users pointed out that import "foo" + bar had surprising behavior, because it looks like it will compute the name of the import, but in actual fact it is parsed as (import "foo") + bar, which converts the imported Jsonnet file to a string, then appends bar to it. In order to avoid that confusion, we've make the parentheses mandatory in those cases.

The vast majority of imports, which are unambiguous, are not affected. For example:

local foo = import "foo";

This release also fixes the compilation of Jsonnet during pip install.

0.8.5

Yet another release needed to fix the Python build.
This release also includes the restrictions on super that should have been in v0.8.1 but the change got lost in the gh-pages branch.

0.8.4

Fix the Python release (again).

0.8.3

The last release was broken on Python so this fixes that. It also fixes a bug with decoding high unicode codepoints.

0.8.2

This release:
- Adds unicode support (finally fixing 1)
- Extends the array and object comprehension syntax to arbtirary if / for specifiers
- Fixes a garbage collection bug when using assertions
- Adds std.count() std.startsWith() and std.endsWith()
- Re-organizes the source tree.

0.8.1

There are 2 major things in this release:

Asserts

The biggest change in this release is the addition of the assert construct. This is backwards-compatible except if you were using 'assert' as an identifier, in which case you'll have to rename it (or use quotes "assert": in the case of a field name).

Assert expressions


assert e1 : e2; e3


Is simply desugared to


if e1 then e3 else error e2


And the : e2 is optional like in Python and Java (except Python uses a comma instead of a colon).

Object assertions (invariants)

It is also possible to put asserts into objects:


local Base = {
assert self.x <= self.y : "%d greater than %d" % [self.x, self.y],
x: 1,
y: 2,
};


These are preserved over inheritance and follow the usual late binding semantics.


Base { x: 3 } // Raises an error.
Base { x: 3, y: 4 } // Ok.


This can be useful for enumerations:


local Base = {
assert std.setMember(self.animal, self.availableAnimals)
: "%s is not a valid animal" % self.animal,
animal: error "You must select an animal",
availableAnimals: ["CAT", "DOG"],
};
Base { animal: "FISH" } // Raises an error.
Base { animal: "FISH", availableAnimals+: ["FISH"] } // Ok.


If you want to constrain the base object so the animals cannot be extended, you can do:


local Base = {
local available_animals = ["CAT", "DOG"],
assert std.setMember(self.animal, available_animals)
: "%s is not a valid animal" % self.animal,
animal: error "You must select an animal",
};


Preventing override of fields

Finally, using this mechanism you can lock down a template so that users can only override the "inputs", not the "outputs". For example imagine building bash scripts as part of a workflow framework:


local Template = {
user:: error "Must set user",
command:: error "Must set command",
outputFile:: "out.log",

local template = self,
local output = {
bash: "sudo %(user)s \"%(command)s\" > %(outputFile)s" % template,
},
bash: output.bash,
assert self == output : "You may not override this template's output."
};
// User code:
Template {user: "myname", command: "ls", bash+:"; echo hi"}


This would produce an error because the assertion prevents the user from adding stuff onto the end of the bash command.

Removal of super as a construct in its own right

Early in development we decided to avoid restrictions in the language to see where this would lead us. Two such cases led to implementation complexity and we were tempted to remove them, but we were not sure if they would be useful. One case was mixins, which turned out to be enormously useful in many cases. The other case was the ability to do super by itself, not just in the context of super.f or super[e]. The semantics of this were tricky to define in the case of extending super, or extending super with itself (although we did so, and the rules are on the website)! It also makes the interpreter and object model harder to implement. To the best of our knowledge, there is not one single person using super in this fashion, so we have now restricted it to just super.f and super[e] as done in other languages.

Page 5 of 7

© 2024 Safety CLI Cybersecurity Inc. All Rights Reserved.