WIP: Expand the developer documentation #27

Draft
gremond wants to merge 51 commits from develop into developer_docs
11 changed files with 61 additions and 17 deletions
Showing only changes of commit 4da9a50265 - Show all commits

View file

@ -75,11 +75,11 @@ class Annotator(Walk): # pylint: disable=R0903
self.forbidden_name = [] self.forbidden_name = []
# default type inference from a default value with :term:`basic types` # default type inference from a default value with :term:`basic types`
self.basic_types = {str: "string", int: "number", bool: "boolean", float: "float"} self.basic_types = {str: "string", int: "number", bool: "boolean", float: "float"}
self.verify_choices()
self.convert_variable() self.convert_variable()
self.convert_test() self.convert_test()
self.convert_examples() self.convert_examples()
self.convert_help() self.convert_help()
self.verify_choices()
def convert_variable(self): def convert_variable(self):
"""convert variable""" """convert variable"""
@ -135,7 +135,7 @@ class Annotator(Walk): # pylint: disable=R0903
return return
# copy type and params # copy type and params
calculated_variable_path = variable.default.variable 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 calculated_variable_path, variable.default.path_prefix, variable.path, variable.version, variable.namespace, variable.xmlfiles
) )
if calculated_variable is None: if calculated_variable is None:
@ -171,15 +171,20 @@ class Annotator(Walk): # pylint: disable=R0903
family = self.objectspace.paths[variable.path.rsplit(".", 1)[0]] family = self.objectspace.paths[variable.path.rsplit(".", 1)[0]]
if variable.hidden: if variable.hidden:
family.hidden = variable.hidden family.hidden = variable.hidden
elif family.hidden: # elif family.hidden:
variable.hidden = family.hidden # variable.hidden = family.hidden
variable.hidden = None 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': 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') msg = _(f'the variable "{variable.path}" has regexp attribut but has not the "regexp" type')
raise DictConsistencyError(msg, 37, variable.xmlfiles) 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): def convert_test(self):
"""Convert variable tests value""" """Convert variable tests value"""
@ -213,8 +218,18 @@ class Annotator(Walk): # pylint: disable=R0903
def verify_choices(self): def verify_choices(self):
for variable in self.get_variables(): 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 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): if not isinstance(variable.choices, list):
continue continue
choices = variable.choices choices = variable.choices

View file

@ -5,3 +5,4 @@ var:
auto_save: true auto_save: true
hidden: true hidden: true
default: 'yes' default: 'yes'
mandatory: false

View file

@ -4,3 +4,4 @@ var1:
description: a first variable description: a first variable
hidden: true hidden: true
default: "no" default: "no"
mandatory: false

View file

@ -3,3 +3,4 @@ version: '1.1'
variable: variable:
redefine: true redefine: true
hidden: true hidden: true
mandatory: false

View file

@ -2,5 +2,10 @@
version: '1.1' version: '1.1'
leader: # a leadership leader: # a leadership
type: leadership type: leadership
leader: [] # a leader leader:
follower: # a follower description: a leader
multi: true
mandatory: false
follower:
description: a follower
mandatory: false

View file

@ -11,13 +11,16 @@ my_family:
description: a type family description: a type family
type: family type: family
my_variable: my_variable:
mandatory: false
description: description:
description: This is a other great family description: This is a other great family
my_variable: my_variable:
mandatory: false
help: help:
description: a help family description: a help family
help: This is a other great family help: This is a other great family
my_variable: my_variable:
mandatory: false
mode: mode:
description: a mode family description: a mode family
mode: advanced mode: advanced
@ -27,7 +30,9 @@ my_family:
description: an hidden family description: an hidden family
hidden: true hidden: true
my_variable: my_variable:
mandatory: false
disabled: disabled:
description: an disabled family description: an disabled family
disabled: true disabled: true
my_variable: my_variable:
mandatory: false

View file

@ -6,6 +6,10 @@ leader:
hidden: true hidden: true
type: leadership type: leadership
leader: # a leader leader:
description: a leader
mandatory: false
follower: # a follower follower:
description: a follower
mandatory: false

View file

@ -8,5 +8,8 @@ leader:
description: a leader description: a leader
multi: true multi: true
hidden: true hidden: true
mandatory: false
follower: # a follower follower:
description: a follower
mandatory: false

View file

@ -7,5 +7,10 @@ leader:
description: a leader description: a leader
multi: true multi: true
hidden: true hidden: true
follower1: # the follower1 mandatory: false
follower2: # the follower2 follower1:
description: the follower1
mandatory: false
follower2:
description: the follower2
mandatory: false

View file

@ -1,4 +1,6 @@
--- ---
version: '1.1' version: '1.1'
leader: leader:
follower3: # follower3 follower3:
description: follower3
mandatory: false

View file

@ -1,4 +1,6 @@
--- ---
version: '1.1' version: '1.1'
family: # a family family: # a family
var: # a variable var:
description: a variable
mandatory: false