Compare commits

..

No commits in common. "697669bc47fdf3cefb71a59eb8e06eebd578c305" and "e4b045ab7595be3b02d26f955ad893433cf18149" have entirely different histories.

283 changed files with 250 additions and 1073 deletions

View file

@ -1,14 +1,3 @@
## 0.1.0a9 (2025-04-30)
### Feat
- add yamllint validation
### Fix
- update tests
- add version
## 0.1.0a8 (2025-04-01)
### Fix

View file

@ -4,7 +4,7 @@ requires = ["flit_core >=3.8.0,<4"]
[project]
name = "rougail.output_formatter"
version = "0.1.0a9"
version = "0.1.0a8"
authors = [{name = "Emmanuel Garette", email = "gnunux@gnunux.info"}]
readme = "README.md"
description = "Rougail output formatter"
@ -39,9 +39,5 @@ name = "cz_conventional_commits"
tag_format = "$version"
version_scheme = "pep440"
version_provider = "pep621"
version_files = [
"src/rougail/output_formatter/__version__.py",
"pyproject.toml:version"
]
update_changelog_on_bump = true
changelog_merge_prerelease = true

View file

@ -22,7 +22,6 @@ from pathlib import Path
from typing import Optional
from ruamel.yaml import YAML, CommentedMap
from ruamel.yaml.representer import RoundTripRepresenter
from ruamel.yaml.tokens import CommentToken
from ruamel.yaml.error import CommentMark
from ruamel.yaml.comments import CommentedSeq
@ -39,27 +38,11 @@ from rougail.object_model import Variable, Family, Calculation, JinjaCalculation
from rougail.utils import normalize_family
from .upgrade import RougailUpgrade
from .__version__ import __version__
def _(text):
return text
# XXX explicit null
def represent_none(self, data):
return self.represent_scalar('tag:yaml.org,2002:null', 'null')
def represent_str(self, data):
if data == '':
return self.represent_scalar('tag:yaml.org,2002:null', "")
return self.represent_scalar('tag:yaml.org,2002:str', data)
RoundTripRepresenter.add_representer(type(None), represent_none)
RoundTripRepresenter.add_representer(str, represent_str)
# XXX
class RougailOutputFormatter:
output_name = 'formatter'
@ -128,9 +111,7 @@ class RougailOutputFormatter:
self.families = {None: CommentedMap()}
self.parse()
self.yaml.indent(mapping=2, sequence=4, offset=2)
self.yaml.version = '1.2'
self.yaml.explicit_start=True
self.yaml.explicit_end = True
self.default_flow_style = False
with BytesIO() as ymlfh:
self.yaml.dump(self.families[None], ymlfh)
@ -155,9 +136,7 @@ class RougailOutputFormatter:
self.families[None][version_name] = None
self.families[None].yaml_value_comment_extend(version_name, [CommentToken('\n\n', CommentMark(0)), None])
version = None
self.remaining = len(self.rougail.paths._data)
for path, obj in self.rougail.paths._data.items():
self.remaining -= 1
if version is None or version == '':
version = obj.version
if path == self.rougail.namespace:
@ -214,16 +193,7 @@ class RougailOutputFormatter:
elif not set(family) - {'description'}:
#
ret[name] = CommentedMap()
add_column = 3
path_len = path.count('.')
if self.rougail.namespace:
path_len -= 1
column = path_len * 2 + len(name) + add_column
if self.remaining:
description = family["description"] + '\n\n'
else:
description = family["description"]
ret.yaml_add_eol_comment(description, name, column=column)
ret.yaml_add_eol_comment(family["description"] + '\n\n', name)
else:
self.add_space(family)
ret[name] = family
@ -286,35 +256,22 @@ class RougailOutputFormatter:
# shorthand notation
default = variable.get('default')
ret[name] = default
add_column = 3
if isinstance(default, list):
ret[name] = CommentedSeq()
if not default:
add_column += 3
for d in default:
ret[name].append(d)
else:
if default is None:
ret[name] = ""
else:
ret[name] = default
add_column += len(str(default)) + 1
if "description" in variable:
description = variable["description"]
if self.remaining and (not multi or not default):
if not multi or not default:
description += "\n\n"
path_len = path.count('.')
if self.rougail.namespace:
path_len -= 1
column = path_len * 2 + len(name) + add_column
ret.yaml_add_eol_comment(description, name, column=column)
ret.yaml_add_eol_comment(description, name)
if multi and default:
self.add_space(ret)
else:
self.add_space(ret)
else:
if "default" in variable and variable["default"] is None:
variable["default"] = ""
ret[name] = variable
self.add_space(variable)
@ -337,7 +294,6 @@ class RougailOutputFormatter:
func = parent.yaml_key_comment_extend
else:
func = parent.yaml_value_comment_extend
if self.remaining:
func(param, [CommentToken(enter, CommentMark(0)), None])
def object_to_yaml(self, key, type_, value, multi, object_path):

View file

@ -1 +0,0 @@
__version__ = "0.1.0a9"

View file

@ -1,6 +1,4 @@
%YAML 1.2
---
_version: 1.1
version: # a variable
...

View file

@ -1,6 +1,4 @@
%YAML 1.2
---
version: 1.1
empty:
...

View file

@ -1,4 +1,3 @@
%YAML 1.2
---
version: 1.1
@ -11,4 +10,3 @@ var2:
jinja: |-
{{ _.var1 }}
description: the value of var1
...

View file

@ -1,4 +1,3 @@
%YAML 1.2
---
version: 1.1
@ -16,4 +15,3 @@ var2:
{{ val }}
{% endfor %}
description: the value of _.var1
...

View file

@ -1,4 +1,3 @@
%YAML 1.2
---
version: 1.1
@ -13,4 +12,3 @@ var2:
description: a second variable
default:
variable: _.var1
...

View file

@ -1,6 +1,4 @@
%YAML 1.2
---
version: 1.1
var1: # a variable
...

View file

@ -1,6 +1,4 @@
%YAML 1.2
---
version: 1.1
var2: # a variable
...

View file

@ -1,6 +1,4 @@
%YAML 1.2
---
version: 1.1
without_type: non # a variable
...

View file

@ -1,4 +1,3 @@
%YAML 1.2
---
version: 1.1
@ -13,4 +12,3 @@ var4: false # the forth variable
var5: false # the fifth variable
var6: false # the sixth variable
...

View file

@ -1,4 +1,3 @@
%YAML 1.2
---
version: 1.1
@ -6,4 +5,3 @@ variable:
description: a variable
mandatory: false
default: true
...

View file

@ -1,4 +1,3 @@
%YAML 1.2
---
version: 1.1
@ -27,7 +26,7 @@ var3:
var4:
description: the forth variable
choices:
- null
-
- b
- c
mandatory: false
@ -47,4 +46,3 @@ var6:
- 2
- 3
default: 1
...

View file

@ -1,4 +1,3 @@
%YAML 1.2
---
version: 1.1
@ -12,4 +11,3 @@ var:
return_type: number
description: choices is 0 to 9
default: 9
...

View file

@ -1,4 +1,3 @@
%YAML 1.2
---
version: 1.1
@ -13,4 +12,3 @@ var2:
description: the second variable
default:
variable: _.var1
...

View file

@ -1,4 +1,3 @@
%YAML 1.2
---
version: 1.1
@ -12,4 +11,3 @@ var2:
choices:
variable: _.var1
default: a
...

View file

@ -1,4 +1,3 @@
%YAML 1.2
---
version: 1.1
@ -17,4 +16,3 @@ var3:
description: a third variable
default:
variable: _.var2
...

View file

@ -1,4 +1,3 @@
%YAML 1.2
---
version: 1.1
@ -19,4 +18,3 @@ family:
description: a third variable
default:
variable: __.var2
...

View file

@ -1,4 +1,3 @@
%YAML 1.2
---
version: 1.1
@ -10,4 +9,3 @@ custom2:
description: the seconf variable
type: custom
default: value
...

View file

@ -1,4 +1,3 @@
%YAML 1.2
---
version: 1.1
@ -6,4 +5,3 @@ variable:
description: a domain name variable
type: domainname
default: my.domain.name
...

View file

@ -1,4 +1,3 @@
%YAML 1.2
---
version: 1.1
@ -8,4 +7,3 @@ variable:
params:
allow_ip: true
default: my.domain.name
...

View file

@ -1,4 +1,3 @@
%YAML 1.2
---
version: 1.1
@ -13,4 +12,3 @@ var4: 10.1 # the forth variable
var5: 10.1 # the fifth variable
var6: 10.1 # the sixth variable
...

View file

@ -1,4 +1,3 @@
%YAML 1.2
---
version: 1.1
@ -13,4 +12,3 @@ var4: 10 # this forth variable
var5: 10 # the fifth variable
var6: 10 # the sixth variable
...

View file

@ -1,4 +1,3 @@
%YAML 1.2
---
version: 1.1
@ -15,4 +14,3 @@ variable3:
description: a port variable with integer default value
type: port
default: 8080
...

View file

@ -1,4 +1,3 @@
%YAML 1.2
---
version: 1.1
@ -9,4 +8,3 @@ var:
- '#b2b2b2'
regexp: ^#(?:[0-9a-f]{3}){1,2}$
default: '#a1a1a1'
...

View file

@ -1,4 +1,3 @@
%YAML 1.2
---
version: 1.1
@ -17,4 +16,3 @@ var2:
- '#b3b2b2'
default:
variable: _.var1
...

View file

@ -1,4 +1,3 @@
%YAML 1.2
---
version: 1.1
@ -10,4 +9,3 @@ secret2:
description: the second variable
type: secret
default: value
...

View file

@ -1,4 +1,3 @@
%YAML 1.2
---
version: 1.1
@ -26,4 +25,3 @@ secret3:
forbidden_char:
- $
default: value
...

View file

@ -1,4 +1,3 @@
%YAML 1.2
---
version: 1.1
@ -13,4 +12,3 @@ var4: value # the forth variable
var5: value # the fifth variable
var6: value # the sixth variable
...

View file

@ -1,4 +1,3 @@
%YAML 1.2
---
version: 1.1
@ -10,4 +9,3 @@ var:
- quote"
- quote"'
default: quote'
...

View file

@ -1,4 +1,3 @@
%YAML 1.2
---
version: 1.1
@ -17,4 +16,3 @@ var2:
Multi line
Help
With useful information
...

View file

@ -1,4 +1,3 @@
%YAML 1.2
---
version: 1.1
@ -9,4 +8,3 @@ var1:
var2:
description: the second variable
help: message with "
...

View file

@ -1,4 +1,3 @@
%YAML 1.2
---
version: 1.1
@ -17,4 +16,3 @@ var2:
Multi line
<Help>
With useful information
...

View file

@ -1,6 +1,4 @@
%YAML 1.2
---
version: 1.1
variable: quote" # a variable
...

View file

@ -1,6 +1,4 @@
%YAML 1.2
---
version: 1.1
variable: quote'" # a variable
...

View file

@ -1,6 +1,4 @@
%YAML 1.2
---
version: 1.1
variable: quote\"\' # a variable
...

View file

@ -1,6 +1,4 @@
%YAML 1.2
---
version: 1.1
variable: quote' # a variable
...

View file

@ -1,4 +1,3 @@
%YAML 1.2
---
version: 1.1
@ -11,4 +10,3 @@ variable:
params:
test_information:
information: test_information
...

View file

@ -1,4 +1,3 @@
%YAML 1.2
---
version: 1.1
@ -7,4 +6,3 @@ variable:
default:
type: namespace
mandatory: false
...

View file

@ -1,4 +1,3 @@
%YAML 1.2
---
version: 1.1
@ -11,4 +10,3 @@ variable:
namespace:
type: namespace
mandatory: false
...

View file

@ -1,4 +1,3 @@
%YAML 1.2
---
version: 1.1
@ -22,7 +21,7 @@ var3:
var4:
description: the forth variable
test:
- null
-
- test1
- test2
mandatory: false
@ -39,4 +38,3 @@ var6:
- test1
- test2
multi: true
...

View file

@ -1,4 +1,3 @@
%YAML 1.2
---
version: 1.1
@ -16,4 +15,3 @@ variable2:
- val2
multi: true
mandatory: false
...

View file

@ -1,4 +1,3 @@
%YAML 1.2
---
version: 1.1
@ -13,4 +12,3 @@ my_variable:
- variable: _.source_variable_1
- variable: _.source_variable_2
default: val1
...

View file

@ -1,4 +1,3 @@
%YAML 1.2
---
version: 1.1
@ -12,5 +11,4 @@ variable:
param1: string
param2: 1
param3: true
param4: null
...
param4:

View file

@ -1,4 +1,3 @@
%YAML 1.2
---
version: 1.1
@ -12,4 +11,3 @@ var:
information:
information: test_information
variable: _.var
...

View file

@ -1,4 +1,3 @@
%YAML 1.2
---
version: 1.1
@ -13,4 +12,3 @@ var2:
information:
information: test_information
variable: _.var1
...

View file

@ -1,4 +1,3 @@
%YAML 1.2
---
version: 1.1
@ -9,4 +8,3 @@ my_calculated_variable:
optional: true
- variable: _.my_variable_unexists
optional: true
...

View file

@ -1,4 +1,3 @@
%YAML 1.2
---
version: 1.1
@ -9,4 +8,3 @@ my_calculated_variable:
optional: true
- variable: _.my_variable
optional: true
...

View file

@ -1,4 +1,3 @@
%YAML 1.2
---
version: 1.1
@ -7,4 +6,3 @@ my_calculated_variable:
default:
variable: _.my_variable
optional: true
...

View file

@ -1,4 +1,3 @@
%YAML 1.2
---
version: 1.1
@ -11,4 +10,3 @@ my_calculated_variable:
default:
variable: _.my_variable
optional: true
...

View file

@ -1,4 +1,3 @@
%YAML 1.2
---
version: 1.1
@ -29,4 +28,3 @@ var1:
mandatory: false
var2: no # a second variable
...

View file

@ -1,4 +1,3 @@
%YAML 1.2
---
version: 1.1
@ -9,4 +8,3 @@ var2:
default:
information: test_information
variable: _.var1
...

View file

@ -1,4 +1,3 @@
%YAML 1.2
---
version: 1.1
@ -9,4 +8,3 @@ var2:
default:
information: test_information
variable: _.var1
...

View file

@ -1,4 +1,3 @@
%YAML 1.2
---
version: 1.1
@ -12,4 +11,3 @@ var:
return_type: number
description: choice for 0 to 9
default: 9
...

View file

@ -1,4 +1,3 @@
%YAML 1.2
---
version: 1.1
@ -8,4 +7,3 @@ variable:
jinja: >-
no
description: return no
...

View file

@ -1,6 +1,4 @@
%YAML 1.2
---
version: 1.1
variable: rougail # a variable
...

View file

@ -1,4 +1,3 @@
%YAML 1.2
---
version: 1.1
@ -23,4 +22,3 @@ variable3:
params:
variable:
variable: rougail.variable
...

View file

@ -1,6 +1,4 @@
%YAML 1.2
---
version: 1.1
variable: value # a variable
...

View file

@ -1,6 +1,4 @@
%YAML 1.2
---
version: 1.1
variable: value in extra # a variable
...

View file

@ -1,4 +1,3 @@
%YAML 1.2
---
version: 1.1
@ -6,4 +5,3 @@ variable:
description: a variable
default:
variable: extra.variable
...

View file

@ -1,4 +1,3 @@
%YAML 1.2
---
version: 1.1
@ -25,4 +24,3 @@ var7: # the seventh variable
var8: # the eighth variable
- true
...

View file

@ -1,4 +1,3 @@
%YAML 1.2
---
version: 1.1
@ -12,4 +11,3 @@ custom2:
type: custom
default:
- value
...

View file

@ -1,4 +1,3 @@
%YAML 1.2
---
version: 1.1
@ -25,4 +24,3 @@ var7: # the seventh variable
var8: # the eighth variable
- 0.0
...

View file

@ -1,4 +1,3 @@
%YAML 1.2
---
version: 1.1
@ -25,4 +24,3 @@ var7: # the seventh variable
var8: # the eighth variable
- 0
...

View file

@ -1,4 +1,3 @@
%YAML 1.2
---
version: 1.1
@ -6,6 +5,5 @@ var1:
description: the second variable
default:
- value
- null
-
empty: false
...

View file

@ -1,4 +1,3 @@
%YAML 1.2
---
version: 1.1
@ -22,4 +21,3 @@ var7: # the seventh variable
var8: # the eighth variable
- value
...

View file

@ -1,7 +1,5 @@
%YAML 1.2
---
version: 1.1
variable: # a variable
- quote"
...

View file

@ -1,7 +1,5 @@
%YAML 1.2
---
version: 1.1
variable: # a variable
- quote'"
...

View file

@ -1,7 +1,5 @@
%YAML 1.2
---
version: 1.1
variable: # a variable
- quote'
...

View file

@ -1,4 +1,3 @@
%YAML 1.2
---
version: 1.1
@ -14,4 +13,3 @@ variable:
params:
test_information:
information: test_information_list
...

View file

@ -1,4 +1,3 @@
%YAML 1.2
---
version: 1.1
@ -11,4 +10,3 @@ variable2:
description: a second variable
choices:
variable: _.variable1
...

View file

@ -1,4 +1,3 @@
%YAML 1.2
---
version: 1.1
@ -8,4 +7,3 @@ int:
min_number: 0
max_number: 100
default: 10
...

View file

@ -1,4 +1,3 @@
%YAML 1.2
---
version: 1.1
@ -6,4 +5,3 @@ variable:
description: an auto save variable
default: no
auto_save: true
...

View file

@ -1,4 +1,3 @@
%YAML 1.2
---
version: 1.1
@ -9,4 +8,3 @@ var2:
default:
variable: _.var1
auto_save: true
...

View file

@ -1,4 +1,3 @@
%YAML 1.2
---
version: 1.1
@ -17,4 +16,3 @@ var2:
_.var1 is yes
{% endif %}
description: only if the variable var1 has value "yes"
...

View file

@ -1,4 +1,3 @@
%YAML 1.2
---
version: 1.1
@ -8,4 +7,3 @@ var:
auto_save: true
mandatory: false
hidden: true
...

View file

@ -1,4 +1,3 @@
%YAML 1.2
---
version: 1.1
@ -17,4 +16,3 @@ var3:
{% if _.var1 == 'value' or _.var2 == 'blah' %}
value
{% endif %}
...

View file

@ -1,4 +1,3 @@
%YAML 1.2
---
version: 1.1
@ -17,4 +16,3 @@ var3:
{% if _.var2 is propertyerror %}
value
{% endif %}
...

View file

@ -1,4 +1,3 @@
%YAML 1.2
---
version: 1.1
@ -21,4 +20,3 @@ variable2:
condition is yes
{% endif %}
description: if condition is egal to "yes"
...

View file

@ -1,4 +1,3 @@
%YAML 1.2
---
version: 1.1
@ -29,4 +28,3 @@ var2:
condition is yes
{% endif %}
description: if condition is yes
...

View file

@ -1,4 +1,3 @@
%YAML 1.2
---
version: 1.1
@ -23,4 +22,3 @@ variable2:
condition is yes
{% endif %}
description: if condition is egal to "yes"
...

View file

@ -1,4 +1,3 @@
%YAML 1.2
---
version: 1.1
@ -35,4 +34,3 @@ var2:
condition:
variable: _.condition
optional: true
...

View file

@ -1,4 +1,3 @@
%YAML 1.2
---
version: 1.1
@ -8,4 +7,3 @@ variable:
description: a variable
disabled:
variable: _.condition
...

View file

@ -1,4 +1,3 @@
%YAML 1.2
---
version: 1.1
@ -8,4 +7,3 @@ variable:
description: a variable
disabled:
variable: _.condition
...

View file

@ -1,4 +1,3 @@
%YAML 1.2
---
version: 1.1
@ -9,4 +8,3 @@ variable:
disabled:
variable: _.condition
when: yes
...

View file

@ -1,4 +1,3 @@
%YAML 1.2
---
version: 1.1
@ -9,4 +8,3 @@ variable:
disabled:
variable: _.condition
when_not: yes
...

View file

@ -1,4 +1,3 @@
%YAML 1.2
---
version: 1.1
@ -9,4 +8,3 @@ variable:
multi: true
disabled:
variable: _.condition
...

View file

@ -1,4 +1,3 @@
%YAML 1.2
---
version: 1.1
@ -9,4 +8,3 @@ variable:
multi: true
disabled:
variable: _.condition
...

View file

@ -1,4 +1,3 @@
%YAML 1.2
---
version: 1.1
@ -11,4 +10,3 @@ variable:
multi: true
disabled:
variable: _.condition
...

View file

@ -1,4 +1,3 @@
%YAML 1.2
---
version: 1.1
@ -23,4 +22,3 @@ var2:
condition is yes
{% endif %}
description: if condition is yes
...

View file

@ -1,4 +1,3 @@
%YAML 1.2
---
version: 1.1
@ -29,4 +28,3 @@ var2:
condition is yes
{% endif %}
description: if condition is yes
...

View file

@ -1,4 +1,3 @@
%YAML 1.2
---
version: 1.1
@ -29,4 +28,3 @@ var2:
condition is yes
{% endif %}
description: if condition is yes
...

View file

@ -1,4 +1,3 @@
%YAML 1.2
---
version: 1.1
@ -11,4 +10,3 @@ int:
value is too high
{% endif %}
description: the max value is 100
...

View file

@ -1,4 +1,3 @@
%YAML 1.2
---
version: 1.1
@ -15,4 +14,3 @@ var1:
default: oui
var2: no # A second variable
...

View file

@ -1,4 +1,3 @@
%YAML 1.2
---
version: 1.1
@ -13,4 +12,3 @@ var1:
default:
- no
- yes
...

View file

@ -1,4 +1,3 @@
%YAML 1.2
---
version: 1.1
@ -20,4 +19,3 @@ var1:
default:
- no
- yes
...

View file

@ -1,4 +1,3 @@
%YAML 1.2
---
version: 1.1
@ -7,4 +6,3 @@ var1:
default:
- non
unique: false
...

View file

@ -1,4 +1,3 @@
%YAML 1.2
---
version: 1.1
@ -7,4 +6,3 @@ variable:
default:
- non
unique: true
...

Some files were not shown because too many files have changed in this diff Show more