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
feat(system): Added new method to save the system to a given folder. #23
base: main
Are you sure you want to change the base?
Conversation
List of changes: - Created a new method `.save` that saves all the content of the system (.json + time series) to a desired folder, - Save method can archive the folder to enable easy sharing of the system, - Added testing to validate that save in fact creates the folder and that when we zip it we delete that folder. Closes #10
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #23 +/- ##
==========================================
- Coverage 95.75% 94.66% -1.10%
==========================================
Files 24 24
Lines 2074 2100 +26
==========================================
+ Hits 1986 1988 +2
- Misses 88 112 +24 ☔ View full report in Codecov by Sentry. |
|
||
## Exporting the entire contents of the system | ||
|
||
If the user wants to createa folder that containts all the information of the |
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.
If the user wants to createa folder that containts all the information of the | |
If the user wants to create a folder that contains all the information of the |
|
||
If the user wants to createa folder that containts all the information of the | ||
system `infrasys` provides a simple method `system.save("my_folder")` that | ||
creates a folder (if it does not exists) and save all the contents of the |
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.
creates a folder (if it does not exists) and save all the contents of the | |
creates a folder (if it does not exist) and save all the contents of the |
|
||
Examples | ||
-------- | ||
>>> system.save("/home/$USER/systems/my_system") |
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.
Will this trick some users into thinking that $USER
will expand to their username?
|
||
if zip: | ||
logger.info("Archiving system and time series into a single file") | ||
_ = shutil.make_archive(str(fpath), "zip", fpath) |
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 feel uncertain about this behavior because it will zip whatever else was in the directory (and then delete it). Would it be better to require that the directory not exist and use the overwrite flag to delete it? The result would be that system.save()
always produces one directory with one system and nothing else.
@@ -284,6 +285,58 @@ def from_dict( | |||
logger.info("Deserialized system {}", system.label) | |||
return system | |||
|
|||
def save( |
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.
Do we need a System.load
classmethod that constructs a system from a directory or zip file? I know it's not a big deal to have the user call System.from_json
. We could essentially make save/load be the main ways of operating and leave the JSON details opaque. I could do the work in a separate PR.
List of changes:
.save
that saves all the content of the system(.json + time series) to a desired folder,
system,
that when we zip it we delete that folder.
howto
section that explains the method.Closes #10