Skip to content

Remove the Pydantic integration - #21

Merged
thomasple merged 4 commits into
mainfrom
remove-pydantic-integration
Oct 25, 2026
Merged

thomasple merged 4 commits into
mainfrom
remove-pydantic-integration

Conversation

@thomasple

@thomasple thomasple commented Oct 25, 2026 •

Copy link
Copy Markdown
Owner

Summary

Closes #20. Removes the Pydantic integration. Users validate the output of convert_mapping with Pydantic or another library instead.

 src/hartreez/
 ├── __init__.py        # drops the UnitDimension export
 ├── mapping.py         # drops require_references and recurse (only pydantic.py used them)
-├── metadata.py        # UnitDimension
-└── pydantic.py        # UnitAwareModel
 tests/
-└── test_pydantic.py
 docs/
 ├── mappings.md        # + "Validate with Pydantic or another library"
-└── pydantic.md
 pyproject.toml         # drops the pydantic extra and dev dependency
 release.yml            # wheel smoke test no longer installs [pydantic]
 README.md              # Pydantic section now links to the recipe
+CHANGELOG.md           # new; linked from PyPI, renamed per release (docs/releasing.md)
 AGENTS.md              # + every user-visible PR adds a changelog entry

The recipe:

data = convert_mapping(raw, au, reference_units={"timestep": "fs", "energy": "eV"})
inputs = CalculationInput.model_validate(data)

The docs say that only paths listed in reference_units are checked, and that extra="forbid" makes Pydantic reject unknown suffixed keys such as junk[ps].

Evidence

  • Before (main): from hartreez.pydantic import UnitAwareModel and from hartreez import UnitDimension import. pytest: 242 passed, 1 skipped.
    After: both raise ImportError. pytest: 197 passed, 1 skipped (torch is not installed; the 45 dropped tests are in tests/test_pydantic.py). Pyright reports no errors.
  • The recipe, run with Pydantic installed, gives timestep=20.67 energy=0.0735 in au. With extra="forbid", {"energy[eV]": 1.0, "junk[ps]": 1.0} is rejected at ('junk',).
  • convert_mapping behaves the same: it always passed recurse=True and never set require_references.

Merge Danger

Door: two-way

Reverting restores the integration. Once a release ships without it, users will have moved to the recipe.

Blast Radius: Pydantic users

hartreez[pydantic], hartreez.pydantic.UnitAwareModel and hartreez.UnitDimension shipped in v0.1.0 and v0.1.1. Code that uses them breaks on upgrade. The removal is recorded under ## Unreleased in the new CHANGELOG.md, so the next release should be 0.2.0.

UnitAwareModel had to predict how Pydantic maps input keys to fields,
and every attempt to close that gap (#17, #18, #19) needed more of
Pydantic's internals. Remove the integration, UnitDimension, the
pydantic extra, and the mapping options only it used. docs/mappings.md
shows how to validate convert_mapping output with Pydantic instead.

Closes #20
@thomasple
thomasple merged commit 55a4274 into main Oct 25, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Remove the Pydantic integration

1 participant