WIP: Expand the developer documentation #27

Draft
gremond wants to merge 294 commits from develop into developer_docs
3 changed files with 70 additions and 47 deletions
Showing only changes of commit 8801765bfb - Show all commits

View file

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

View file

@ -206,48 +206,63 @@ class ParserVariable:
return return
root = Path(__file__).parent.parent root = Path(__file__).parent.parent
self.walker = None self.walker = None
self.variable = Variable if self.variable_objects is None:
self.family = Family self.variable = Variable
for structural_name in self.structurals: self.family = Family
structural = f"structural_{structural_name}" for structural_name in self.structurals:
module_path = root / structural / "__init__.py" structural = f"structural_{structural_name}"
if not module_path.is_file(): module_path = root / structural / "__init__.py"
continue if not module_path.is_file():
module = load_modules(f"rougail.{structural}", str(module_path)) continue
if "Variable" in module.__all__: module = load_modules(f"rougail.{structural}", str(module_path))
self.variable = type( if "Variable" in module.__all__:
self.variable.__name__ + "_" + structural, self.variable = type(
(self.variable, module.Variable), self.variable.__name__ + "_" + structural,
{}, (self.variable, module.Variable),
) {},
if "Family" in module.__all__: )
self.family = type( if "Family" in module.__all__:
self.family.__name__ + "_" + structural, self.family = type(
(self.family, module.Family), self.family.__name__ + "_" + structural,
{}, (self.family, module.Family),
) {},
if not self.walker and "Walker" in module.__all__: )
self.walker = module.Walker if not self.walker and "Walker" in module.__all__:
self.dynamic = type(Dynamic.__name__, (Dynamic, self.family), {}) self.walker = module.Walker
self.choices = type(Choices.__name__, (Choices, self.variable), {}) self.dynamic = type(Dynamic.__name__, (Dynamic, self.family), {})
self.regexp = type(Regexp.__name__, (Regexp, self.variable), {}) self.choices = type(Choices.__name__, (Choices, self.variable), {})
variable_types = self.convert_options.copy() self.regexp = type(Regexp.__name__, (Regexp, self.variable), {})
variable_types.remove("choice") variable_types = self.convert_options.copy()
variable_types.remove("regexp") variable_types.remove("choice")
variable_types.remove("symlink") variable_types.remove("regexp")
self.variable_objects = [ variable_types.remove("symlink")
self.get_variable_object(obj, is_variable=True) self.variable_objects = [
for obj in [ self.get_variable_object(obj, is_variable=True)
(self.variable, variable_types), for obj in [
SymLink, (self.variable, variable_types),
self.choices, SymLink,
self.regexp, self.choices,
self.regexp,
]
] ]
] self.family_objects = [
self.family_objects = [ self.get_variable_object(obj, is_variable=False)
self.get_variable_object(obj, is_variable=False) for obj in [self.dynamic, self.family]
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 self.is_init = True
def get_variable_object(self, obj, *, is_variable: bool) -> dict: def get_variable_object(self, obj, *, is_variable: bool) -> dict:
@ -599,12 +614,16 @@ class RougailConvert(ParserVariable):
*, *,
custom_variable_types: dict = {}, custom_variable_types: dict = {},
custom_family_types: dict = {}, custom_family_types: dict = {},
variable_objects = None,
family_objects = None,
) -> None: ) -> None:
self.annotator = False self.annotator = False
self.has_namespace = False self.has_namespace = False
self.custom_variable_types = custom_variable_types self.custom_variable_types = custom_variable_types
self.custom_family_types = custom_family_types self.custom_family_types = custom_family_types
self.loaded_custom_types = None self.loaded_custom_types = None
self.variable_objects = variable_objects
self.family_objects = family_objects
super().__init__(rougailconfig) super().__init__(rougailconfig)
def get_attributes_types( def get_attributes_types(

View file

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