From 6a52501a3a171de4d27d618ae6708e01b543623e Mon Sep 17 00:00:00 2001 From: alexPatrie Date: Mon, 4 Mar 2024 12:06:14 -0500 Subject: [PATCH] added notebook formatter in workflow --- .github/workflows/fixNotebooks.yaml | 31 +++++++++++++++++++++++++++++ biosimulator_processes/utils.py | 8 ++++++++ 2 files changed, 39 insertions(+) create mode 100644 .github/workflows/fixNotebooks.yaml diff --git a/.github/workflows/fixNotebooks.yaml b/.github/workflows/fixNotebooks.yaml new file mode 100644 index 000000000..5899e9363 --- /dev/null +++ b/.github/workflows/fixNotebooks.yaml @@ -0,0 +1,31 @@ +name: Tests + +on: + push: + branches: [main] + pull_request: + branches: [main] + +jobs: + fix-notebooks: + runs-on: ubuntu-latest + + steps: + - name: Check out repository + uses: actions/checkout@main + with: + ref: main + fetch-depth: 0 + + - name: Set up Python + uses: actions/setup-python@main + with: + python-version: '3.10' + + - id: fixNotebooks + name: Fix notebook output + uses: GabrielBB/xvfb-action@v1 + with: + working-directory: ${{ github.workspace }} + run: | + python -c "from biosimulator_processes.utils import fix_notebooks_execution_count; fix_notebooks_execution_count(); exit();" diff --git a/biosimulator_processes/utils.py b/biosimulator_processes/utils.py index 14266928d..51f2abcff 100644 --- a/biosimulator_processes/utils.py +++ b/biosimulator_processes/utils.py @@ -1,4 +1,5 @@ from typing import Dict +import os from basico import biomodels, load_model_from_string from process_bigraph import Composite, pf import nbformat @@ -241,3 +242,10 @@ def fix_execution_count(notebook_path): with open(notebook_path, 'w', encoding='utf-8') as f: nbformat.write(nb, f) + + +def fix_notebooks_execution_count(): + for root, _, files in os.walk('../notebooks'): + for _file in files: + notebook_path = os.path.join(root, _file) + fix_execution_count(notebook_path)