Add "save_to_disk" flag in the Diagram class to control automatic diagram file saving #1017
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This pull request introduces a new feature to the Diagram class: the save_to_disk flag. This flag allows users to control whether the generated diagram should be saved to disk or not. By default, the diagram is still saved to disk, which preserves the current behavior. However, by setting save_to_disk=False, users can prevent the diagram from being written to a file.
Key Amendments:
save_to_disk Flag:
Added a new optional parameter save_to_disk to the Diagram class constructor (init method).
The save_to_disk flag controls whether the diagram is saved to disk. If set to False, the diagram will not be saved as a file.
Modified the Diagram class render() method
The render() method now checks the value of save_to_disk before saving the diagram. If save_to_disk is False, the diagram rendering process will be skipped, and the diagram will not be saved to disk.
Modified the exit() method
The exit() method, which is called when exiting the with Diagram(...) context, now checks the save_to_disk flag. If save_to_disk is True, the diagram is rendered and saved as usual. If save_to_disk is False, the rendering is skipped.
Why These Changes Are Needed:
Currently, the Diagram class always saves the generated diagram to disk and users do not have the option to easily disable this. This behavior can be unnecessary or undesirable in situations where users only need to work with the diagram in memory in a byte stream (e.g., for further processing, testing, or streaming). The addition of the save_to_disk flag provides users with more flexibility and control over how their diagrams are handled.