Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
caosdb-advanced-user-tools
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
caosdb
Software
caosdb-advanced-user-tools
Commits
6fcf533d
Verified
Commit
6fcf533d
authored
1 year ago
by
Daniel Hornung
Browse files
Options
Downloads
Patches
Plain Diff
MAINT: _get_listdatatype -> get_list_datatype (from pylinkahead)
parent
87773e8f
No related branches found
Branches containing commit
No related tags found
Tags containing commit
2 merge requests
!89
ENH: JsonSchemaExporter accepts do_not_create parameter.
,
!88
jsex / yaml parser
Pipeline
#43867
passed
1 year ago
Stage: setup
Stage: cert
Stage: style
Stage: unittest
Stage: integrationtest
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/caosadvancedtools/models/parser.py
+21
-34
21 additions, 34 deletions
src/caosadvancedtools/models/parser.py
unittests/test_yaml_model_parser.py
+11
-0
11 additions, 0 deletions
unittests/test_yaml_model_parser.py
with
32 additions
and
34 deletions
src/caosadvancedtools/models/parser.py
+
21
−
34
View file @
6fcf533d
...
...
@@ -46,8 +46,9 @@ from typing import List, Optional
from
warnings
import
warn
import
jsonschema
import
caosdb
as
db
import
linkahead
as
db
from
linkahead.common.datatype
import
get_list_datatype
from
.data_model
import
CAOSDB_INTERNAL_PROPERTIES
,
DataModel
# Keywords which are allowed in data model descriptions.
...
...
@@ -82,23 +83,6 @@ JSON_SCHEMA_ATOMIC_TYPES = [
]
def
_get_listdatatype
(
dtype
):
"""
matches a string to check whether the type definition is a list
returns the type within the list or None, if it cannot be matched with a
list definition
"""
# TODO: string representation should be the same as used by the server:
# e.g. LIST<TEXT>
# this should be changed in the module and the old behavour should be
# marked as depricated
match
=
re
.
match
(
r
"
^LIST[(<](?P<dt>.*)[)>]$
"
,
dtype
)
if
match
is
None
:
return
None
else
:
return
match
.
group
(
"
dt
"
)
# Taken from https://stackoverflow.com/a/53647080, CC-BY-SA, 2018 by
# https://stackoverflow.com/users/2572431/augurar
...
...
@@ -412,8 +396,8 @@ debug : bool, optional
# is it a property
and
"
datatype
"
in
definition
# but not simply an RT of the model
and
not
(
_
get_listdatatype
(
definition
[
"
datatype
"
])
==
name
and
_
get_listdatatype
(
definition
[
"
datatype
"
])
in
self
.
model
)):
and
not
(
get_list
_
datatype
(
definition
[
"
datatype
"
])
==
name
and
get_list
_
datatype
(
definition
[
"
datatype
"
])
in
self
.
model
)):
# and create the new property
self
.
model
[
name
]
=
db
.
Property
(
name
=
name
,
...
...
@@ -499,9 +483,9 @@ debug : bool, optional
n
=
self
.
_stringify
(
n
)
if
isinstance
(
e
,
dict
):
if
"
datatype
"
in
e
and
_
get_listdatatype
(
e
[
"
datatype
"
])
is
not
None
:
if
"
datatype
"
in
e
and
get_list
_
datatype
(
e
[
"
datatype
"
])
is
not
None
:
# Reuse the existing datatype for lists.
datatype
=
db
.
LIST
(
_
get_listdatatype
(
e
[
"
datatype
"
]))
datatype
=
db
.
LIST
(
get_list
_
datatype
(
e
[
"
datatype
"
]))
else
:
# Ignore a possible e["datatype"] here if it's not a list
# since it has been treated in the definition of the
...
...
@@ -523,6 +507,9 @@ debug : bool, optional
def
_inherit
(
self
,
name
,
prop
,
inheritance
):
if
not
isinstance
(
prop
,
list
):
if
isinstance
(
prop
,
str
):
raise
YamlDefinitionError
(
f
"
Parents must be a list but is given as string:
{
name
}
>
{
prop
}
"
)
raise
YamlDefinitionError
(
"
Parents must be a list, error in line {}
"
.
format
(
prop
[
"
__line__
"
]))
...
...
@@ -640,19 +627,19 @@ debug : bool, optional
dtype
=
value
.
datatype
is_list
=
False
try
:
if
_
get_listdatatype
(
value
.
datatype
)
is
not
None
:
dtype
=
_get_listdatatype
(
value
.
datatype
)
is_list
=
True
except
TypeError
as
err
:
err
.
args
=
(
*
err
.
args
,
f
"
yaml line:
{
value
.
__dict__
.
get
(
'
__line__
'
)
}
"
)
raise
(
err
)
if
dtype
in
self
.
model
:
if
get_list_datatype
(
dtype
)
is
not
None
:
dtype
=
get_list
_
datatype
(
dtype
)
is_list
=
True
dtype_name
=
dtype
if
not
isinstance
(
dtype_name
,
str
):
dtype_name
=
dtype
.
name
if
dtype
_name
in
self
.
model
:
if
is_list
:
value
.
datatype
=
db
.
LIST
(
self
.
model
[
dtype
])
value
.
datatype
=
db
.
LIST
(
self
.
model
[
dtype
_name
])
else
:
value
.
datatype
=
self
.
model
[
dtype
]
value
.
datatype
=
self
.
model
[
dtype
_name
]
continue
...
...
@@ -674,7 +661,7 @@ debug : bool, optional
continue
raise
ValueError
(
"
Property {} has an unknown datatype: {}
"
.
format
(
value
.
name
,
value
.
datatyp
e
))
value
.
name
,
dtype_nam
e
))
def
_set_recordtypes
(
self
):
"""
properties are defined in first iteration; set remaining as RTs
"""
...
...
This diff is collapsed.
Click to expand it.
unittests/test_yaml_model_parser.py
+
11
−
0
View file @
6fcf533d
...
...
@@ -566,3 +566,14 @@ def test_yaml_error():
with
raises
(
ValueError
,
match
=
r
"
line 2: .*
"
):
parse_model_from_yaml
(
"
unittests/models/model_invalid.yml
"
)
def
test_inherit_error
():
"""
Must fail with an understandable exception.
"""
model_string
=
"""
prop1:
inherit_from_obligatory: prop2
"""
with
raises
(
YamlDefinitionError
,
match
=
r
"
Parents must be a list but is given as string: prop1 > prop2
"
):
parse_model_from_string
(
model_string
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment