From 4b21b1507fdc5ffbcc65c02d1d43399c9595d4a1 Mon Sep 17 00:00:00 2001 From: Emmanuel Garette Date: Wed, 14 Oct 2020 18:17:31 +0200 Subject: [PATCH] can add personal function --- src/rougail/annotator.py | 11 +++++----- src/rougail/tiramisureflector.py | 9 +++++--- tests/dictionaries/40empty_param/00_base.xml | 21 +++++++++++++++++++ tests/dictionaries/40empty_param/__init__.py | 0 .../40empty_param/makedict/base.json | 2 ++ .../40empty_param/tiramisu/base.py | 12 +++++++++++ tests/dictionaries/40empty_param2/00_base.xml | 21 +++++++++++++++++++ tests/dictionaries/40empty_param2/__init__.py | 0 .../40empty_param2/makedict/base.json | 2 ++ .../40empty_param2/tiramisu/base.py | 12 +++++++++++ .../80empty_param_number/00_base.xml | 21 +++++++++++++++++++ .../80empty_param_number/__init__.py | 0 12 files changed, 102 insertions(+), 9 deletions(-) create mode 100644 tests/dictionaries/40empty_param/00_base.xml create mode 100644 tests/dictionaries/40empty_param/__init__.py create mode 100644 tests/dictionaries/40empty_param/makedict/base.json create mode 100644 tests/dictionaries/40empty_param/tiramisu/base.py create mode 100644 tests/dictionaries/40empty_param2/00_base.xml create mode 100644 tests/dictionaries/40empty_param2/__init__.py create mode 100644 tests/dictionaries/40empty_param2/makedict/base.json create mode 100644 tests/dictionaries/40empty_param2/tiramisu/base.py create mode 100644 tests/dictionaries/80empty_param_number/00_base.xml create mode 100644 tests/dictionaries/80empty_param_number/__init__.py diff --git a/src/rougail/annotator.py b/src/rougail/annotator.py index 9a178ed7..c6d8d7fc 100644 --- a/src/rougail/annotator.py +++ b/src/rougail/annotator.py @@ -596,7 +596,9 @@ class ConstraintAnnotator: if not hasattr(objectspace.space, 'constraints'): return self.objectspace = objectspace - self.eosfunc = imp.load_source('eosfunc', eosfunc_file) + eosfunc = imp.load_source('eosfunc', eosfunc_file) + self.functions = dir(eosfunc) + self.functions.extend(INTERNAL_FUNCTIONS) self.valid_enums = {} if hasattr(self.objectspace.space.constraints, 'check'): self.check_check() @@ -618,10 +620,8 @@ class ConstraintAnnotator: def check_check(self): remove_indexes = [] - functions = dir(self.eosfunc) - functions.extend(INTERNAL_FUNCTIONS) for check_idx, check in enumerate(self.objectspace.space.constraints.check): - if not check.name in functions: + if not check.name in self.functions: raise DictConsistencyError(_('cannot find check function {}').format(check.name)) if hasattr(check, 'param'): param_option_indexes = [] @@ -1008,7 +1008,6 @@ class ConstraintAnnotator: indexes = list(fills.keys()) indexes.sort() targets = [] - eosfunc = dir(self.eosfunc) for idx in indexes: fill = fills[idx] # test if it's redefined calculation @@ -1016,7 +1015,7 @@ class ConstraintAnnotator: raise DictConsistencyError(_(f"A fill already exists for the target: {fill.target}")) targets.append(fill.target) # - if fill.name not in eosfunc: + if fill.name not in self.functions: raise DictConsistencyError(_('cannot find fill function {}').format(fill.name)) namespace = fill.namespace diff --git a/src/rougail/tiramisureflector.py b/src/rougail/tiramisureflector.py index 2e12eff6..30754662 100644 --- a/src/rougail/tiramisureflector.py +++ b/src/rougail/tiramisureflector.py @@ -44,13 +44,16 @@ class TiramisuReflector: funcs_path, ): self.storage = ElementStorage() - self.storage.text = ["try:", + self.storage.text = ["import imp", + f"func = imp.load_source('func', '{funcs_path}')", + "for key, value in dict(locals()).items():", + " if key != ['imp', 'func']:", + " setattr(func, key, value)", + "try:", " from tiramisu3 import *", "except:", " from tiramisu import *", "from rougail.tiramisu import ConvertDynOptionDescription", - "import imp", - f"func = imp.load_source('func', '{funcs_path}')", ] self.make_tiramisu_objects(xmlroot) # parse object diff --git a/tests/dictionaries/40empty_param/00_base.xml b/tests/dictionaries/40empty_param/00_base.xml new file mode 100644 index 00000000..00a7a201 --- /dev/null +++ b/tests/dictionaries/40empty_param/00_base.xml @@ -0,0 +1,21 @@ + + + + + + + + + + 3127 + + + + + + + + + + + diff --git a/tests/dictionaries/40empty_param/__init__.py b/tests/dictionaries/40empty_param/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/tests/dictionaries/40empty_param/makedict/base.json b/tests/dictionaries/40empty_param/makedict/base.json new file mode 100644 index 00000000..e5019d07 --- /dev/null +++ b/tests/dictionaries/40empty_param/makedict/base.json @@ -0,0 +1,2 @@ +{"rougail.proxy_authentifie.toto1": null, "rougail.proxy_authentifie.toto2": "3127"} + diff --git a/tests/dictionaries/40empty_param/tiramisu/base.py b/tests/dictionaries/40empty_param/tiramisu/base.py new file mode 100644 index 00000000..ed9678cd --- /dev/null +++ b/tests/dictionaries/40empty_param/tiramisu/base.py @@ -0,0 +1,12 @@ +try: + from tiramisu3 import * +except: + from tiramisu import * +from rougail.tiramisu import ConvertDynOptionDescription +import imp +func = imp.load_source('func', 'tests/dictionaries/../eosfunc/test.py') +option_3 = PortOption(allow_private=True, properties=frozenset({'expert'}), name='toto1', doc='Port d\'écoute du proxy', multi=False, default=Calculation(func.calc_multi_condition, Params((ParamValue("None")), kwargs={}))) +option_4 = PortOption(allow_private=True, properties=frozenset({'expert', 'mandatory'}), name='toto2', doc='Port d\'écoute du proxy NTLM', multi=False, default='3127') +option_2 = OptionDescription(name='proxy_authentifie', doc='proxy authentifié', properties=frozenset({'expert'}), children=[option_3, option_4]) +option_1 = OptionDescription(name='rougail', doc='rougail', children=[option_2]) +option_0 = OptionDescription(name='baseoption', doc='baseoption', children=[option_1]) diff --git a/tests/dictionaries/40empty_param2/00_base.xml b/tests/dictionaries/40empty_param2/00_base.xml new file mode 100644 index 00000000..9c0fa4f0 --- /dev/null +++ b/tests/dictionaries/40empty_param2/00_base.xml @@ -0,0 +1,21 @@ + + + + + + + + + + 3127 + + + + + + + + + + + diff --git a/tests/dictionaries/40empty_param2/__init__.py b/tests/dictionaries/40empty_param2/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/tests/dictionaries/40empty_param2/makedict/base.json b/tests/dictionaries/40empty_param2/makedict/base.json new file mode 100644 index 00000000..e5019d07 --- /dev/null +++ b/tests/dictionaries/40empty_param2/makedict/base.json @@ -0,0 +1,2 @@ +{"rougail.proxy_authentifie.toto1": null, "rougail.proxy_authentifie.toto2": "3127"} + diff --git a/tests/dictionaries/40empty_param2/tiramisu/base.py b/tests/dictionaries/40empty_param2/tiramisu/base.py new file mode 100644 index 00000000..7c34985e --- /dev/null +++ b/tests/dictionaries/40empty_param2/tiramisu/base.py @@ -0,0 +1,12 @@ +try: + from tiramisu3 import * +except: + from tiramisu import * +from rougail.tiramisu import ConvertDynOptionDescription +import imp +func = imp.load_source('func', 'tests/dictionaries/../eosfunc/test.py') +option_3 = PortOption(allow_private=True, properties=frozenset({'expert'}), name='toto1', doc='Port d\'écoute du proxy', multi=False, default=Calculation(func.calc_multi_condition, Params((), kwargs={'value': ParamValue("None")}))) +option_4 = PortOption(allow_private=True, properties=frozenset({'expert', 'mandatory'}), name='toto2', doc='Port d\'écoute du proxy NTLM', multi=False, default='3127') +option_2 = OptionDescription(name='proxy_authentifie', doc='proxy authentifié', properties=frozenset({'expert'}), children=[option_3, option_4]) +option_1 = OptionDescription(name='rougail', doc='rougail', children=[option_2]) +option_0 = OptionDescription(name='baseoption', doc='baseoption', children=[option_1]) diff --git a/tests/dictionaries/80empty_param_number/00_base.xml b/tests/dictionaries/80empty_param_number/00_base.xml new file mode 100644 index 00000000..f2a2228d --- /dev/null +++ b/tests/dictionaries/80empty_param_number/00_base.xml @@ -0,0 +1,21 @@ + + + + + + + + + + 3127 + + + + + + + + + + + diff --git a/tests/dictionaries/80empty_param_number/__init__.py b/tests/dictionaries/80empty_param_number/__init__.py new file mode 100644 index 00000000..e69de29b