Skip to content
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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

pesap
Copy link
Collaborator

@pesap pesap commented May 1, 2024

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.
  • Added howto section that explains the method.

Closes #10

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
@pesap pesap added the enhancement New feature or request label May 1, 2024
@pesap pesap self-assigned this May 1, 2024
@pesap pesap requested a review from daniel-thom May 1, 2024 02:54
@codecov-commenter
Copy link

Codecov Report

Attention: Patch coverage is 96.15385% with 1 lines in your changes are missing coverage. Please review.

Project coverage is 94.66%. Comparing base (fe2295d) to head (03efc6e).

Files Patch % Lines
src/infrasys/system.py 90.90% 1 Missing ⚠️
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.
📢 Have feedback on the report? Share it here.


## Exporting the entire contents of the system

If the user wants to createa folder that containts all the information of the
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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")
Copy link
Collaborator

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)
Copy link
Collaborator

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(
Copy link
Collaborator

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Create save command
3 participants