Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
pycalibration
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Model registry
Analyze
Contributor 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
calibration
pycalibration
Commits
513b600c
Commit
513b600c
authored
2 years ago
by
Thomas Kluyver
Browse files
Options
Downloads
Patches
Plain Diff
Check for conflicts when merging metadata
parent
f86be23d
No related branches found
No related tags found
1 merge request
!781
Support for saving metadata fragments & merging into calibration_metadata.yml
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/cal_tools/tools.py
+18
-3
18 additions, 3 deletions
src/cal_tools/tools.py
with
18 additions
and
3 deletions
src/cal_tools/tools.py
+
18
−
3
View file @
513b600c
...
...
@@ -813,13 +813,23 @@ def module_index_to_qm(index: int, total_modules: int = 16):
def
recursive_update
(
target
:
dict
,
source
:
dict
):
"""
Recursively merge source into target, checking for conflicts
Conflicting entries will not be copied to target. Returns True if any
conflicts were found.
"""
conflict
=
False
for
k
,
v2
in
source
.
items
():
v1
=
target
.
get
(
k
,
None
)
if
isinstance
(
v1
,
dict
)
and
isinstance
(
v2
,
dict
):
recursive_update
(
v1
,
v2
)
conflict
=
recursive_update
(
v1
,
v2
)
or
conflict
elif
(
v1
is
not
None
)
and
(
v1
!=
v2
):
conflict
=
True
else
:
target
[
k
]
=
v2
return
conflict
class
CalibrationMetadata
(
dict
):
"""
Convenience class: dictionary stored in metadata YAML file
...
...
@@ -868,14 +878,19 @@ class CalibrationMetadata(dict):
def
gather_fragments
(
self
):
"""
Merge in fragments saved by add_fragment(), then delete them
"""
frag_files
=
list
(
self
.
_yaml_fn
.
parent
.
glob
(
'
metadata_frag_*.yml
'
))
to_delete
=
[]
for
fn
in
frag_files
:
with
fn
.
open
(
"
r
"
)
as
fd
:
data
=
yaml
.
safe_load
(
fd
)
recursive_update
(
self
,
data
)
if
recursive_update
(
self
,
data
):
print
(
f
"
{
fn
}
contained conflicting metadata.
"
f
"
This file will be left for debugging
"
)
else
:
to_delete
.
append
(
fn
)
self
.
save
()
for
fn
in
frag_files
:
for
fn
in
to_delete
:
fn
.
unlink
()
...
...
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