add 'just_doc' option

This commit is contained in:
egarette@silique.fr 2023-01-07 16:08:48 +01:00
parent c05a695b81
commit 4765744953
8 changed files with 51 additions and 27 deletions

View file

@ -72,7 +72,7 @@ class Annotator(TargetAnnotator, ParamAnnotator):
""" """
remove_indexes = [] remove_indexes = []
for check_idx, check in enumerate(constraints.check): for check_idx, check in enumerate(constraints.check):
if not check.name in self.functions: if not check.name in self.functions and not self.objectspace.just_doc:
msg = _(f'cannot find check function "{check.name}"') msg = _(f'cannot find check function "{check.name}"')
raise DictConsistencyError(msg, 1, check.xmlfiles) raise DictConsistencyError(msg, 1, check.xmlfiles)
if hasattr(check, 'param') and check.param == []: if hasattr(check, 'param') and check.param == []:

View file

@ -38,6 +38,11 @@ from rougail.annotator.param import ParamAnnotator
from rougail.annotator.variable import Walk from rougail.annotator.variable import Walk
class FakeVariable:
def __getattr__(self, name):
return None
class Annotator(TargetAnnotator, ParamAnnotator, Walk): class Annotator(TargetAnnotator, ParamAnnotator, Walk):
"""Annotate condition """Annotate condition
""" """
@ -222,7 +227,7 @@ class Annotator(TargetAnnotator, ParamAnnotator, Walk):
listvars, listvars,
fills, fills,
) )
elif not target.optional: elif not target.optional and self.objectspace.just_doc is False:
msg = f'cannot found target "{target.type}" "{target.name}"' msg = f'cannot found target "{target.type}" "{target.name}"'
raise DictConsistencyError(_(msg), 2, target.xmlfiles) raise DictConsistencyError(_(msg), 2, target.xmlfiles)
remove_targets.append(target_idx) remove_targets.append(target_idx)
@ -323,6 +328,9 @@ class Annotator(TargetAnnotator, ParamAnnotator, Walk):
add_path_prefix=True, add_path_prefix=True,
) )
except DictConsistencyError as err: except DictConsistencyError as err:
if self.objectspace.just_doc:
condition.source = FakeVariable()
continue
if err.errno == 36: if err.errno == 36:
msg = _(f'the source "{condition.source}" in condition cannot be a dynamic ' msg = _(f'the source "{condition.source}" in condition cannot be a dynamic '
f'variable') f'variable')

View file

@ -76,7 +76,7 @@ class Annotator(TargetAnnotator, ParamAnnotator):
""" """
for fill in constraints.fill: for fill in constraints.fill:
# test if the function exists # test if the function exists
if fill.name not in self.functions: if not self.objectspace.just_doc and fill.name not in self.functions:
msg = _(f'cannot find fill function "{fill.name}"') msg = _(f'cannot find fill function "{fill.name}"')
raise DictConsistencyError(msg, 25, fill.xmlfiles) raise DictConsistencyError(msg, 25, fill.xmlfiles)
for target in fill.target: for target in fill.target:

View file

@ -90,7 +90,7 @@ class ParamAnnotator:
path_prefix, path_prefix,
) )
except DictConsistencyError as err: except DictConsistencyError as err:
if err.errno != 42 or not param.optional: if not self.objectspace.just_doc and (err.errno != 42 or not param.optional):
raise err raise err
param_to_delete.append(param_idx) param_to_delete.append(param_idx)
elif param.type == 'function': elif param.type == 'function':
@ -118,7 +118,7 @@ class ParamAnnotator:
raise DictConsistencyError(msg, 53, obj.xmlfiles) raise DictConsistencyError(msg, 53, obj.xmlfiles)
elif param.type == 'index': elif param.type == 'index':
for target in obj.target: for target in obj.target:
if not self.objectspace.paths.is_follower(target.name): if not self.objectspace.just_doc and not self.objectspace.paths.is_follower(target.name):
msg = _(f'"{param.type}" parameter cannot be set with target ' msg = _(f'"{param.type}" parameter cannot be set with target '
f'"{target.name.name}" which is not a follower variable') f'"{target.name.name}" which is not a follower variable')
raise DictConsistencyError(msg, 60, obj.xmlfiles) raise DictConsistencyError(msg, 60, obj.xmlfiles)

View file

@ -91,7 +91,7 @@ class TargetAnnotator(Walk):
if err.errno != 42: if err.errno != 42:
raise err raise err
# for optional variable # for optional variable
if not target.optional: if not target.optional and not self.objectspace.just_doc:
msg = f'cannot found target "{target.type}" "{target.name}"' msg = f'cannot found target "{target.type}" "{target.name}"'
raise DictConsistencyError(_(msg), 12, target.xmlfiles) from err raise DictConsistencyError(_(msg), 12, target.xmlfiles) from err
remove_targets.append(index) remove_targets.append(index)

View file

@ -63,6 +63,7 @@ class RougailConvert:
""" """
def __init__(self, def __init__(self,
rougailconfig: RougailConfig=None, rougailconfig: RougailConfig=None,
just_doc: bool=False,
) -> None: ) -> None:
if rougailconfig is None: if rougailconfig is None:
rougailconfig = RougailConfig rougailconfig = RougailConfig
@ -70,11 +71,9 @@ class RougailConvert:
xmlreflector = Reflector(self.rougailconfig) xmlreflector = Reflector(self.rougailconfig)
self.rougailobjspace = RougailObjSpace(xmlreflector, self.rougailobjspace = RougailObjSpace(xmlreflector,
self.rougailconfig, self.rougailconfig,
just_doc,
) )
self.internal_functions = self.rougailconfig['internal_functions'] self.internal_functions = self.rougailconfig['internal_functions']
self.functions_file = self.rougailconfig['functions_file']
if not isinstance(self.functions_file, list):
self.functions_file = [self.functions_file]
self.dictionaries = False self.dictionaries = False
self.annotator = False self.annotator = False
self.reflector = None self.reflector = None
@ -111,7 +110,7 @@ class RougailConvert:
path_prefix: str, path_prefix: str,
namespace_description: str=None, namespace_description: str=None,
) -> List[str]: ) -> List[str]:
for xmlfile, document in xmlreflector.load_dictionaries_from_folders(xmlfolders): for xmlfile, document in xmlreflector.load_dictionaries_from_folders(xmlfolders, self.rougailobjspace.just_doc):
self.rougailobjspace.xml_parse_document(xmlfile, self.rougailobjspace.xml_parse_document(xmlfile,
document, document,
namespace, namespace,
@ -122,9 +121,7 @@ class RougailConvert:
def annotate(self): def annotate(self):
if self.annotator: if self.annotator:
raise DictConsistencyError(_('Cannot execute annotate multiple time'), 85, None) raise DictConsistencyError(_('Cannot execute annotate multiple time'), 85, None)
SpaceAnnotator(self.rougailobjspace, SpaceAnnotator(self.rougailobjspace)
self.functions_file,
)
self.annotator = True self.annotator = True
def reflexion(self, def reflexion(self,
@ -136,7 +133,10 @@ class RougailConvert:
self.annotate() self.annotate()
if self.reflector: if self.reflector:
raise DictConsistencyError(_('Cannot execute reflexion multiple time'), 86, None) raise DictConsistencyError(_('Cannot execute reflexion multiple time'), 86, None)
functions_file = [func for func in self.functions_file if func not in exclude_imports] functions_file = self.rougailconfig['functions_file']
if not isinstance(functions_file, list):
functions_file = [functions_file]
functions_file = [func for func in functions_file if func not in exclude_imports]
self.reflector = TiramisuReflector(self.rougailobjspace, self.reflector = TiramisuReflector(self.rougailobjspace,
functions_file, functions_file,
self.internal_functions, self.internal_functions,

View file

@ -28,7 +28,7 @@ You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
""" """
from typing import Optional from typing import Optional, List
from .i18n import _ from .i18n import _
from .reflector import Reflector from .reflector import Reflector
@ -106,7 +106,9 @@ class RougailObjSpace:
def __init__(self, def __init__(self,
xmlreflector: Reflector, xmlreflector: Reflector,
rougailconfig: 'RougailConfig', rougailconfig: 'RougailConfig',
just_doc: bool,
) -> None: ) -> None:
self.just_doc = just_doc
self.space = ObjSpace() self.space = ObjSpace()
self.paths = Path(rougailconfig) self.paths = Path(rougailconfig)
@ -201,6 +203,7 @@ class RougailObjSpace:
namespace_description, namespace_description,
redefine_variables, redefine_variables,
False, False,
True,
) )
def _xml_parse(self, # pylint: disable=R0913 def _xml_parse(self, # pylint: disable=R0913
@ -211,6 +214,7 @@ class RougailObjSpace:
namespace_description, namespace_description,
redefine_variables, redefine_variables,
is_dynamic, is_dynamic,
first_level,
) -> None: ) -> None:
# var to check unique family name in a XML file # var to check unique family name in a XML file
family_names = [] family_names = []
@ -218,6 +222,8 @@ class RougailObjSpace:
if not isinstance(child.tag, str): if not isinstance(child.tag, str):
# doesn't proceed the XML commentaries # doesn't proceed the XML commentaries
continue continue
if first_level and self.just_doc and child.tag == 'services':
continue
if is_dynamic: if is_dynamic:
is_sub_dynamic = True is_sub_dynamic = True
else: else:
@ -246,6 +252,7 @@ class RougailObjSpace:
child, child,
variableobj, variableobj,
) )
if not self.just_doc:
self.remove(child, self.remove(child,
variableobj, variableobj,
redefine_variables, redefine_variables,
@ -276,6 +283,7 @@ class RougailObjSpace:
namespace_description, namespace_description,
redefine_variables, redefine_variables,
is_sub_dynamic, is_sub_dynamic,
False,
) )
def get_variableobj(self, def get_variableobj(self,
@ -370,7 +378,7 @@ class RougailObjSpace:
# manage object only if already exists, so cancel # manage object only if already exists, so cancel
raise SpaceObjShallNotBeUpdated() raise SpaceObjShallNotBeUpdated()
redefine = convert_boolean(subspace.get('redefine', False)) redefine = convert_boolean(subspace.get('redefine', False))
if redefine is True: if redefine is True and not self.just_doc:
# cannot redefine an inexistant object # cannot redefine an inexistant object
msg = _(f'Redefined object: "{name}" does not exist yet') msg = _(f'Redefined object: "{name}" does not exist yet')
raise DictConsistencyError(msg, 46, [xmlfile]) raise DictConsistencyError(msg, 46, [xmlfile])
@ -432,9 +440,10 @@ class RougailObjSpace:
redefine = convert_boolean(child.attrib.get('redefine', False)) redefine = convert_boolean(child.attrib.get('redefine', False))
if redefine and child.tag == 'variable': if redefine and child.tag == 'variable':
# delete old values # delete old values
has_value = hasattr(variableobj, 'value') if hasattr(variableobj, 'value') and len(child) != 0:
if has_value and len(child) != 0:
del variableobj.value del variableobj.value
if self.just_doc:
variableobj.multi = len(child) > 1
for attr, val in child.attrib.items(): for attr, val in child.attrib.items():
if attr == 'text' and child.tag in self.forced_text_elts_as_name: if attr == 'text' and child.tag in self.forced_text_elts_as_name:
continue continue
@ -469,12 +478,12 @@ class RougailObjSpace:
if child.attrib.get('remove_condition', False): if child.attrib.get('remove_condition', False):
self.remove_condition(variableobj.name) self.remove_condition(variableobj.name)
if child.attrib.get('remove_fill', False): if child.attrib.get('remove_fill', False):
self.remove_fill(variableobj.name) self.remove_fill(variableobj.name, variableobj.xmlfiles)
elif child.tag == 'fill': elif child.tag == 'fill':
for target in child: for target in child:
if target.tag == 'target' and \ if target.tag == 'target' and \
self.paths.get_path(target.text, namespace) in redefine_variables: self.paths.get_path(target.text, namespace) in redefine_variables:
self.remove_fill(target.text) self.remove_fill(target.text, variableobj.xmlfiles)
def remove_check(self, name): def remove_check(self, name):
"""Remove a check with a specified target """Remove a check with a specified target
@ -515,11 +524,15 @@ class RougailObjSpace:
def remove_fill(self, def remove_fill(self,
name: str, name: str,
xmlfiles: List[str],
) -> None: ) -> None:
"""Remove a fill with a specified target """Remove a fill with a specified target
""" """
remove_fills = [] remove_fills = []
constraints = self.get_constraints() constraints = self.get_constraints()
if not hasattr(constraints, 'fill'):
msg = _(f'Cannot remove fill to "{name}", the variable has no fill yet')
raise DictConsistencyError(msg, 89, xmlfiles)
for idx, fill in enumerate(constraints.fill): # pylint: disable=E1101 for idx, fill in enumerate(constraints.fill): # pylint: disable=E1101
for target in fill.target: for target in fill.target:
if target.name == name: if target.name == name:
@ -579,6 +592,8 @@ class RougailObjSpace:
def get_variables(objectspace): def get_variables(objectspace):
"""Iter all variables from the objectspace """Iter all variables from the objectspace
""" """
if not hasattr(objectspace.space, 'variables'):
return
for family in objectspace.space.variables.values(): for family in objectspace.space.variables.values():
yield from _get_variables(family, objectspace.family) yield from _get_variables(family, objectspace.family)

View file

@ -71,6 +71,7 @@ class Reflector:
def load_dictionaries_from_folders(self, def load_dictionaries_from_folders(self,
folders: List[str], folders: List[str],
just_doc: bool,
): ):
"""Loads all the dictionary files located in the folders' list """Loads all the dictionary files located in the folders' list
@ -90,8 +91,8 @@ class Reflector:
if filename in filenames: if filename in filenames:
raise DictConsistencyError(_(f'duplicate dictionary file name {filename}'), 78, [filenames[filename], full_filename]) raise DictConsistencyError(_(f'duplicate dictionary file name {filename}'), 78, [filenames[filename], full_filename])
filenames[filename] = (ext, full_filename) filenames[filename] = (ext, full_filename)
if not filenames: if not filenames and not just_doc:
raise DictConsistencyError(_('there is no dictionary file'), 77, [folder]) raise DictConsistencyError(_('there is no dictionary file'), 77, folders)
file_names = list(filenames.keys()) file_names = list(filenames.keys())
file_names.sort() file_names.sort()
for filename in file_names: for filename in file_names: