Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
caosdb-pylib
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
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-pylib
Commits
caf2a942
Commit
caf2a942
authored
4 months ago
by
Henrik tom Wörden
Browse files
Options
Downloads
Patches
Plain Diff
MAINT: deprecate old arguments
parent
eb30b29e
No related branches found
No related tags found
2 merge requests
!159
Release 0.16.o
,
!154
Added the possibility to use custom labels instead of 'old' and 'new'
Pipeline
#57458
failed
4 months ago
Stage: code_style
Stage: linting
Stage: test
Stage: deploy
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/linkahead/apiutils.py
+47
-35
47 additions, 35 deletions
src/linkahead/apiutils.py
with
47 additions
and
35 deletions
src/linkahead/apiutils.py
+
47
−
35
View file @
caf2a942
...
...
@@ -622,11 +622,14 @@ def merge_entities(entity_a: Entity,
return
entity_a
def
describe_diff
(
olddiff
:
dict
[
str
,
Any
],
newdiff
:
dict
[
str
,
Any
],
name
:
str
=
None
,
as_update
:
bool
=
True
,
label_old
:
str
=
"
old version
"
,
label_new
:
str
=
"
new version
"
)
->
str
:
def
describe_diff
(
entity0_diff
:
dict
[
str
,
Any
],
entity1_diff
:
dict
[
str
,
Any
],
name
:
Optional
[
str
]
=
None
,
as_update
:
Optional
[
bool
]
=
None
,
label_e0
:
str
=
"
first version
"
,
label_e1
:
str
=
"
second version
"
,
olddiff
:
Any
=
None
,
newdiff
:
Any
=
None
,
)
->
str
:
"""
Generate a textual description of the differences between two entities.
These can be generated using :func:`compare_entities` and used within this function like this:
...
...
@@ -636,25 +639,25 @@ def describe_diff(olddiff: dict[str, Any], newdiff: dict[str, Any],
Arguments:
----------
old
diff: dict[str, Any]
entity0_
diff: dict[str, Any]
First element of the tuple output of :func:`compare_entities`.
This is referred to as the
"
old
"
version.
new
diff: dict[str, Any]
entity1_
diff: dict[str, Any]
Second element of the tuple output of :func:`compare_entities`.
This is referred to as the
"
new
"
version.
name: str
name:
Optional[
str
]
Default None. Name of the entity that will be shown in the output text.
as_update: bool
Default
Tru
e. Not used anymore.
as_update:
Optional[
bool
]
Default
Non
e. Not used anymore.
label_
old
: str
label_
e0
: str
Can be used to set a custom label for the diff that is associated with the old entity.
label_
new
: str
label_
e1
: str
Can be used to set a custom label for the diff that is associated with the new entity.
Returns:
...
...
@@ -664,42 +667,51 @@ def describe_diff(olddiff: dict[str, Any], newdiff: dict[str, Any],
"""
description
=
""
for
attr
in
list
(
set
(
list
(
olddiff
.
keys
())
+
list
(
newdiff
.
keys
()))):
if
as_update
:
warnings
.
warn
(
"'
as_update
'
is deprecated. Do not use it.
"
,
DeprecationWarning
)
if
olddiff
:
warnings
.
warn
(
"'
olddiff
'
is deprecated. Use
'
entity0_diff
'
instead.
"
,
DeprecationWarning
)
entity0_diff
=
olddiff
if
newdiff
:
warnings
.
warn
(
"'
newdiff
'
is deprecated. Use
'
entity1_diff
'
instead.
"
,
DeprecationWarning
)
entity1_diff
=
newdiff
for
attr
in
list
(
set
(
list
(
entity0_diff
.
keys
())
+
list
(
entity1_diff
.
keys
()))):
if
attr
==
"
parents
"
or
attr
==
"
properties
"
:
continue
description
+=
"
{} differs:
\n
"
.
format
(
attr
)
description
+=
label_
old
+
"
: {}
\n
"
.
format
(
old
diff
[
attr
]
if
attr
in
old
diff
else
"
not set
"
)
description
+=
label_
new
+
"
: {}
\n\n
"
.
format
(
new
diff
[
attr
]
if
attr
in
new
diff
else
"
not set
"
)
description
+=
label_
e0
+
"
: {}
\n
"
.
format
(
entity0_
diff
[
attr
]
if
attr
in
entity0_
diff
else
"
not set
"
)
description
+=
label_
e1
+
"
: {}
\n\n
"
.
format
(
entity1_
diff
[
attr
]
if
attr
in
entity1_
diff
else
"
not set
"
)
if
len
(
old
diff
[
"
parents
"
])
>
0
:
description
+=
(
"
Parents that are only in the
"
+
label_
old
+
"
:
\n
"
+
"
,
"
.
join
(
old
diff
[
"
parents
"
])
+
"
\n
"
)
if
len
(
entity0_
diff
[
"
parents
"
])
>
0
:
description
+=
(
"
Parents that are only in the
"
+
label_
e0
+
"
:
\n
"
+
"
,
"
.
join
(
entity0_
diff
[
"
parents
"
])
+
"
\n
"
)
if
len
(
new
diff
[
"
parents
"
])
>
0
:
description
+=
(
"
Parents that are only in the
"
+
label_
new
+
"
:
\n
"
+
"
,
"
.
join
(
old
diff
[
"
parents
"
])
+
"
\n
"
)
if
len
(
entity1_
diff
[
"
parents
"
])
>
0
:
description
+=
(
"
Parents that are only in the
"
+
label_
e1
+
"
:
\n
"
+
"
,
"
.
join
(
entity0_
diff
[
"
parents
"
])
+
"
\n
"
)
for
prop
in
list
(
set
(
list
(
old
diff
[
"
properties
"
].
keys
())
+
list
(
new
diff
[
"
properties
"
].
keys
()))):
for
prop
in
list
(
set
(
list
(
entity0_
diff
[
"
properties
"
].
keys
())
+
list
(
entity1_
diff
[
"
properties
"
].
keys
()))):
description
+=
"
property {} differs:
\n
"
.
format
(
prop
)
if
prop
not
in
old
diff
[
"
properties
"
]:
description
+=
"
it does not exist in the
"
+
label_
old
+
"
:
\n
"
elif
prop
not
in
new
diff
[
"
properties
"
]:
description
+=
"
it does not exist in the
"
+
label_
new
+
"
:
\n
"
if
prop
not
in
entity0_
diff
[
"
properties
"
]:
description
+=
"
it does not exist in the
"
+
label_
e0
+
"
:
\n
"
elif
prop
not
in
entity1_
diff
[
"
properties
"
]:
description
+=
"
it does not exist in the
"
+
label_
e1
+
"
:
\n
"
else
:
description
+=
label_
old
+
"
: {}
\n
"
.
format
(
old
diff
[
"
properties
"
][
prop
])
description
+=
label_
new
+
"
: {}
\n\n
"
.
format
(
new
diff
[
"
properties
"
][
prop
])
description
+=
label_
e0
+
"
: {}
\n
"
.
format
(
entity0_
diff
[
"
properties
"
][
prop
])
description
+=
label_
e1
+
"
: {}
\n\n
"
.
format
(
entity1_
diff
[
"
properties
"
][
prop
])
if
description
!=
""
:
description
=
(
"
## Difference between the
"
+
label_
old
+
label_
e0
+
"
and the
"
+
label_
new
+
label_
e1
+
"
of {}
\n\n
"
.
format
(
name
))
+
description
return
description
...
...
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