Skip to content

Save class objects in json and toml#145

Merged
raphaeltimbo merged 3 commits into
petrobras:mainfrom
marcusfilipesr:dev-save
Jul 18, 2026
Merged

Save class objects in json and toml#145
raphaeltimbo merged 3 commits into
petrobras:mainfrom
marcusfilipesr:dev-save

Conversation

@marcusfilipesr

Copy link
Copy Markdown
Collaborator

Now, the user can save ccp class objects (Point, Curve and Impeller) into json or toml file.

@marcusfilipesr marcusfilipesr self-assigned this Jul 6, 2026
@marcusfilipesr marcusfilipesr added the enhancement New feature or request label Jul 6, 2026
@marcusfilipesr

Copy link
Copy Markdown
Collaborator Author

I've made some modifications to allow the save_load tests to pass.

There is an interesting behavior with other tests that are now failing, but they are not directly related to the modifications of this PR.

@raphaeltimbo
raphaeltimbo merged commit 2730cfc into petrobras:main Jul 18, 2026
raphaeltimbo added a commit that referenced this pull request Jul 18, 2026
…om_dict

Replace the per-class toml/json save/load logic with a single serializers
module (ccp/data_io/serializers.py):

- File format is decided by the file suffix (.toml or .json); the
  file_type parameter is removed. Unsupported suffixes raise ValueError
  instead of silently truncating or leaving variables unbound.
- Writes are atomic (temp file + os.replace), so a failed dump never
  corrupts an existing file.
- Point, Curve, Impeller, StraightThrough and BackToBack now expose
  public to_dict()/from_dict() (replacing _dict_to_save/_dict_from_load)
  and inherit save()/load() from a Serializable mixin.
- Saved files record the writing library version in a "ccp_version" key,
  enabling future format migrations; Curve/Impeller files nest points
  under a "points" table. Legacy flat files still load.
- Fix app pages passing io.StringIO to Impeller/StraightThrough/
  BackToBack.load (broken since #145 for Impeller): pages now use the
  public from_dict with toml parsed in memory.
- Tests: round-trips parametrized over toml and json for Point, Curve
  and Impeller, unsupported-format error case, and a legacy flat-file
  load test.

Part of the app-page diff is whitespace-only: ruff format applied to
files that were not formatted on main.
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.

2 participants