Skip to content

Make jsonify tolerant of differing-but-valid PyPhi versions#140

Open
rogerSuperBuilderAlpha wants to merge 2 commits into
wmayner:feature/iit-4.0from
rogerSuperBuilderAlpha:fix/jsonify-version-tolerance
Open

Make jsonify tolerant of differing-but-valid PyPhi versions#140
rogerSuperBuilderAlpha wants to merge 2 commits into
wmayner:feature/iit-4.0from
rogerSuperBuilderAlpha:fix/jsonify-version-tolerance

Conversation

@rogerSuperBuilderAlpha
Copy link
Copy Markdown

Problem

jsonify._check_version requires the version string embedded in serialized JSON to exactly equal the running PyPhi version:

if version != PYPHI_VERSION:
    raise pyphi.exceptions.JSONVersionError(...)

The package version is derived from the latest git tag via hatch-vcs. On a fresh clone of feature/iit-4.0 (which has no 2.0.0a1 tag — the latest semver tag is 1.2.1), the reported version is something like 1.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:

pyphi.exceptions.JSONVersionError: Cannot load JSON from a different version of PyPhi.
JSON version = 2.0.0a1, current version = 1.2.1.dev1470+gb78d0e34.

Change

This loosens the check, in the spirit of the existing # TODO: somehow check schema instead of version? in jsonify.py:

  • A version that parses as a valid PEP 440 version but differs from the current one now emits a warnings.warn(...) 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 (e.g. "0.1.bogus") still raises JSONVersionError, so the existing guard — and test_version_check_during_deserialization — is preserved.

Notes

  • Adds packaging to runtime dependencies (now imported by jsonify for version parsing; it is already universally present transitively).
  • Adds a regression test for the warn-and-load path.
  • Adds a changelog entry.

Verification

On Python 3.12 / feature/iit-4.0, the core suite (pytest test pyphi, excluding the optional ray/redis test 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.)

rogerSuperBuilderAlpha and others added 2 commits May 30, 2026 11:14
`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>
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.

1 participant