From ca6c55af6306543baf198c0081caa4f20e2406f1 Mon Sep 17 00:00:00 2001 From: Daniel Weindl Date: Mon, 23 Nov 2026 14:33:58 +0100 Subject: [PATCH 1/2] Move model modules and their tests (renames only) Move the model implementation from `petab/v1/models` to `petab/_models`, and the PySB and BNGL tests and fixtures from `tests/v1` to `tests/models`, without changes; the imports are fixed in the next commit. Co-Authored-By: Claude Opus 5.5 --- petab/{v1/models => _models}/bngl_model.py | 0 petab/{v1/models => _models}/model.py | 0 petab/{v1/models => _models}/pysb_model.py | 0 petab/{v1/models => _models}/sbml_model.py | 0 tests/{v1 => models}/bngl/parabola.bngl | 0 tests/{v1 => models}/bngl_corpus/README.md | 0 tests/{v1 => models}/bngl_corpus/golden.json | 0 tests/{v1 => models}/fetch_bngl_corpus.py | 0 tests/{v1 => models}/test_bngl_corpus.py | 0 tests/{v1 => models}/test_model_bngl.py | 0 tests/{v1 => models}/test_model_pysb.py | 0 11 files changed, 0 insertions(+), 0 deletions(-) rename petab/{v1/models => _models}/bngl_model.py (100%) rename petab/{v1/models => _models}/model.py (100%) rename petab/{v1/models => _models}/pysb_model.py (100%) rename petab/{v1/models => _models}/sbml_model.py (100%) rename tests/{v1 => models}/bngl/parabola.bngl (100%) rename tests/{v1 => models}/bngl_corpus/README.md (100%) rename tests/{v1 => models}/bngl_corpus/golden.json (100%) rename tests/{v1 => models}/fetch_bngl_corpus.py (100%) rename tests/{v1 => models}/test_bngl_corpus.py (100%) rename tests/{v1 => models}/test_model_bngl.py (100%) rename tests/{v1 => models}/test_model_pysb.py (100%) diff --git a/petab/v1/models/bngl_model.py b/petab/_models/bngl_model.py similarity index 100% rename from petab/v1/models/bngl_model.py rename to petab/_models/bngl_model.py diff --git a/petab/v1/models/model.py b/petab/_models/model.py similarity index 100% rename from petab/v1/models/model.py rename to petab/_models/model.py diff --git a/petab/v1/models/pysb_model.py b/petab/_models/pysb_model.py similarity index 100% rename from petab/v1/models/pysb_model.py rename to petab/_models/pysb_model.py diff --git a/petab/v1/models/sbml_model.py b/petab/_models/sbml_model.py similarity index 100% rename from petab/v1/models/sbml_model.py rename to petab/_models/sbml_model.py diff --git a/tests/v1/bngl/parabola.bngl b/tests/models/bngl/parabola.bngl similarity index 100% rename from tests/v1/bngl/parabola.bngl rename to tests/models/bngl/parabola.bngl diff --git a/tests/v1/bngl_corpus/README.md b/tests/models/bngl_corpus/README.md similarity index 100% rename from tests/v1/bngl_corpus/README.md rename to tests/models/bngl_corpus/README.md diff --git a/tests/v1/bngl_corpus/golden.json b/tests/models/bngl_corpus/golden.json similarity index 100% rename from tests/v1/bngl_corpus/golden.json rename to tests/models/bngl_corpus/golden.json diff --git a/tests/v1/fetch_bngl_corpus.py b/tests/models/fetch_bngl_corpus.py similarity index 100% rename from tests/v1/fetch_bngl_corpus.py rename to tests/models/fetch_bngl_corpus.py diff --git a/tests/v1/test_bngl_corpus.py b/tests/models/test_bngl_corpus.py similarity index 100% rename from tests/v1/test_bngl_corpus.py rename to tests/models/test_bngl_corpus.py diff --git a/tests/v1/test_model_bngl.py b/tests/models/test_model_bngl.py similarity index 100% rename from tests/v1/test_model_bngl.py rename to tests/models/test_model_bngl.py diff --git a/tests/v1/test_model_pysb.py b/tests/models/test_model_pysb.py similarity index 100% rename from tests/v1/test_model_pysb.py rename to tests/models/test_model_pysb.py From 1365b1ab6d9ccffa5d68a3a268512efa7807ab19 Mon Sep 17 00:00:00 2001 From: Daniel Weindl Date: Mon, 23 Nov 2026 14:34:04 +0100 Subject: [PATCH 2/2] Move model classes to a version-independent package The model classes serve both PEtab v1 and v2, but lived in `petab.v1.models`, with `petab.v2.models` re-exporting them. This suggested that PySB and BNGL models were supported with PEtab v1. Move the implementation to the private package `petab._models` (in the previous commit; here, only imports change). `petab.v1.models` and `petab.v2.models` re-export it. Deprecate (for now only in the changelog) the PySB and BNGL modules in `petab.v1.models`. Move the PySB and BNGL tests and fixtures to `tests/models`. Co-Authored-By: Claude Opus 5.5 --- .github/workflows/ci_tests.yml | 2 +- .gitignore | 4 +-- .../+v1-pysb-bngl-models.deprecation.md | 6 ++++ doc/development.rst | 2 +- petab/_models/__init__.py | 34 +++++++++++++++++++ petab/_models/bngl_model.py | 4 +-- petab/_models/pysb_model.py | 4 +-- petab/_models/sbml_model.py | 4 +-- petab/v1/models/__init__.py | 19 ++++------- petab/v1/models/bngl_model.py | 12 +++++++ petab/v1/models/model.py | 9 +++++ petab/v1/models/pysb_model.py | 12 +++++++ petab/v1/models/sbml_model.py | 9 +++++ petab/v2/core.py | 2 +- petab/v2/models/__init__.py | 3 +- petab/v2/models/bngl_model.py | 8 ++++- petab/v2/models/model.py | 8 ++++- petab/v2/models/pysb_model.py | 8 ++++- petab/v2/models/sbml_model.py | 8 ++++- tests/models/__init__.py | 0 tests/models/bngl_corpus/README.md | 4 +-- tests/models/fetch_bngl_corpus.py | 8 ++--- tests/models/test_bngl_corpus.py | 12 +++---- tests/models/test_model_bngl.py | 8 ++--- tests/models/test_model_pysb.py | 4 +-- 25 files changed, 147 insertions(+), 47 deletions(-) create mode 100644 changelog.d/+v1-pysb-bngl-models.deprecation.md create mode 100644 petab/_models/__init__.py create mode 100644 petab/v1/models/bngl_model.py create mode 100644 petab/v1/models/model.py create mode 100644 petab/v1/models/pysb_model.py create mode 100644 petab/v1/models/sbml_model.py create mode 100644 tests/models/__init__.py diff --git a/.github/workflows/ci_tests.yml b/.github/workflows/ci_tests.yml index 8070bab7..094ba697 100644 --- a/.github/workflows/ci_tests.yml +++ b/.github/workflows/ci_tests.yml @@ -37,7 +37,7 @@ jobs: if: matrix.platform == 'ubuntu-latest' - name: Fetch BNGL test corpus - run: uv run --no-project python -P tests/v1/fetch_bngl_corpus.py + run: uv run --no-project python -P tests/models/fetch_bngl_corpus.py - name: Unit tests run: | diff --git a/.gitignore b/.gitignore index d1431f9c..53f43239 100644 --- a/.gitignore +++ b/.gitignore @@ -115,8 +115,8 @@ venv.bak/ _untracked doc/_static/README.rst -# BNGL corpus fixtures are fetched on demand (tests/v1/fetch_bngl_corpus.py) -tests/v1/bngl_corpus/*.bngl +# BNGL corpus fixtures are fetched on demand (tests/models/fetch_bngl_corpus.py) +tests/models/bngl_corpus/*.bngl # CI resolves the latest dependency versions uv.lock diff --git a/changelog.d/+v1-pysb-bngl-models.deprecation.md b/changelog.d/+v1-pysb-bngl-models.deprecation.md new file mode 100644 index 00000000..0232eb6f --- /dev/null +++ b/changelog.d/+v1-pysb-bngl-models.deprecation.md @@ -0,0 +1,6 @@ +PySB and BNGL models are only supported with PEtab v2. +`petab.v1.models.pysb_model`, `petab.v1.models.bngl_model`, and loading +PySB or BNGL models via `petab.v1` are deprecated and will be removed in a +future release; use `petab.v2.models.pysb_model` and +`petab.v2.models.bngl_model` instead +([#622](https://github.com/PEtab-dev/libpetab-python/pull/622)) diff --git a/doc/development.rst b/doc/development.rst index 992616cc..0bb19598 100644 --- a/doc/development.rst +++ b/doc/development.rst @@ -77,7 +77,7 @@ have been downloaded via: .. code-block:: bash - uv run --no-project python -P tests/v1/fetch_bngl_corpus.py + uv run --no-project python -P tests/models/fetch_bngl_corpus.py Style guide ----------- diff --git a/petab/_models/__init__.py b/petab/_models/__init__.py new file mode 100644 index 00000000..1b67bb01 --- /dev/null +++ b/petab/_models/__init__.py @@ -0,0 +1,34 @@ +"""Model types supported by PEtab, shared by :mod:`petab.v1` and +:mod:`petab.v2`. + +Use :mod:`petab.v1.models` or :mod:`petab.v2.models` instead of importing +from here. +""" + +#: SBML model type as used in a PEtab v2 yaml file as `language`. +MODEL_TYPE_SBML = "sbml" +#: PySB model type as used in a PEtab v2 yaml file as `language`. +MODEL_TYPE_PYSB = "pysb" +#: BNGL model type as used in a PEtab v2 yaml file as `language`. +MODEL_TYPE_BNGL = "bngl" + +known_model_types = { + MODEL_TYPE_SBML, + MODEL_TYPE_PYSB, + MODEL_TYPE_BNGL, +} + +# The model modules use helpers from `petab.v1`, whose initialization +# imports `petab.v1.models` and thus this package; initialize `petab.v1` +# first to avoid a circular import. +import petab.v1 # noqa: E402, F401 + +from .model import Model # noqa: E402 + +__all__ = [ + "MODEL_TYPE_BNGL", + "MODEL_TYPE_PYSB", + "MODEL_TYPE_SBML", + "Model", + "known_model_types", +] diff --git a/petab/_models/bngl_model.py b/petab/_models/bngl_model.py index 2f8cef39..a1290bc7 100644 --- a/petab/_models/bngl_model.py +++ b/petab/_models/bngl_model.py @@ -39,8 +39,8 @@ from dataclasses import dataclass from pathlib import Path -from ..._utils import _generate_path -from .. import is_valid_identifier +from .._utils import _generate_path +from ..v1.lint import is_valid_identifier from . import MODEL_TYPE_BNGL from .model import Model diff --git a/petab/_models/pysb_model.py b/petab/_models/pysb_model.py index de1ce95c..0fa4be66 100644 --- a/petab/_models/pysb_model.py +++ b/petab/_models/pysb_model.py @@ -13,8 +13,8 @@ import pysb -from ..._utils import _generate_path -from .. import is_valid_identifier +from .._utils import _generate_path +from ..v1.lint import is_valid_identifier from . import MODEL_TYPE_PYSB from .model import Model diff --git a/petab/_models/sbml_model.py b/petab/_models/sbml_model.py index 831a42e3..ce791ec5 100644 --- a/petab/_models/sbml_model.py +++ b/petab/_models/sbml_model.py @@ -10,8 +10,8 @@ import sympy as sp from sbmlmath import sbml_math_to_sympy -from ..._utils import _generate_path -from ..sbml import ( +from .._utils import _generate_path +from ..v1.sbml import ( get_sbml_model, is_sbml_consistent, load_sbml_from_string, diff --git a/petab/v1/models/__init__.py b/petab/v1/models/__init__.py index 29c44a26..416c73ae 100644 --- a/petab/v1/models/__init__.py +++ b/petab/v1/models/__init__.py @@ -1,19 +1,12 @@ """Handling of different model types supported by PEtab.""" -#: SBML model type as used in a PEtab v2 yaml file as `language`. -MODEL_TYPE_SBML = "sbml" -#: PySB model type as used in a PEtab v2 yaml file as `language`. -MODEL_TYPE_PYSB = "pysb" -#: BNGL model type as used in a PEtab v2 yaml file as `language`. -MODEL_TYPE_BNGL = "bngl" - -known_model_types = { - MODEL_TYPE_SBML, - MODEL_TYPE_PYSB, +from ..._models import ( MODEL_TYPE_BNGL, -} - -from .model import Model # noqa F401 + MODEL_TYPE_PYSB, + MODEL_TYPE_SBML, + known_model_types, +) +from .model import Model __all__ = [ "MODEL_TYPE_BNGL", diff --git a/petab/v1/models/bngl_model.py b/petab/v1/models/bngl_model.py new file mode 100644 index 00000000..4cfd804c --- /dev/null +++ b/petab/v1/models/bngl_model.py @@ -0,0 +1,12 @@ +"""Deprecated: use :mod:`petab.v2.models.bngl_model`. + +BNGL models are only supported with PEtab v2. +""" + +from ..._models import bngl_model as _impl +from ..._models.bngl_model import * +from ..._models.bngl_model import __all__ # noqa: F401 + + +def __getattr__(name): + return getattr(_impl, name) diff --git a/petab/v1/models/model.py b/petab/v1/models/model.py new file mode 100644 index 00000000..124b4426 --- /dev/null +++ b/petab/v1/models/model.py @@ -0,0 +1,9 @@ +"""PEtab model abstraction""" + +from ..._models import model as _impl +from ..._models.model import * +from ..._models.model import __all__ # noqa: F401 + + +def __getattr__(name): + return getattr(_impl, name) diff --git a/petab/v1/models/pysb_model.py b/petab/v1/models/pysb_model.py new file mode 100644 index 00000000..38893741 --- /dev/null +++ b/petab/v1/models/pysb_model.py @@ -0,0 +1,12 @@ +"""Deprecated: use :mod:`petab.v2.models.pysb_model`. + +PySB models are only supported with PEtab v2. +""" + +from ..._models import pysb_model as _impl +from ..._models.pysb_model import * +from ..._models.pysb_model import __all__ # noqa: F401 + + +def __getattr__(name): + return getattr(_impl, name) diff --git a/petab/v1/models/sbml_model.py b/petab/v1/models/sbml_model.py new file mode 100644 index 00000000..7f06cc67 --- /dev/null +++ b/petab/v1/models/sbml_model.py @@ -0,0 +1,9 @@ +"""Functions for handling SBML models""" + +from ..._models import sbml_model as _impl +from ..._models.sbml_model import * +from ..._models.sbml_model import __all__ # noqa: F401 + + +def __getattr__(name): + return getattr(_impl, name) diff --git a/petab/v2/core.py b/petab/v2/core.py index c719811a..9e782c37 100644 --- a/petab/v2/core.py +++ b/petab/v2/core.py @@ -50,12 +50,12 @@ ) from ..v1.distributions import * from ..v1.math import petab_math_str, sympify_petab -from ..v1.models.model import Model, model_factory from ..v1.yaml import get_path_prefix from ..versions import parse_version from . import C, get_observable_df from ._helpers import is_reserved_keyword, is_valid_identifier from .extensions import ExtensionConfig, parse_extension_config +from .models.model import Model, model_factory from .options import TableColumns, get_options if TYPE_CHECKING: diff --git a/petab/v2/models/__init__.py b/petab/v2/models/__init__.py index 7b66f4e6..49ecb8e3 100644 --- a/petab/v2/models/__init__.py +++ b/petab/v2/models/__init__.py @@ -1,3 +1,4 @@ """Handling of different model types supported by PEtab.""" -from ...v1.models import * +from ..._models import * +from ..._models import __all__ # noqa: F401 diff --git a/petab/v2/models/bngl_model.py b/petab/v2/models/bngl_model.py index 42df986d..c07727dc 100644 --- a/petab/v2/models/bngl_model.py +++ b/petab/v2/models/bngl_model.py @@ -1,3 +1,9 @@ """Functions for handling BNGL models""" -from ...v1.models.bngl_model import * +from ..._models import bngl_model as _impl +from ..._models.bngl_model import * +from ..._models.bngl_model import __all__ # noqa: F401 + + +def __getattr__(name): + return getattr(_impl, name) diff --git a/petab/v2/models/model.py b/petab/v2/models/model.py index 56c213bd..124b4426 100644 --- a/petab/v2/models/model.py +++ b/petab/v2/models/model.py @@ -1,3 +1,9 @@ """PEtab model abstraction""" -from ...v1.models.model import * +from ..._models import model as _impl +from ..._models.model import * +from ..._models.model import __all__ # noqa: F401 + + +def __getattr__(name): + return getattr(_impl, name) diff --git a/petab/v2/models/pysb_model.py b/petab/v2/models/pysb_model.py index 1630f02c..171f3818 100644 --- a/petab/v2/models/pysb_model.py +++ b/petab/v2/models/pysb_model.py @@ -1,3 +1,9 @@ """Functions for handling PySB models""" -from ...v1.models.pysb_model import * +from ..._models import pysb_model as _impl +from ..._models.pysb_model import * +from ..._models.pysb_model import __all__ # noqa: F401 + + +def __getattr__(name): + return getattr(_impl, name) diff --git a/petab/v2/models/sbml_model.py b/petab/v2/models/sbml_model.py index e68b1581..7f06cc67 100644 --- a/petab/v2/models/sbml_model.py +++ b/petab/v2/models/sbml_model.py @@ -1,3 +1,9 @@ """Functions for handling SBML models""" -from ...v1.models.sbml_model import * +from ..._models import sbml_model as _impl +from ..._models.sbml_model import * +from ..._models.sbml_model import __all__ # noqa: F401 + + +def __getattr__(name): + return getattr(_impl, name) diff --git a/tests/models/__init__.py b/tests/models/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/tests/models/bngl_corpus/README.md b/tests/models/bngl_corpus/README.md index 2aee5db8..5550643d 100644 --- a/tests/models/bngl_corpus/README.md +++ b/tests/models/bngl_corpus/README.md @@ -1,13 +1,13 @@ # Curated BNGL corpus fixtures Public community BNGL models, chosen for feature coverage, backing -`tests/v1/test_bngl_corpus.py`: it asserts `parse_bngl` enumerates the same +`tests/models/test_bngl_corpus.py`: it asserts `parse_bngl` enumerates the same model entities BNG2.pl does. The BNG2.pl answers are cached in `golden.json` (the entity name sets BNG2.pl emits from `writeModel`, its canonical parse), so the test needs **no BNG2.pl** -- it compares the reader against the frozen oracle. Regenerate the golden (needs BNG2.pl) with: - python tests/v1/test_bngl_corpus.py + python tests/models/test_bngl_corpus.py Vendored from public repos ([RuleWorld/RuleHub](https://github.com/RuleWorld/rulehub), diff --git a/tests/models/fetch_bngl_corpus.py b/tests/models/fetch_bngl_corpus.py index 21e9d721..6c41e486 100755 --- a/tests/models/fetch_bngl_corpus.py +++ b/tests/models/fetch_bngl_corpus.py @@ -1,5 +1,5 @@ #!/usr/bin/env python3 -"""Materialize the BNGL test corpus backing ``tests/v1/test_bngl_corpus.py``. +"""Materialize the BNGL test corpus for ``tests/models/test_bngl_corpus.py``. The corpus is 21 third-party ``.bngl`` fixture files. Rather than vendoring ~3200 lines of model text, this script fetches them on @@ -14,7 +14,7 @@ ``parity_checks/bng_parity/vendor_corpus.py``. Usage: - python tests/v1/fetch_bngl_corpus.py [--dest DIR] [--force] [--dry-run] + python tests/models/fetch_bngl_corpus.py [--dest DIR] [--force] [--dry-run] """ from __future__ import annotations @@ -47,7 +47,7 @@ # (dest filename, (repo, sha), upstream path, expected sha256 of the RAW # upstream bytes, optional (find, replace, expected_count) repair applied # after the hash check). Transcribed from -# tests/v1/bngl_corpus/README.md's provenance table. +# tests/models/bngl_corpus/README.md's provenance table. CORPUS = [ ( "An_2009.bngl", @@ -255,7 +255,7 @@ def main() -> int: type=Path, default=Path(__file__).parent / "bngl_corpus", help="directory to write fetched .bngl files into (default: " - "bngl_corpus/ next to this script, i.e. tests/v1/bngl_corpus)", + "bngl_corpus/ next to this script, i.e. tests/models/bngl_corpus)", ) ap.add_argument( "--force", diff --git a/tests/models/test_bngl_corpus.py b/tests/models/test_bngl_corpus.py index aa49f7d3..82e88ee0 100644 --- a/tests/models/test_bngl_corpus.py +++ b/tests/models/test_bngl_corpus.py @@ -1,6 +1,6 @@ """Corpus regression gate: the BNGL reader agrees with BNG2.pl on real models. -Asserts :func:`petab.v1.models.bngl_model.parse_bngl` enumerates the same model +Asserts :func:`petab.v2.models.bngl_model.parse_bngl` enumerates the same model entities BNG2.pl does, over a curated set of public community BNGL models under ``bngl_corpus/``. BNG2.pl's answers are cached in ``bngl_corpus/golden.json``: the entity name sets BNG2.pl emits from ``writeModel`` (its canonical parse, no @@ -13,7 +13,7 @@ Regenerate the golden after adding a fixture or changing the reader (needs a BNG2.pl on ``BNGPATH``/``PATH``) and review the diff:: - python tests/v1/test_bngl_corpus.py + python tests/models/test_bngl_corpus.py """ from __future__ import annotations @@ -28,14 +28,14 @@ import pytest -from petab.v1.models.bngl_model import parse_bngl +from petab.v2.models.bngl_model import parse_bngl _CORPUS = Path(__file__).parent / "bngl_corpus" _GOLDEN = _CORPUS / "golden.json" _MODELS = sorted(_CORPUS.glob("*.bngl")) _NO_CORPUS_REASON = ( - "no .bngl files in tests/v1/bngl_corpus/ -- fetch them first with " - "`python tests/v1/fetch_bngl_corpus.py`" + "no .bngl files in tests/models/bngl_corpus/ -- fetch them first with " + "`python tests/models/fetch_bngl_corpus.py`" ) @@ -170,7 +170,7 @@ def _canonical_bngl(model_text, bng2): def _regenerate(): - from petab.v1.models.bngl_model import _locate_bng2 + from petab.v2.models.bngl_model import _locate_bng2 bng2 = _locate_bng2() if bng2 is None: diff --git a/tests/models/test_model_bngl.py b/tests/models/test_model_bngl.py index b4641faf..cd83c6a7 100644 --- a/tests/models/test_model_bngl.py +++ b/tests/models/test_model_bngl.py @@ -1,10 +1,10 @@ -"""Tests for petab.v1.models.bngl_model""" +"""Tests for petab.v2.models.bngl_model""" from pathlib import Path import pytest -from petab.v1.models.bngl_model import BnglEntities, BnglModel, parse_bngl +from petab.v2.models.bngl_model import BnglEntities, BnglModel, parse_bngl #: A self-contained BNGL model exercising every entity kind read by the #: PEtab layer: parameters, a molecule type, a seed species, an observable, @@ -233,7 +233,7 @@ def test_is_valid(model): def test_is_valid_detects_broken_model_when_bng_available(tmp_path): - from petab.v1.models.bngl_model import _locate_bng2 + from petab.v2.models.bngl_model import _locate_bng2 if _locate_bng2() is None: pytest.skip("BNG2.pl not available; is_valid falls back to True") @@ -249,7 +249,7 @@ def test_is_valid_detects_broken_model_when_bng_available(tmp_path): def test_model_factory_routes_bngl(): - from petab.v1.models.model import model_factory + from petab.v2.models.model import model_factory model = model_factory(EXAMPLE_BNGL, "bngl") assert isinstance(model, BnglModel) diff --git a/tests/models/test_model_pysb.py b/tests/models/test_model_pysb.py index 48aa4481..6afebafd 100644 --- a/tests/models/test_model_pysb.py +++ b/tests/models/test_model_pysb.py @@ -1,9 +1,9 @@ -"""Test related to petab.models.model_pysb""" +"""Tests for petab.v2.models.pysb_model""" import pysb import pytest -from petab.v1.models.pysb_model import ( +from petab.v2.models.pysb_model import ( PySBModel, parse_species_name, pattern_from_string,