fix: variable and family object are same has type object

This commit is contained in:
egarette@silique.fr 2026-09-02 22:16:34 +02:00
parent b3917cb862
commit 8801765bfb
3 changed files with 70 additions and 47 deletions

View file

@ -42,8 +42,11 @@ class Rougail(UserData):
load_from_tiramisu_cache
and Path(self.rougailconfig["tiramisu_cache"]).is_file()
)
types = rougail_type(self.rougailconfig)
if not self.load_from_tiramisu_cache:
if rougailconfig["types"]:
types = rougail_type(self.rougailconfig)
else:
types = {}
self.converted = RougailConvert(self.rougailconfig, **types)
self.config = None

View file

@ -206,6 +206,7 @@ class ParserVariable:
return
root = Path(__file__).parent.parent
self.walker = None
if self.variable_objects is None:
self.variable = Variable
self.family = Family
for structural_name in self.structurals:
@ -248,6 +249,20 @@ class ParserVariable:
self.get_variable_object(obj, is_variable=False)
for obj in [self.dynamic, self.family]
]
else:
self.variable = self.variable_objects[0]
self.choices = self.variable_objects[2]
self.regexp = self.variable_objects[3]
self.family = self.family_objects[-1]
self.dynamic = self.family_objects[0]
for structural_name in self.structurals:
structural = f"structural_{structural_name}"
module_path = root / structural / "__init__.py"
if not module_path.is_file():
continue
module = load_modules(f"rougail.{structural}", str(module_path))
if not self.walker and "Walker" in module.__all__:
self.walker = module.Walker
self.is_init = True
def get_variable_object(self, obj, *, is_variable: bool) -> dict:
@ -599,12 +614,16 @@ class RougailConvert(ParserVariable):
*,
custom_variable_types: dict = {},
custom_family_types: dict = {},
variable_objects = None,
family_objects = None,
) -> None:
self.annotator = False
self.has_namespace = False
self.custom_variable_types = custom_variable_types
self.custom_family_types = custom_family_types
self.loaded_custom_types = None
self.variable_objects = variable_objects
self.family_objects = family_objects
super().__init__(rougailconfig)
def get_attributes_types(

View file

@ -27,6 +27,7 @@ class TypeRougailConvert(StaticRougailConvert):
main_structural_directories: list[str],
secret_pattern: str,
default_structural_format_version: str,
structurals: list[str],
) -> None:
super().__init__(
False,
@ -38,23 +39,21 @@ class TypeRougailConvert(StaticRougailConvert):
)
self.default_structural_format_version = default_structural_format_version
self.secret_pattern = secret_pattern
self.structurals = structurals
self.loaded_custom_types = {}
def load_config(self) -> None:
super().load_config()
# self.add_extra_options = self.add_extra_options
self.sort_structural_files_all = False
self.structurals = ["directory"]
def rougail_type(rougailconfig):
types = rougailconfig["types"]
if not types:
return {"custom_variable_types": {}, "custom_family_types": {}}
convert = TypeRougailConvert(
types,
rougailconfig["types"],
rougailconfig["secret_manager.pattern"],
rougailconfig["default_structural_format_version"],
rougailconfig["step.structural"],
)
convert.init()
convert.parse_directories()
@ -79,6 +78,8 @@ def rougail_type(rougailconfig):
else:
custom_family_types[typ] = data
return {
"variable_objects": convert.variable_objects,
"family_objects": convert.family_objects,
"custom_variable_types": custom_variable_types,
"custom_family_types": custom_family_types,
}