Make jsonify tolerant of differing-but-valid PyPhi versions#140
Open
rogerSuperBuilderAlpha wants to merge 2 commits into
Open
Make jsonify tolerant of differing-but-valid PyPhi versions#140rogerSuperBuilderAlpha wants to merge 2 commits into
rogerSuperBuilderAlpha wants to merge 2 commits into
Conversation
`jsonify._check_version` required the version string embedded in serialized JSON to exactly equal the running PyPhi version, raising `JSONVersionError` otherwise. Because the package version is derived from the latest git tag (hatch-vcs), a development checkout of this branch reports e.g. `1.2.1.dev1470+g...`, which never matches the `2.0.0a1` stamped into the committed test fixtures. As a result 22 tests fail on a fresh clone for any contributor. Loosen the check (cf. the existing `# TODO: somehow check schema instead of version?`): a version that parses as a valid PEP 440 version but differs from the current one now emits a warning and loads on a best-effort basis, since the on-disk schema is stable across releases. A version string that cannot be parsed at all still raises `JSONVersionError`, preserving the existing guard (`test_version_check_during_deserialization`). - Add `packaging` to runtime dependencies (now imported by `jsonify`). - Add a regression test for the warn-and-load path. - Note the change in the changelog. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
for more information, see https://pre-commit.ci
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Problem
jsonify._check_versionrequires the version string embedded in serialized JSON to exactly equal the running PyPhi version:The package version is derived from the latest git tag via
hatch-vcs. On a fresh clone offeature/iit-4.0(which has no2.0.0a1tag — the latest semver tag is1.2.1), the reported version is something like1.2.1.dev1470+gb78d0e34. The committed JSON test fixtures, however, are stamped"__version__": "2.0.0a1". The exact-string comparison therefore rejects them, and 22 tests fail on a clean checkout for any contributor:Change
This loosens the check, in the spirit of the existing
# TODO: somehow check schema instead of version?injsonify.py:warnings.warn(...)and loads on a best-effort basis, since the on-disk schema is stable across releases."0.1.bogus") still raisesJSONVersionError, so the existing guard — andtest_version_check_during_deserialization— is preserved.Notes
packagingto runtime dependencies (now imported byjsonifyfor version parsing; it is already universally present transitively).Verification
On Python 3.12 /
feature/iit-4.0, the core suite (pytest test pyphi, excluding the optionalray/redistest modules) goes from 22 failures/errors → 0 attributable to this issue, with no regressions. (One unrelated pre-existing failure,test_distribution.py::test_unflatten, remains and is out of scope here.)