feat: add Namespace(Param|Calculation) support

This commit is contained in:
egarette@silique.fr 2025-03-26 19:32:30 +01:00
parent 99a41bd4e5
commit 75fc04c501
15 changed files with 150 additions and 26 deletions

View file

@ -31,7 +31,7 @@ from tiramisu import undefined
from tiramisu.config import get_common_path
from rougail.convert import RougailConvert
from rougail.object_model import Variable, Family, Calculation, JinjaCalculation, IdentifierCalculation, IdentifierPropertyCalculation, IdentifierParam, IndexCalculation, IndexParam, Param
from rougail.object_model import Variable, Family, Calculation, JinjaCalculation, IdentifierCalculation, IdentifierPropertyCalculation, NamespaceCalculation, IdentifierParam, IndexCalculation, IndexParam, NamespaceParam, Param
from rougail.utils import normalize_family
from .upgrade import RougailUpgrade
@ -314,8 +314,10 @@ class RougailOutputFormatter:
variable = CommentedMap()
if isinstance(value, (IdentifierCalculation, IdentifierPropertyCalculation)):
variable["type"] = "identifier"
if isinstance(value, IndexCalculation):
elif isinstance(value, IndexCalculation):
variable["type"] = "index"
elif isinstance(value, NamespaceCalculation):
variable["type"] = "namespace"
for key, default in variable_attributes.items():
val = getattr(value, key)
if val != default and val is not undefined:
@ -333,8 +335,10 @@ class RougailOutputFormatter:
variable = CommentedMap()
if isinstance(value, IdentifierParam):
variable["type"] = "identifier"
if isinstance(value, IndexParam):
elif isinstance(value, IndexParam):
variable["type"] = "index"
elif isinstance(value, NamespaceParam):
variable["type"] = "namespace"
for key, default in param_attributes.items():
val = getattr(value, key)
if val != default and val is not undefined:

View file

@ -0,0 +1,8 @@
---
version: 1.1
variable:
description: a variable
default:
type: namespace
mandatory: false

View file

@ -0,0 +1,12 @@
---
version: 1.1
variable:
description: a variable
default:
jinja: >-
{{ namespace }}
params:
namespace:
type: namespace
mandatory: false

View file

@ -0,0 +1,10 @@
---
version: 1.1
condition: [] # a condition
variable:
description: a variable
multi: true
disabled:
variable: _.condition

View file

@ -0,0 +1,12 @@
---
version: 1.1
condition: # a condition
- val1
- val2
variable:
description: a variable
multi: true
disabled:
variable: _.condition

View file

@ -5,10 +5,8 @@ leader:
description: a leadership
type: leadership
leader:
description: the leader
multi: true
leader: [] # the leader
follower1: # the follower1
follower1: # the follower1
follower2: # the follower2

View file

@ -5,13 +5,9 @@ leadership:
description: A leadership
type: leadership
leader:
description: The leader
multi: true
leader: [] # The leader
follower1:
description: The first follower
multi: true
follower1: [] # The first follower
follower2: # The second follower
follower2: # The second follower
- value

View file

@ -5,9 +5,7 @@ leader:
description: a leadership
type: leadership
leader:
description: a leader
multi: true
leader: [] # a leader
follower1:
description: a follower

View file

@ -7,9 +7,7 @@ leader:
description: a leadership
type: leadership
leader:
description: a leader
multi: true
leader: [] # a leader
follower:
description: a follower

View file

@ -0,0 +1,25 @@
---
version: 1.1
var: # A suffix variable
- val.1
- val.2
dyn{{ identifier }}:
description: A dynamic family
dynamic:
variable: _.var
var1:
description: A dynamic variable
default:
type: identifier
var2:
description: A dynamic variable
default:
jinja: >-
{{ identifier }}
params:
identifier:
type: identifier

View file

@ -0,0 +1,21 @@
---
version: 1.1
var1:
description: A suffix variable
test:
- val1
multi: true
mandatory: false
dyn{{ identifier }}:
dynamic:
variable: _.var1
var: # A dynamic variable
var2:
description: A variable calculated
default:
variable: _.dynval1.var
optional: true

View file

@ -0,0 +1,22 @@
---
version: 1.1
var2:
description: A variable calculated
default:
variable: _.dynval1.var
optional: true
var1:
description: A suffix variable
test:
- val1
- val2
multi: true
mandatory: false
dyn{{ identifier }}:
dynamic:
variable: _.var1
var: # A dynamic variable

View file

@ -0,0 +1,24 @@
---
version: 1.1
var: # a suffix variable
- val1
- val2
my_dyn_family_{{ identifier }}:
description: a dynamic family
dynamic:
variable: _.var
propertyerror: false
var:
description: a variable inside a dynamic family
default:
type: identifier
mandatory: false
var2:
description: a variable
multi: true
default:
variable: _.my_dyn_family_{{ identifier }}.var

View file

@ -14,9 +14,7 @@ dyn{{ identifier }}:
description: a leadership
type: leadership
leader:
description: a leader
multi: true
leader: [] # a leader
follower1:
description: a follower1

View file

@ -18,9 +18,7 @@ dyn{{ identifier }}:
description: a leadership
type: leadership
leader:
description: a leader
multi: true
leader: [] # a leader
follower1:
description: a follower1