-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Deep update of specs in Lancium adapter #276
Conversation
4545341
to
124ba18
Compare
Codecov ReportBase: 98.88% // Head: 98.88% // No change to project coverage 👍
Additional details and impacted files@@ Coverage Diff @@
## master #276 +/- ##
=======================================
Coverage 98.88% 98.88%
=======================================
Files 56 56
Lines 2325 2325
=======================================
Hits 2299 2299
Misses 26 26
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. ☔ View full report at Codecov. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added some comments on the deep_update
implementations. I'm very certain on the typing considerations but feel free to ignore the algorithm suggestions/changes.
tardis/utilities/utils.py
Outdated
original_mapping: Mapping[KeyType, Any], | ||
mapping_update: Mapping[KeyType, Any], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think technically the original must be MutableMapping
since we need to change items in the copy. Consider to even restrict it to Dict
since that's what is substituted at some points and you also special-case List
(instead of Sequence
).
For mapping_update
it's fine.
In the interest of generality, you might want to support List
as well – that would allow a recursive deep_update
into lists as well. Only if you want the extra work, though...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have changed the original to MutableMapping
. I thought to support List
's as well, however I concluded that there is currently no need for it , so I decided to implement only the minimal solution working for us.
Thank you @maxfischer2781 for the in depth review. I will change things or reply to the inline comments otherwise. |
27784fa
to
8538432
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Feel free to update the master
.
Co-authored-by: Max Fischer <[email protected]>
Co-authored-by: Max Fischer <[email protected]>
d1d1080
to
a9fb255
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maxfischer2781 force-approved the fix-lancium-adapter
branch
tardis/utilities/utils.py
Outdated
elif isinstance(value, list): | ||
updated_mapping[key] = deepcopy(original_mapping.get(key, [])) | ||
# do not duplicate entries which are already in the list | ||
updated_mapping[key].extend( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is extend
really what I expect deep_update
to do? Running
original_mapping = {"foo": [1, 2, 3], "bar": "baz"}
mapping_update = {"foo": [4, 5, 6]}
updated_mapping = deep_update(original_mapping, mapping_update)
I naively would expect updated_mapping
to be {"foo": [4, 5, 6], "bar": "baz"}
and not {"foo": [1, 2, 3, 4, 5, 6], "bar": "baz"}
. This behavior I could achieve by explicitly running
original_mapping = {"foo": [1, 2, 3], "bar": "baz"}
mapping_update = {"foo": list(set(original_mapping["foo"] + [4, 5, 6]))}
updated_mapping = deep_update(original_mapping, mapping_update)
Maybe this can be accomplished by explicitly setting some extend_lists
-flag (possibly with True
as default) in the call of deep_update
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think to implement deep_update
was not a very wise idea and I am not happy with it as well. It seems to be prone to errors and to misunderstandings. Since, we know exactly what needs to be appended or overwritten in the Lancium SiteAdapter, I will implement it "manually" in the adapter itself following KISS.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have to agree that using an implementation specific to Lancium instead of trying to formulate a generic case seems more appropriate, given how many edge cases we run into otherwise. 😕
This reverts commit a9fb255.
37b6d03
to
a6566c4
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's... simpler. 😁
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with @maxfischer2781, that looks a lot simpler 😅 Thanks @giffels!
Currently, the spec dictionary in the Lancium adapter is not "deeply" updated. For example:
TARDIS is setting up the Drone specific environment in the spec dictionary:
However, if the user decides to set-up a specific environment in the configuration, like:
this is currently going to overwrite the environment specfied by TARDIS.
This pull request uses a deep update function to ensure, that the environment is updated instead of being overwritten.