From e2e1528607f20ea0ac3281d1508eeb3faca5d501 Mon Sep 17 00:00:00 2001 From: Daniel Weindl Date: Sat, 29 Jun 2024 17:58:57 +0200 Subject: [PATCH] Use v2 linter for v2 problems (#71) So far only on libpetab-python/develop Required for https://github.com/PEtab-dev/petab_test_suite/pull/14 --- .ci_pip_reqs.txt | 2 +- .github/workflows/ci_tests.yml | 1 + petabtests/file.py | 20 +++++++++++++++----- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/.ci_pip_reqs.txt b/.ci_pip_reqs.txt index 65e9674..99b0ecf 100644 --- a/.ci_pip_reqs.txt +++ b/.ci_pip_reqs.txt @@ -1,4 +1,4 @@ pytest flake8 -https://github.com/petab-dev/libpetab-python/archive/develop.zip +git+https://github.com/PEtab-dev/libpetab-python@develop sympy>=1.12.1 diff --git a/.github/workflows/ci_tests.yml b/.github/workflows/ci_tests.yml index ddebb60..4b2480c 100644 --- a/.github/workflows/ci_tests.yml +++ b/.github/workflows/ci_tests.yml @@ -28,6 +28,7 @@ jobs: run: | python -m pip install --upgrade pip wheel pip install -e . + pip uninstall -y petab pip install -r .ci_pip_reqs.txt - name: Run tests run: | diff --git a/petabtests/file.py b/petabtests/file.py index b55effe..b58ffb8 100644 --- a/petabtests/file.py +++ b/petabtests/file.py @@ -8,7 +8,8 @@ import petab import yaml from petab.C import * # noqa: F403 - +from petab.v1.lint import lint_problem as lint_problem_v1 +from petab.v2.lint import lint_problem as lint_problem_v2 from .C import * # noqa: F403 __all__ = [ @@ -180,13 +181,22 @@ def write_problem( # write yaml yaml_file = problem_yaml_name(test_id) - with open(os.path.join(dir_, yaml_file), 'w') as outfile: + yaml_path = os.path.join(dir_, yaml_file) + with open(yaml_path, 'w') as outfile: yaml.dump(config, outfile, default_flow_style=False) # validate written PEtab files - problem = petab.Problem.from_yaml(os.path.join(dir_, yaml_file)) - if petab.lint_problem(problem): - raise RuntimeError("Invalid PEtab problem, see messages above.") + if format_version == 1: + # PEtab v1 + problem = petab.Problem.from_yaml(yaml_path) + if lint_problem_v1(problem): + raise RuntimeError("Invalid PEtab problem, see messages above.") + else: + # v2 + validation_result = lint_problem_v2(yaml_path) + if validation_result: + print(validation_result) + raise RuntimeError("Invalid PEtab problem, see messages above.") def write_solution(