From 4da9a502658c3192695eaccb42a870a76f75474c Mon Sep 17 00:00:00 2001 From: Emmanuel Garette Date: Fri, 25 Oct 2024 08:12:08 +0200 Subject: [PATCH] fix: valid mode even if there is no mode configured --- src/rougail/annotator/variable.py | 31 ++++++++++++++----- .../dictionaries/rougail/00-base.yml | 1 + .../dictionaries/rougail/00-base.yml | 1 + .../dictionaries/rougail/01-redefine.yml | 1 + .../dictionaries/rougail/00-base.yml | 9 ++++-- .../dictionaries/rougail/00-base.yml | 5 +++ .../dictionaries/rougail/00-base.yml | 8 +++-- .../dictionaries/rougail/00-base.yml | 5 ++- .../dictionaries/rougail/00-base.yml | 9 ++++-- .../dictionaries/rougail/01-base.yml | 4 ++- .../dictionaries/rougail/00-base.yml | 4 ++- 11 files changed, 61 insertions(+), 17 deletions(-) diff --git a/src/rougail/annotator/variable.py b/src/rougail/annotator/variable.py index 1f622026c..8bedda6d6 100644 --- a/src/rougail/annotator/variable.py +++ b/src/rougail/annotator/variable.py @@ -75,11 +75,11 @@ class Annotator(Walk): # pylint: disable=R0903 self.forbidden_name = [] # default type inference from a default value with :term:`basic types` self.basic_types = {str: "string", int: "number", bool: "boolean", float: "float"} + self.verify_choices() self.convert_variable() self.convert_test() self.convert_examples() self.convert_help() - self.verify_choices() def convert_variable(self): """convert variable""" @@ -135,7 +135,7 @@ class Annotator(Walk): # pylint: disable=R0903 return # copy type and params calculated_variable_path = variable.default.variable - calculated_variable, suffix = self.objectspace.paths.get_with_dynamic( + calculated_variable, identifier = self.objectspace.paths.get_with_dynamic( calculated_variable_path, variable.default.path_prefix, variable.path, variable.version, variable.namespace, variable.xmlfiles ) if calculated_variable is None: @@ -171,15 +171,20 @@ class Annotator(Walk): # pylint: disable=R0903 family = self.objectspace.paths[variable.path.rsplit(".", 1)[0]] if variable.hidden: family.hidden = variable.hidden - elif family.hidden: - variable.hidden = family.hidden +# elif family.hidden: +# variable.hidden = family.hidden variable.hidden = None - if variable.choices is not None and variable.type != 'choice': - msg = _(f'the variable "{variable.path}" has choices attribut but has not the "choice" type') - raise DictConsistencyError(msg, 11, variable.xmlfiles) if variable.regexp is not None and variable.type != 'regexp': msg = _(f'the variable "{variable.path}" has regexp attribut but has not the "regexp" type') raise DictConsistencyError(msg, 37, variable.xmlfiles) + if variable.mandatory is None: + family_path = variable.path + hidden = variable.hidden is True + while '.' in family_path and not hidden: + family_path = family_path.rsplit(".", 1)[0] + family = self.objectspace.paths[family_path] + hidden = family.hidden is True + variable.mandatory = not hidden def convert_test(self): """Convert variable tests value""" @@ -213,8 +218,18 @@ class Annotator(Walk): # pylint: disable=R0903 def verify_choices(self): for variable in self.get_variables(): - if variable.type != 'choice' or variable.default is None: + if variable.type is None and variable.choices: + # choice type inference from the `choices` attribute + variable.type = "choice" + if variable.choices is not None and variable.type != 'choice': + msg = _(f'the variable "{variable.path}" has choices attribut but has not the "choice" type') + raise DictConsistencyError(msg, 11, variable.xmlfiles) + if variable.type != 'choice': continue + if variable.default is None: + continue + if None in variable.choices and variable.mandatory is None: + variable.mandatory = False if not isinstance(variable.choices, list): continue choices = variable.choices diff --git a/tests/dictionaries/04_1auto_save_and_hidden/dictionaries/rougail/00-base.yml b/tests/dictionaries/04_1auto_save_and_hidden/dictionaries/rougail/00-base.yml index 8790271ab..94cde787b 100644 --- a/tests/dictionaries/04_1auto_save_and_hidden/dictionaries/rougail/00-base.yml +++ b/tests/dictionaries/04_1auto_save_and_hidden/dictionaries/rougail/00-base.yml @@ -5,3 +5,4 @@ var: auto_save: true hidden: true default: 'yes' + mandatory: false diff --git a/tests/dictionaries/16_5exists_redefine/dictionaries/rougail/00-base.yml b/tests/dictionaries/16_5exists_redefine/dictionaries/rougail/00-base.yml index 7e1cc9135..5ba66f478 100644 --- a/tests/dictionaries/16_5exists_redefine/dictionaries/rougail/00-base.yml +++ b/tests/dictionaries/16_5exists_redefine/dictionaries/rougail/00-base.yml @@ -4,3 +4,4 @@ var1: description: a first variable hidden: true default: "no" + mandatory: false diff --git a/tests/dictionaries/16_5redefine_hidden/dictionaries/rougail/01-redefine.yml b/tests/dictionaries/16_5redefine_hidden/dictionaries/rougail/01-redefine.yml index 9327a590a..07a25984c 100644 --- a/tests/dictionaries/16_5redefine_hidden/dictionaries/rougail/01-redefine.yml +++ b/tests/dictionaries/16_5redefine_hidden/dictionaries/rougail/01-redefine.yml @@ -3,3 +3,4 @@ version: '1.1' variable: redefine: true hidden: true + mandatory: false diff --git a/tests/dictionaries/17_5redefine_leadership/dictionaries/rougail/00-base.yml b/tests/dictionaries/17_5redefine_leadership/dictionaries/rougail/00-base.yml index 09503b4de..147302435 100644 --- a/tests/dictionaries/17_5redefine_leadership/dictionaries/rougail/00-base.yml +++ b/tests/dictionaries/17_5redefine_leadership/dictionaries/rougail/00-base.yml @@ -2,5 +2,10 @@ version: '1.1' leader: # a leadership type: leadership - leader: [] # a leader - follower: # a follower + leader: + description: a leader + multi: true + mandatory: false + follower: + description: a follower + mandatory: false diff --git a/tests/dictionaries/20_0family_underscore/dictionaries/rougail/00-base.yml b/tests/dictionaries/20_0family_underscore/dictionaries/rougail/00-base.yml index f223fff68..032906fc2 100644 --- a/tests/dictionaries/20_0family_underscore/dictionaries/rougail/00-base.yml +++ b/tests/dictionaries/20_0family_underscore/dictionaries/rougail/00-base.yml @@ -11,13 +11,16 @@ my_family: description: a type family type: family my_variable: + mandatory: false description: description: This is a other great family my_variable: + mandatory: false help: description: a help family help: This is a other great family my_variable: + mandatory: false mode: description: a mode family mode: advanced @@ -27,7 +30,9 @@ my_family: description: an hidden family hidden: true my_variable: + mandatory: false disabled: description: an disabled family disabled: true my_variable: + mandatory: false diff --git a/tests/dictionaries/44_0leadership_hidden/dictionaries/rougail/00-base.yml b/tests/dictionaries/44_0leadership_hidden/dictionaries/rougail/00-base.yml index 3eb68fd9c..f870bca4d 100644 --- a/tests/dictionaries/44_0leadership_hidden/dictionaries/rougail/00-base.yml +++ b/tests/dictionaries/44_0leadership_hidden/dictionaries/rougail/00-base.yml @@ -6,6 +6,10 @@ leader: hidden: true type: leadership - leader: # a leader + leader: + description: a leader + mandatory: false - follower: # a follower + follower: + description: a follower + mandatory: false diff --git a/tests/dictionaries/44_0leadership_leader_hidden/dictionaries/rougail/00-base.yml b/tests/dictionaries/44_0leadership_leader_hidden/dictionaries/rougail/00-base.yml index 63fe6da1a..fe0e282d4 100644 --- a/tests/dictionaries/44_0leadership_leader_hidden/dictionaries/rougail/00-base.yml +++ b/tests/dictionaries/44_0leadership_leader_hidden/dictionaries/rougail/00-base.yml @@ -8,5 +8,8 @@ leader: description: a leader multi: true hidden: true + mandatory: false - follower: # a follower + follower: + description: a follower + mandatory: false diff --git a/tests/dictionaries/44_1leadership_append_hidden_follower/dictionaries/rougail/00-base.yml b/tests/dictionaries/44_1leadership_append_hidden_follower/dictionaries/rougail/00-base.yml index b8d035cf9..061771727 100644 --- a/tests/dictionaries/44_1leadership_append_hidden_follower/dictionaries/rougail/00-base.yml +++ b/tests/dictionaries/44_1leadership_append_hidden_follower/dictionaries/rougail/00-base.yml @@ -7,5 +7,10 @@ leader: description: a leader multi: true hidden: true - follower1: # the follower1 - follower2: # the follower2 + mandatory: false + follower1: + description: the follower1 + mandatory: false + follower2: + description: the follower2 + mandatory: false diff --git a/tests/dictionaries/44_1leadership_append_hidden_follower/dictionaries/rougail/01-base.yml b/tests/dictionaries/44_1leadership_append_hidden_follower/dictionaries/rougail/01-base.yml index 396a466f5..b9bdef37f 100644 --- a/tests/dictionaries/44_1leadership_append_hidden_follower/dictionaries/rougail/01-base.yml +++ b/tests/dictionaries/44_1leadership_append_hidden_follower/dictionaries/rougail/01-base.yml @@ -1,4 +1,6 @@ --- version: '1.1' leader: - follower3: # follower3 + follower3: + description: follower3 + mandatory: false diff --git a/tests/dictionaries/60_0family_hidden/dictionaries/rougail/00-base.yml b/tests/dictionaries/60_0family_hidden/dictionaries/rougail/00-base.yml index 1112c77b3..791f8bf2c 100644 --- a/tests/dictionaries/60_0family_hidden/dictionaries/rougail/00-base.yml +++ b/tests/dictionaries/60_0family_hidden/dictionaries/rougail/00-base.yml @@ -1,4 +1,6 @@ --- version: '1.1' family: # a family - var: # a variable + var: + description: a variable + mandatory: false