diff --git a/src/caosadvancedtools/models/parser.py b/src/caosadvancedtools/models/parser.py index 0180e4d1ab4595101588abe7380a09abcf94089a..e9c459ca447666ad270e658d4186dd69c40dc37f 100644 --- a/src/caosadvancedtools/models/parser.py +++ b/src/caosadvancedtools/models/parser.py @@ -48,7 +48,8 @@ import caosdb as db from .data_model import DataModel # Keywords which are allowed in data model descriptions. -KEYWORDS = ["parent", # TODO: can we remove that, see: #36 +KEYWORDS = ["parent", # deprecated, use inherit_from_* instead: + # https://gitlab.com/caosdb/caosdb-advanced-user-tools/-/issues/36 "importance", "datatype", # for example TEXT, INTEGER or REFERENCE "unit", @@ -60,7 +61,8 @@ KEYWORDS = ["parent", # TODO: can we remove that, see: #36 "inherit_from_suggested", "inherit_from_obligatory", "role", - "value", ] + "value", + ] # TODO: check whether it's really ignored # These KEYWORDS are not forbidden as properties, but merely ignored. @@ -160,9 +162,9 @@ def parse_model_from_json_schema(filename: str): class Parser(object): def __init__(self): - """ - Initialize an empty parer object and initialize - the dictionary of entities and the list of treated elements. + """Initialize an empty parser object and initialize the dictionary of entities and the list of + treated elements. + """ self.model = {} self.treated = [] @@ -359,7 +361,25 @@ class Parser(object): raise def _add_to_recordtype(self, ent_name, props, importance): - """Add properties to a RecordType.""" + """Add properties to a RecordType. + + Parameters + ---------- + ent_name : str + The name of the entity to which the properties shall be added. + + props : dict [str -> dict or :doc:`Entity`] + The properties, indexed by their names. Properties may be given as :doc:`Entity` objects + or as dictionaries. + + importance + The importance as used in :doc:`Entity.add_property`. + + Returns + ------- + None + + """ for n, e in props.items(): if n in KEYWORDS: @@ -374,9 +394,10 @@ class Parser(object): if isinstance(e, dict): if "datatype" in e and _get_listdatatype(e["datatype"]) is not None: + # Reuse the existing datatype for lists. datatype = db.LIST(_get_listdatatype(e["datatype"])) else: - # ignore a possible e["datatype"] here if it's not a list + # Ignore a possible e["datatype"] here if it's not a list # since it has been treated in the definition of the # property (entity) already datatype = None diff --git a/tox.ini b/tox.ini index 1b3cd4ef0d39955197448ace9fdf5d26ea6749b4..f7b5aabf37628f57e8e192dfced969541aecfe25 100644 --- a/tox.ini +++ b/tox.ini @@ -11,3 +11,6 @@ deps=nose xlrd == 1.2 h5py commands=py.test --cov=caosadvancedtools -vv {posargs} + +[flake8] +max-line-length=100 diff --git a/unittests/test_yaml_model_parser.py b/unittests/test_yaml_model_parser.py index c3f09462fe0dbf67afa9c2bb9bf17224bd91eef6..01730cdb1690c7c4a917475d10c9035177fb58b7 100644 --- a/unittests/test_yaml_model_parser.py +++ b/unittests/test_yaml_model_parser.py @@ -408,7 +408,7 @@ def test_issue_72(): https://gitlab.indiscale.com/caosdb/src/caosdb-advanced-user-tools/-/issues/72 In some cases, faulty values would be read in for properties without a - secified value. + specified value. """ model = """