From a91a4d6a55303b5ebb0598f2845bd54e8917021a Mon Sep 17 00:00:00 2001 From: Emmanuel Garette Date: Wed, 11 Dec 2024 20:50:15 +0100 Subject: [PATCH] feat: output could have annotator --- src/rougail/annotator/__init__.py | 7 ++ .../makedict/after.json | 17 +++++ .../makedict/base.json | 8 +++ .../makedict/before.json | 17 +++++ .../makedict/mandatory.json | 1 + .../tiramisu/base.py | 22 +++++++ .../tiramisu/multi.py | 33 ++++++++++ tests/test_doc.py | 64 ------------------- 8 files changed, 105 insertions(+), 64 deletions(-) create mode 100644 tests/dictionaries/60_6family_dynamic_sub_dynamic_empty2/makedict/after.json create mode 100644 tests/dictionaries/60_6family_dynamic_sub_dynamic_empty2/makedict/base.json create mode 100644 tests/dictionaries/60_6family_dynamic_sub_dynamic_empty2/makedict/before.json create mode 100644 tests/dictionaries/60_6family_dynamic_sub_dynamic_empty2/makedict/mandatory.json create mode 100644 tests/dictionaries/60_6family_dynamic_sub_dynamic_empty2/tiramisu/base.py create mode 100644 tests/dictionaries/60_6family_dynamic_sub_dynamic_empty2/tiramisu/multi.py delete mode 100644 tests/test_doc.py diff --git a/src/rougail/annotator/__init__.py b/src/rougail/annotator/__init__.py index dedf276f7..ef00879b3 100644 --- a/src/rougail/annotator/__init__.py +++ b/src/rougail/annotator/__init__.py @@ -71,6 +71,11 @@ class SpaceAnnotator: # pylint: disable=R0903 if extra_annotator in ANNOTATORS: continue get_annotators(ANNOTATORS, extra_annotator) + if objectspace.output: + try: + get_annotators(ANNOTATORS, f"rougail.output_{objectspace.output}", "annotator") + except ModuleNotFoundError: + pass for user_data in objectspace.user_datas: try: get_annotators(ANNOTATORS, f"rougail.user_data_{user_data}", "annotator") @@ -88,6 +93,8 @@ class SpaceAnnotator: # pylint: disable=R0903 annotators.extend(ANNOTATORS[f"rougail.{plugin}.annotator"]) for user_data in objectspace.user_datas: annotators.extend(ANNOTATORS[f"rougail.user_data_{user_data}.annotator"]) + if objectspace.output: + annotators.extend(ANNOTATORS[f"rougail.output_{objectspace.output}.annotator"]) annotators = sorted(annotators, key=get_level) functions = {} functions_files = objectspace.functions_files diff --git a/tests/dictionaries/60_6family_dynamic_sub_dynamic_empty2/makedict/after.json b/tests/dictionaries/60_6family_dynamic_sub_dynamic_empty2/makedict/after.json new file mode 100644 index 000000000..32c236a8c --- /dev/null +++ b/tests/dictionaries/60_6family_dynamic_sub_dynamic_empty2/makedict/after.json @@ -0,0 +1,17 @@ +{ + "rougail.var": { + "owner": "default", + "value": [ + "val1", + "val2" + ] + }, + "rougail.dynval1.var": { + "owner": "default", + "value": [] + }, + "rougail.dynval2.var": { + "owner": "default", + "value": [] + } +} diff --git a/tests/dictionaries/60_6family_dynamic_sub_dynamic_empty2/makedict/base.json b/tests/dictionaries/60_6family_dynamic_sub_dynamic_empty2/makedict/base.json new file mode 100644 index 000000000..95f96c820 --- /dev/null +++ b/tests/dictionaries/60_6family_dynamic_sub_dynamic_empty2/makedict/base.json @@ -0,0 +1,8 @@ +{ + "rougail.var": [ + "val1", + "val2" + ], + "rougail.dynval1.var": [], + "rougail.dynval2.var": [] +} diff --git a/tests/dictionaries/60_6family_dynamic_sub_dynamic_empty2/makedict/before.json b/tests/dictionaries/60_6family_dynamic_sub_dynamic_empty2/makedict/before.json new file mode 100644 index 000000000..32c236a8c --- /dev/null +++ b/tests/dictionaries/60_6family_dynamic_sub_dynamic_empty2/makedict/before.json @@ -0,0 +1,17 @@ +{ + "rougail.var": { + "owner": "default", + "value": [ + "val1", + "val2" + ] + }, + "rougail.dynval1.var": { + "owner": "default", + "value": [] + }, + "rougail.dynval2.var": { + "owner": "default", + "value": [] + } +} diff --git a/tests/dictionaries/60_6family_dynamic_sub_dynamic_empty2/makedict/mandatory.json b/tests/dictionaries/60_6family_dynamic_sub_dynamic_empty2/makedict/mandatory.json new file mode 100644 index 000000000..0637a088a --- /dev/null +++ b/tests/dictionaries/60_6family_dynamic_sub_dynamic_empty2/makedict/mandatory.json @@ -0,0 +1 @@ +[] \ No newline at end of file diff --git a/tests/dictionaries/60_6family_dynamic_sub_dynamic_empty2/tiramisu/base.py b/tests/dictionaries/60_6family_dynamic_sub_dynamic_empty2/tiramisu/base.py new file mode 100644 index 000000000..90cdb7ebf --- /dev/null +++ b/tests/dictionaries/60_6family_dynamic_sub_dynamic_empty2/tiramisu/base.py @@ -0,0 +1,22 @@ +from tiramisu import * +from tiramisu.setting import ALLOWED_LEADER_PROPERTIES +from re import compile as re_compile +from rougail.tiramisu import func, dict_env, load_functions, ConvertDynOptionDescription +load_functions('../rougail-tests/funcs/test.py') +try: + groups.namespace +except: + groups.addgroup('namespace') +ALLOWED_LEADER_PROPERTIES.add("basic") +ALLOWED_LEADER_PROPERTIES.add("standard") +ALLOWED_LEADER_PROPERTIES.add("advanced") +dict_env['default_rougail.dyn{{ identifier }}.dyn_{{ identifier }}.var_identifiers'] = "{{ s1 }}-{{ s2 }}\n" +option_2 = StrOption(name="var", doc="A identifier variable", multi=True, default=["val1", "val2"], default_multi="val1", properties=frozenset({"standard"}), informations={'type': 'string'}) +option_4 = StrOption(name="var", doc="A dynamic variable", multi=True, properties=frozenset({"standard"}), informations={'type': 'string'}) +option_6 = StrOption(name="var", doc="A variable dynamic", default=Calculation(func['calc_value'], Params((ParamIdentifier()))), properties=frozenset({"mandatory", "standard"}), informations={'type': 'string'}) +option_7 = StrOption(name="var_identifier", doc="identifier from first family", default=Calculation(func['calc_value'], Params((ParamIdentifier(identifier_index=0)))), properties=frozenset({"mandatory", "standard"}), informations={'type': 'string'}) +option_8 = StrOption(name="var_identifiers", doc="merge identifiers", default=Calculation(func['jinja_to_function'], Params((), kwargs={'__internal_jinja': ParamValue("default_rougail.dyn{{ identifier }}.dyn_{{ identifier }}.var_identifiers"), '__internal_type': ParamValue("string"), '__internal_multi': ParamValue(False), '__internal_files': ParamValue(['../rougail-tests/structures/60_6family_dynamic_sub_dynamic_empty2/rougail/00-base.yml']), '__internal_attribute': ParamValue("default"), '__internal_variable': ParamValue("rougail.dyn{{ identifier }}.dyn_{{ identifier }}.var_identifiers"), 's1': ParamIdentifier(identifier_index=0), 's2': ParamIdentifier(identifier_index=1)})), properties=frozenset({"mandatory", "standard"}), informations={'type': 'string'}) +optiondescription_5 = ConvertDynOptionDescription(name="dyn_{{ identifier }}", doc="a Second dynamic variable", identifiers=Calculation(func['calc_value'], Params((ParamOption(option_4)))), children=[option_6, option_7, option_8], properties=frozenset({"standard"}), informations={'dynamic_variable': 'rougail.dyn{{ identifier }}.var'}) +optiondescription_3 = ConvertDynOptionDescription(name="dyn{{ identifier }}", doc="A dynamic family", identifiers=Calculation(func['calc_value'], Params((ParamOption(option_2)))), children=[option_4, optiondescription_5], properties=frozenset({"standard"}), informations={'dynamic_variable': 'rougail.var'}) +optiondescription_1 = OptionDescription(name="rougail", doc="Rougail", group_type=groups.namespace, children=[option_2, optiondescription_3], properties=frozenset({"standard"})) +option_0 = OptionDescription(name="baseoption", doc="baseoption", children=[optiondescription_1]) diff --git a/tests/dictionaries/60_6family_dynamic_sub_dynamic_empty2/tiramisu/multi.py b/tests/dictionaries/60_6family_dynamic_sub_dynamic_empty2/tiramisu/multi.py new file mode 100644 index 000000000..1c260f27b --- /dev/null +++ b/tests/dictionaries/60_6family_dynamic_sub_dynamic_empty2/tiramisu/multi.py @@ -0,0 +1,33 @@ +from tiramisu import * +from tiramisu.setting import ALLOWED_LEADER_PROPERTIES +from re import compile as re_compile +from rougail.tiramisu import func, dict_env, load_functions, ConvertDynOptionDescription +load_functions('../rougail-tests/funcs/test.py') +try: + groups.namespace +except: + groups.addgroup('namespace') +ALLOWED_LEADER_PROPERTIES.add("basic") +ALLOWED_LEADER_PROPERTIES.add("standard") +ALLOWED_LEADER_PROPERTIES.add("advanced") +dict_env['default_1.rougail.dyn{{ identifier }}.dyn_{{ identifier }}.var_identifiers'] = "{{ s1 }}-{{ s2 }}\n" +dict_env['default_2.rougail.dyn{{ identifier }}.dyn_{{ identifier }}.var_identifiers'] = "{{ s1 }}-{{ s2 }}\n" +option_3 = StrOption(name="var", doc="A identifier variable", multi=True, default=["val1", "val2"], default_multi="val1", properties=frozenset({"standard"}), informations={'type': 'string'}) +option_5 = StrOption(name="var", doc="A dynamic variable", multi=True, properties=frozenset({"standard"}), informations={'type': 'string'}) +option_7 = StrOption(name="var", doc="A variable dynamic", default=Calculation(func['calc_value'], Params((ParamIdentifier()))), properties=frozenset({"mandatory", "standard"}), informations={'type': 'string'}) +option_8 = StrOption(name="var_identifier", doc="identifier from first family", default=Calculation(func['calc_value'], Params((ParamIdentifier(identifier_index=0)))), properties=frozenset({"mandatory", "standard"}), informations={'type': 'string'}) +option_9 = StrOption(name="var_identifiers", doc="merge identifiers", default=Calculation(func['jinja_to_function'], Params((), kwargs={'__internal_jinja': ParamValue("default_1.rougail.dyn{{ identifier }}.dyn_{{ identifier }}.var_identifiers"), '__internal_type': ParamValue("string"), '__internal_multi': ParamValue(False), '__internal_files': ParamValue(['../rougail-tests/structures/60_6family_dynamic_sub_dynamic_empty2/rougail/00-base.yml']), '__internal_attribute': ParamValue("default"), '__internal_variable': ParamValue("1.rougail.dyn{{ identifier }}.dyn_{{ identifier }}.var_identifiers"), 's1': ParamIdentifier(identifier_index=0), 's2': ParamIdentifier(identifier_index=1)})), properties=frozenset({"mandatory", "standard"}), informations={'type': 'string'}) +optiondescription_6 = ConvertDynOptionDescription(name="dyn_{{ identifier }}", doc="a Second dynamic variable", identifiers=Calculation(func['calc_value'], Params((ParamOption(option_5)))), children=[option_7, option_8, option_9], properties=frozenset({"standard"}), informations={'dynamic_variable': 'rougail.dyn{{ identifier }}.var'}) +optiondescription_4 = ConvertDynOptionDescription(name="dyn{{ identifier }}", doc="A dynamic family", identifiers=Calculation(func['calc_value'], Params((ParamOption(option_3)))), children=[option_5, optiondescription_6], properties=frozenset({"standard"}), informations={'dynamic_variable': '1.rougail.var'}) +optiondescription_2 = OptionDescription(name="rougail", doc="Rougail", group_type=groups.namespace, children=[option_3, optiondescription_4], properties=frozenset({"standard"})) +optiondescription_1 = OptionDescription(name="1", doc="1", children=[optiondescription_2], properties=frozenset({"standard"})) +option_12 = StrOption(name="var", doc="A identifier variable", multi=True, default=["val1", "val2"], default_multi="val1", properties=frozenset({"standard"}), informations={'type': 'string'}) +option_14 = StrOption(name="var", doc="A dynamic variable", multi=True, properties=frozenset({"standard"}), informations={'type': 'string'}) +option_16 = StrOption(name="var", doc="A variable dynamic", default=Calculation(func['calc_value'], Params((ParamIdentifier()))), properties=frozenset({"mandatory", "standard"}), informations={'type': 'string'}) +option_17 = StrOption(name="var_identifier", doc="identifier from first family", default=Calculation(func['calc_value'], Params((ParamIdentifier(identifier_index=0)))), properties=frozenset({"mandatory", "standard"}), informations={'type': 'string'}) +option_18 = StrOption(name="var_identifiers", doc="merge identifiers", default=Calculation(func['jinja_to_function'], Params((), kwargs={'__internal_jinja': ParamValue("default_2.rougail.dyn{{ identifier }}.dyn_{{ identifier }}.var_identifiers"), '__internal_type': ParamValue("string"), '__internal_multi': ParamValue(False), '__internal_files': ParamValue(['../rougail-tests/structures/60_6family_dynamic_sub_dynamic_empty2/rougail/00-base.yml']), '__internal_attribute': ParamValue("default"), '__internal_variable': ParamValue("2.rougail.dyn{{ identifier }}.dyn_{{ identifier }}.var_identifiers"), 's1': ParamIdentifier(identifier_index=0), 's2': ParamIdentifier(identifier_index=1)})), properties=frozenset({"mandatory", "standard"}), informations={'type': 'string'}) +optiondescription_15 = ConvertDynOptionDescription(name="dyn_{{ identifier }}", doc="a Second dynamic variable", identifiers=Calculation(func['calc_value'], Params((ParamOption(option_14)))), children=[option_16, option_17, option_18], properties=frozenset({"standard"}), informations={'dynamic_variable': 'rougail.dyn{{ identifier }}.var'}) +optiondescription_13 = ConvertDynOptionDescription(name="dyn{{ identifier }}", doc="A dynamic family", identifiers=Calculation(func['calc_value'], Params((ParamOption(option_12)))), children=[option_14, optiondescription_15], properties=frozenset({"standard"}), informations={'dynamic_variable': '2.rougail.var'}) +optiondescription_11 = OptionDescription(name="rougail", doc="Rougail", group_type=groups.namespace, children=[option_12, optiondescription_13], properties=frozenset({"standard"})) +optiondescription_10 = OptionDescription(name="2", doc="2", children=[optiondescription_11], properties=frozenset({"standard"})) +option_0 = OptionDescription(name="baseoption", doc="baseoption", children=[optiondescription_1, optiondescription_10]) diff --git a/tests/test_doc.py b/tests/test_doc.py deleted file mode 100644 index 1f955085e..000000000 --- a/tests/test_doc.py +++ /dev/null @@ -1,64 +0,0 @@ -from pathlib import Path -from pytest import fixture, raises -from shutil import rmtree -from rougail import Rougail, RougailConfig - -doc = Path('doc') -tests = Path('tests') -tmp = tests / 'tmp' -if tmp.is_dir(): - rmtree(tmp) -tmp.mkdir() -RougailConfig['main_dictionaries'] = [str(tmp)] -RougailConfig['functions_files'] = [str(tests / 'eosfunc' / 'test.py')] - - -scripts = {} -for filename in doc.glob('*/*.md'): - filename = str(filename) - with open(filename) as fh: - yaml = False - redefine = False - new_script = '' - for line in fh.readlines(): - if new_script and line == '```\n': - scripts.setdefault(filename, []) - if redefine: - scripts[filename][-1].append(new_script) - else: - scripts[filename].append([new_script]) - yaml = False - redefine = False - if yaml: - if line.strip() == 'redefine: true': - redefine = True - new_script += line - if line == '```yml\n': - yaml = True - new_script = '' -scripts_list = [(filename, script) for filename, scripts_ in scripts.items() for script in scripts_] - - -@fixture(scope="module", params=scripts_list) -def test_dir(request): - return request.param - - -def test_scripts(test_dir): - if tmp.is_dir(): - rmtree(tmp) - tmp.mkdir() - for idx, content in enumerate(test_dir[1]): - if not content.startswith('---'): - raise Exception(f'not a valid template in {test_dir[0]}') - filename = tmp / f'0{idx}-base.yml' - with open(filename, 'w') as fh: - fh.write(content) - rougail = Rougail() - try: - config = rougail.get_config() - config.value.dict() - except Exception as err: - #rmtree(tmp) - raise Exception(f'error in {test_dir[0]}: {err}') from err - rmtree(tmp)