ENT-13814: Added syntax-description and GH Action to update it weekly to replace policy_language.py#59
Merged
olehermanse merged 1 commit intocfengine:mainfrom Apr 13, 2026
Conversation
… to replace policy_language.py Adds syntax-description.json Removes old policy_language.py Uses syntax-decription.json to get BUILTINS Signed-off-by: Simon Halvorsen <simon.halvorsen@northern.tech>
olehermanse
reviewed
Apr 13, 2026
Comment on lines
+53
to
+77
| def _derive_syntax_sets(data: dict) -> tuple: | ||
| """Derive the four sets used for linting from a loaded syntax-description dict. | ||
|
|
||
| Returns: (ALLOWED_BUNDLE_TYPES, BUILTIN_PROMISE_TYPES, BUILTIN_FUNCTIONS, DEPRECATED_PROMISE_TYPES) | ||
| """ | ||
| builtin_body_types = set(data.get("bodyTypes", {}).keys()) | ||
|
|
||
| allowed_bundle_types = data.get("bundleTypes", {}).keys() | ||
|
|
||
| builtin_promise_types = set(data.get("promiseTypes", {}).keys()) | ||
|
|
||
| builtin_functions = set(data.get("functions", {}).keys()) | ||
|
|
||
| deprecated_promise_types = { | ||
| "defaults", | ||
| "guest_environments", | ||
| } # Has to be hardcoded, not tagged in syntax-description.json | ||
|
|
||
| return ( | ||
| builtin_body_types, | ||
| allowed_bundle_types, | ||
| builtin_promise_types, | ||
| builtin_functions, | ||
| deprecated_promise_types, | ||
| ) |
Member
There was a problem hiding this comment.
In the future, we will want to access the syntax data in more complicated ways, not just lists of keys. I don't think this approach will scale nicely, please use a class instead;
class SyntaxData:
def __init__(self, path):
self._data = get_json(path)
# Maybe add some assertions here, linting will not work correctly
# if for example allowed bundle types is empty.
[...]
def get_bundle_types(self):
[...]
# In the future we might choose to do something like;
def is_valid_attribute(self, promise_type, attribute_name, attribute_value):
[...]
olehermanse
reviewed
Apr 13, 2026
| @@ -0,0 +1,69 @@ | |||
| name: Update syntax-description | |||
Member
There was a problem hiding this comment.
I would probably prefer to put the JSON / yaml in as separate commits to avoid doing too many things in one commit.
olehermanse
reviewed
Apr 13, 2026
| """ | ||
| builtin_body_types = set(data.get("bodyTypes", {}).keys()) | ||
|
|
||
| allowed_bundle_types = data.get("bundleTypes", {}).keys() |
Member
There was a problem hiding this comment.
As mentioned below, linting will not work correctly if this one is empty, so it might be appropriate to assert / fail early when the syntax data is invalid / missing.
olehermanse
approved these changes
Apr 13, 2026
Member
olehermanse
left a comment
There was a problem hiding this comment.
Looks correct, adjustments can be made in follow-up PRs.
larsewi
reviewed
Apr 13, 2026
Comment on lines
+51
to
+55
| if ! cmp -s new.json ./src/cfengine_cli/syntax-description.json; then | ||
| cat new.json > ./src/cfengine_cli/syntax-description.json | ||
| echo "CHANGES_DETECTED=true" >> $GITHUB_ENV | ||
| rm new.json | ||
| fi |
Contributor
There was a problem hiding this comment.
Suggested change
| if ! cmp -s new.json ./src/cfengine_cli/syntax-description.json; then | |
| cat new.json > ./src/cfengine_cli/syntax-description.json | |
| echo "CHANGES_DETECTED=true" >> $GITHUB_ENV | |
| rm new.json | |
| fi | |
| if ! cmp -s new.json ./src/cfengine_cli/syntax-description.json; then | |
| cat new.json > ./src/cfengine_cli/syntax-description.json | |
| echo "CHANGES_DETECTED=true" >> $GITHUB_ENV | |
| rm new.json | |
| fi |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds syntax-description.json
Removes old policy_language.py
Uses syntax-decription.json to get BUILTINS