-
Notifications
You must be signed in to change notification settings - Fork 1
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
use antares-study-version
package to handle versions
#79
Conversation
MartinBelthle
commented
Oct 8, 2024
•
edited
Loading
edited
antares-study-version package
to handle versions
@@ -43,7 +43,7 @@ class StudyDTO: | |||
# Simulation stage data | |||
time_limit: t.Optional[int] = None | |||
n_cpu: int = 1 | |||
antares_version: int = 0 | |||
antares_version: StudyVersion = StudyVersion.parse(0) |
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 don't think the parsing from tiny db will work ?
Also we need to take care that reading "old style" DTOs from tinydb still works, otherwise we will get exceptions when transitioning to this new version with old DTOs on disk
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.
Writing:
It is done inside method save_study
like this:
new["antares_version"] = f"{new['antares_version']:2d}"
line 93 of the file data_repo_tinydb.py
Reading:
It's done like this since last commit so it works for old versions too:
@classmethod
def from_dict(cls, doc: t.Mapping[str, t.Any]) -> "StudyDTO":
"""
Create a Study DTO from a mapping.
"""
attrs = dict(**doc)
attrs.pop("name", None) # calculated
attrs["antares_version"] = StudyVersion.parse(attrs["antares_version"])
return cls(**attrs)
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.
Thanks, I still added a smalle unit test to test this.
antares-study-version package
to handle versionsantares-study-version
package to handle versions
Signed-off-by: Sylvain Leclerc <[email protected]>
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.
Very minor comment, ok to merge after this
@@ -90,6 +90,7 @@ def save_study(self, study: StudyDTO): | |||
self.db.update(new, tinydb.where(pk_name) == pk_value) | |||
else: | |||
logger.info(f"Inserting study '{pk_value}' in database: {new!r}") | |||
new["antares_version"] = f"{new['antares_version']:2d}" |
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.
it's not very safe to do this because we change the study object:
if it's used after this method call, antares_version is a string and not a StudyVersion anymore.
It would be more safe to copy the dict for example
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.
Ah okay I see, modifying vars(study)
alters the study
object. I didn't think about that. I'll do a deepcopy of the dict.