From cf110ad17e8ec28721c5f9249ac519613b0e9eaf Mon Sep 17 00:00:00 2001 From: KRiedmiller Date: Thu, 3 Aug 2023 18:15:10 +0200 Subject: [PATCH 01/12] test: run test with gh actions in docker --- .github/workflows/ci.yml | 18 ++++++++++++++++-- .gitignore | 2 ++ README.md | 21 +++++++++++++++++++- plugins/setup.cfg | 1 - requirements.txt | 2 +- src/kimmdy/utils.py | 21 ++++++++------------ tests/test_integration.py | 2 ++ tox.ini | 40 +++++++++++++++++++++++++++++++++++++-- 8 files changed, 87 insertions(+), 20 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e9d34fbe..2d664115 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -9,7 +9,7 @@ jobs: lint: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - uses: psf/black@stable release: name: release @@ -23,7 +23,7 @@ jobs: with: release-type: python package-name: kimmdy - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: tag stable versions if: ${{ steps.release.outputs.release_created }} run: | @@ -34,3 +34,17 @@ jobs: git push origin :stable || true git tag -a stable -m "Last Stable Release" git push origin stable + test: + runs-on: ubuntu-latest + container: riedmiki/gromacs-plumed-python:2021 + steps: + - uses : actions/checkout@v3 + - name: run tox + run: | + tox + zip -r htmlcov.zip htmlcov + - uses: actions/upload-artifact@v3 + with: + name: coverage artifact + path: htmlcov.zip + diff --git a/.gitignore b/.gitignore index 64bff237..a007f418 100644 --- a/.gitignore +++ b/.gitignore @@ -68,7 +68,9 @@ pip-log.txt pip-delete-this-directory.txt # Unit test / coverage reports +artifacts htmlcov/ +htmlcov* .tox/ .nox/ .coverage diff --git a/README.md b/README.md index 857d9863..4ec7acc0 100644 --- a/README.md +++ b/README.md @@ -8,8 +8,16 @@ Reactive MD pipeline for GROMACS using Kinetic Monte Carlo / Molecular Dynamics * `cd kimmdy` * `python -m venv .venv` * `source ./venv/bin/activate` +* `python -m pip install -e ./` +* Some rections need a GROMACS version patched with PLUMED, gromacs name should then contain `MODIFIED` or `plumed` + +## Development setup + * `python -m pip install -r requirments.txt` -* Some rections need a GROMACS version patched with PLUMED +* code style: black +* docstrings: numpy +* [Conventional commit](https://www.conventionalcommits.org/en/v1.0.0/) messages when possible for pretty release notes. + ## First simulation @@ -19,3 +27,14 @@ Reactive MD pipeline for GROMACS using Kinetic Monte Carlo / Molecular Dynamics * check output: `kimmdy.log`, `test_out_00X/` +## Local testing + +For developoment, we provide a docker image containing gromacs and multiple python versions to test against. +To run the test locally, you must: +- install docker +- install [act](https://github.com/nektos/act), easiest option is with github cli + - install github cli (`gh`) + - `gh extension install https://github.com/nektos/gh-act` +- run tests with `gh extension exec act -j test --artifact-server-path ./artifacts` + - customize which python versions to test in `tox.ini` + - html coverage report is exported into `artifacts` diff --git a/plugins/setup.cfg b/plugins/setup.cfg index 9c1b3589..cfb4dc74 100644 --- a/plugins/setup.cfg +++ b/plugins/setup.cfg @@ -17,7 +17,6 @@ package_dir = =src include_package_data = True install_requires = - kimmdy MDAnalysis python_requires = >= 3.9 diff --git a/requirements.txt b/requirements.txt index 9448e5a4..b6c8d2b4 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,7 +3,7 @@ tox black hypothesis jupyter -git+https://github.com/machow/quartodoc.git +# git+https://github.com/machow/quartodoc.git pydantic<2 -e . -e ./plugins diff --git a/src/kimmdy/utils.py b/src/kimmdy/utils.py index 2a86867d..ca0e3069 100644 --- a/src/kimmdy/utils.py +++ b/src/kimmdy/utils.py @@ -169,7 +169,7 @@ def check_gmx_version(config): """Check for an existing gromacs installation. If PLUMED is meant to be used it additionally checks for the keyword - 'MODIFIED' in the version name. + 'MODIFIED' or 'plumed' in the version name. """ try: version = [ @@ -184,18 +184,13 @@ def check_gmx_version(config): logging.error(m) raise SystemError(m) - # this should probably be a TODO: then - # i hate this - if ( - any( - "plumed" in y - for y in [ - config.mds.attr(x).get_attributes() for x in config.mds.get_attributes() - ] - ) - and not "MODIFIED" in version - ): - m = "GROMACS version does not contain MODIFIED, aborting due to lack of PLUMED patch." + if any( + "plumed" in y + for y in [ + config.mds.attr(x).get_attributes() for x in config.mds.get_attributes() + ] + ) and (not ("MODIFIED" in version or "plumed" in version)): + m = "GROMACS version does not contain MODIFIED or plumed, aborting due to lack of PLUMED patch." logging.error(m) logging.error("Version was: " + version) if not config.dryrun: diff --git a/tests/test_integration.py b/tests/test_integration.py index 59f9016c..120f3745 100644 --- a/tests/test_integration.py +++ b/tests/test_integration.py @@ -91,6 +91,7 @@ def test_integration_hat_reaction(tmp_path, caplog): ) +@pytest.mark.slow def test_integration_homolysis_reaction(tmp_path, caplog): testdir = setup_testdir(tmp_path, "homolysis") caplog.set_level(logging.INFO) @@ -105,6 +106,7 @@ def test_integration_homolysis_reaction(tmp_path, caplog): ) +@pytest.mark.slow def test_integration_whole_run(tmp_path, caplog): testdir = setup_testdir(tmp_path, "whole_run") caplog.set_level(logging.INFO) diff --git a/tox.ini b/tox.ini index 5260e422..004af819 100644 --- a/tox.ini +++ b/tox.ini @@ -1,13 +1,49 @@ [tox] envlist = - py38 + clean + lint py39 py310 + py311 + report [testenv] +description = run tests +package_root = + ./ + plugins deps = pytest pytest-cov pytest-randomly + hypothesis + ; installes editable, packaged would be better: + -r requirements.txt + ; would work if extra would be public: + ; extras = plugins commands = - pytest --cov=kimmdy --randomly-seed=1 \ No newline at end of file + pytest -m "not slow" --cov=kimmdy --randomly-seed=1 + ; pytest --cov=kimmdy --randomly-seed=1 + ; pytest --cov=kimmdy --cov-append --randomly-seed=1 + ; only test discovery: + ; pytest --cov=kimmdy --randomly-seed=1 --co + +[testenv:lint] +description = run black +skip_install = true +deps = + black +commands = + black src tests + +[testenv:clean] +deps = coverage +skip_install = true +commands = coverage erase + +[testenv:report] +deps = coverage +skip_install = true +commands = + coverage html + From ef886ccfbc87acec8f00e037baf6732f8063dd79 Mon Sep 17 00:00:00 2001 From: KRiedmiller Date: Thu, 3 Aug 2023 18:29:18 +0200 Subject: [PATCH 02/12] test: add badge --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 4ec7acc0..f6c00e78 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,7 @@ # KIMMDY +[![CI](https://github.com/hits-mbm-dev/kimmdy/actions/workflows/ci.yml/badge.svg)](https://github.com/hits-mbm-dev/kimmdy/actions/workflows/ci.yml) + Reactive MD pipeline for GROMACS using Kinetic Monte Carlo / Molecular Dynamics (KIMMDY) ## Quick start From ba00e4c6346db31691ad8250d240ec8013650949 Mon Sep 17 00:00:00 2001 From: KRiedmiller Date: Fri, 4 Aug 2023 09:00:22 +0200 Subject: [PATCH 03/12] fix: upload artifact even for failed tests --- .github/workflows/ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2d664115..0c697d3e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -44,6 +44,7 @@ jobs: tox zip -r htmlcov.zip htmlcov - uses: actions/upload-artifact@v3 + if: ${{ !cancelled() }} with: name: coverage artifact path: htmlcov.zip From 53be7a97ae60d591922c455153c0b5a3d9e7b33d Mon Sep 17 00:00:00 2001 From: KRiedmiller Date: Fri, 4 Aug 2023 11:02:25 +0200 Subject: [PATCH 04/12] test: fix error due to slow test, print durations --- .github/workflows/ci.yml | 7 +++---- tests/test_integration.py | 1 + tests/test_topology.py | 5 ++++- tox.ini | 2 +- 4 files changed, 9 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0c697d3e..57a446e6 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -40,11 +40,10 @@ jobs: steps: - uses : actions/checkout@v3 - name: run tox - run: | - tox - zip -r htmlcov.zip htmlcov + run: tox || true + - name: zip coverage report + run: zip -r htmlcov.zip htmlcov || true - uses: actions/upload-artifact@v3 - if: ${{ !cancelled() }} with: name: coverage artifact path: htmlcov.zip diff --git a/tests/test_integration.py b/tests/test_integration.py index 120f3745..fb56bf28 100644 --- a/tests/test_integration.py +++ b/tests/test_integration.py @@ -78,6 +78,7 @@ def test_grompp_with_kimmdy_topology(tmp_path): ) +@pytest.mark.slow def test_integration_hat_reaction(tmp_path, caplog): testdir = setup_testdir(tmp_path, "hat_naive") caplog.set_level(logging.INFO) diff --git a/tests/test_topology.py b/tests/test_topology.py index 7794f27a..030c9247 100644 --- a/tests/test_topology.py +++ b/tests/test_topology.py @@ -244,7 +244,10 @@ def test_break_bind_bond_hexala(self, hexala_top_fix): assert top.improper_dihedrals == og_top.improper_dihedrals @given(bondindex=st.integers(min_value=0, max_value=70)) - @settings(suppress_health_check=[HealthCheck.function_scoped_fixture]) + @settings( + suppress_health_check=[HealthCheck.function_scoped_fixture], deadline=1000 + ) + @pytest.mark.slow def test_break_bind_random_bond_hexala(self, hexala_top_fix, bondindex): top = deepcopy(hexala_top_fix) og_top = deepcopy(top) diff --git a/tox.ini b/tox.ini index 004af819..e2cc7d80 100644 --- a/tox.ini +++ b/tox.ini @@ -22,7 +22,7 @@ deps = ; would work if extra would be public: ; extras = plugins commands = - pytest -m "not slow" --cov=kimmdy --randomly-seed=1 + pytest -m "not slow" --durations=15 --cov=kimmdy --randomly-seed=1 ; pytest --cov=kimmdy --randomly-seed=1 ; pytest --cov=kimmdy --cov-append --randomly-seed=1 ; only test discovery: From ed718ce2bdced83349bce12fe201166e1ea56899 Mon Sep 17 00:00:00 2001 From: KRiedmiller Date: Fri, 4 Aug 2023 11:41:06 +0200 Subject: [PATCH 05/12] test: only if pr is labled --- .github/workflows/ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 57a446e6..ddf1ad5a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -40,6 +40,7 @@ jobs: steps: - uses : actions/checkout@v3 - name: run tox + if : contains( github.event.pull_request.labeled.label.name, 'CI:run_test') run: tox || true - name: zip coverage report run: zip -r htmlcov.zip htmlcov || true From 1a746c58663ad0d70b58e202a0e96c6629e42316 Mon Sep 17 00:00:00 2001 From: KRiedmiller Date: Fri, 4 Aug 2023 12:01:47 +0200 Subject: [PATCH 06/12] test: check pr label --- .github/workflows/ci.yml | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ddf1ad5a..155d39f4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -38,9 +38,14 @@ jobs: runs-on: ubuntu-latest container: riedmiki/gromacs-plumed-python:2021 steps: + - name: Check pr lable + uses: jesusvasquez333/verify-pr-label-action@v1.4.0 + with: + github-token: '${{ secrets.GITHUB_TOKEN }}' + valid-labels: 'CI:run_test' + invalid-labels: 'autorelease:tagged' - uses : actions/checkout@v3 - name: run tox - if : contains( github.event.pull_request.labeled.label.name, 'CI:run_test') run: tox || true - name: zip coverage report run: zip -r htmlcov.zip htmlcov || true @@ -48,4 +53,5 @@ jobs: with: name: coverage artifact path: htmlcov.zip - + + From 1bdcdd96c3cf651f40de7dc2d140dd8f6f62e2ef Mon Sep 17 00:00:00 2001 From: KRiedmiller Date: Fri, 4 Aug 2023 13:43:30 +0200 Subject: [PATCH 07/12] fix: only run with lable --- .github/workflows/ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 155d39f4..483ed5b2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -44,6 +44,7 @@ jobs: github-token: '${{ secrets.GITHUB_TOKEN }}' valid-labels: 'CI:run_test' invalid-labels: 'autorelease:tagged' + disable-reviews: true - uses : actions/checkout@v3 - name: run tox run: tox || true From 4cf62920ab44293310850fad1d65142bd5a40217 Mon Sep 17 00:00:00 2001 From: KRiedmiller Date: Fri, 4 Aug 2023 13:53:40 +0200 Subject: [PATCH 08/12] fix: get exit state --- .github/workflows/ci.yml | 7 ++++++- tox.ini | 6 +++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 483ed5b2..74fa3e38 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -47,12 +47,17 @@ jobs: disable-reviews: true - uses : actions/checkout@v3 - name: run tox - run: tox || true + run: tox - name: zip coverage report + if: ${{ !cancelled() }} run: zip -r htmlcov.zip htmlcov || true - uses: actions/upload-artifact@v3 + if: ${{ !cancelled() }} with: name: coverage artifact path: htmlcov.zip + - name: Get exit status for badge + if: ${{ failure() }} + run: false diff --git a/tox.ini b/tox.ini index e2cc7d80..08e0a9fa 100644 --- a/tox.ini +++ b/tox.ini @@ -2,9 +2,9 @@ envlist = clean lint - py39 - py310 - py311 + ; py39 + ; py310 + ; py311 report [testenv] From eb3cad1af7646c0fccf0d4985851246fb31d02a3 Mon Sep 17 00:00:00 2001 From: KRiedmiller Date: Fri, 4 Aug 2023 13:57:02 +0200 Subject: [PATCH 09/12] fix: test commit --- tox.ini | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tox.ini b/tox.ini index 08e0a9fa..3bf96b7e 100644 --- a/tox.ini +++ b/tox.ini @@ -6,7 +6,8 @@ envlist = ; py310 ; py311 report - + ; + [testenv] description = run tests package_root = From 6f1c666ba1790cc52cee879005018c5eccbce8b5 Mon Sep 17 00:00:00 2001 From: KRiedmiller Date: Fri, 4 Aug 2023 14:02:20 +0200 Subject: [PATCH 10/12] test: cleanup --- tox.ini | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tox.ini b/tox.ini index 3bf96b7e..b8e1efbd 100644 --- a/tox.ini +++ b/tox.ini @@ -2,12 +2,11 @@ envlist = clean lint - ; py39 - ; py310 - ; py311 + py39 + py310 + py311 report - ; - + [testenv] description = run tests package_root = @@ -46,5 +45,6 @@ commands = coverage erase deps = coverage skip_install = true commands = + coverage report coverage html From 3cee068d41ddd9ec807e5334a7cee47bfb66cbf1 Mon Sep 17 00:00:00 2001 From: KRiedmiller Date: Fri, 4 Aug 2023 14:10:53 +0200 Subject: [PATCH 11/12] fix: get exit status of pr label --- .github/workflows/ci.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 74fa3e38..be6a0b60 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -39,6 +39,7 @@ jobs: container: riedmiki/gromacs-plumed-python:2021 steps: - name: Check pr lable + id: prlabel uses: jesusvasquez333/verify-pr-label-action@v1.4.0 with: github-token: '${{ secrets.GITHUB_TOKEN }}' @@ -57,7 +58,7 @@ jobs: name: coverage artifact path: htmlcov.zip - name: Get exit status for badge - if: ${{ failure() }} - run: false + if: ${{ failure() && steps.prlabel.conclusion == 'failure'}} + run: true From dcc314c65c424f486d77be9b600781cb6c2c9f18 Mon Sep 17 00:00:00 2001 From: KRiedmiller Date: Fri, 4 Aug 2023 14:24:40 +0200 Subject: [PATCH 12/12] test: separate job for label detection --- .github/workflows/ci.yml | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index be6a0b60..5ba1bcc4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -34,18 +34,25 @@ jobs: git push origin :stable || true git tag -a stable -m "Last Stable Release" git push origin stable - test: + prlabel: runs-on: ubuntu-latest - container: riedmiki/gromacs-plumed-python:2021 + outputs: + status: ${{ steps.prcheck.conclusion }} steps: - name: Check pr lable - id: prlabel + id: prcheck uses: jesusvasquez333/verify-pr-label-action@v1.4.0 with: github-token: '${{ secrets.GITHUB_TOKEN }}' valid-labels: 'CI:run_test' - invalid-labels: 'autorelease:tagged' + invalid-labels: '' disable-reviews: true + test: + runs-on: ubuntu-latest + container: riedmiki/gromacs-plumed-python:2021 + needs: prlabel + if: needs.prlabel.outputs.status == 'success' + steps: - uses : actions/checkout@v3 - name: run tox run: tox @@ -57,8 +64,5 @@ jobs: with: name: coverage artifact path: htmlcov.zip - - name: Get exit status for badge - if: ${{ failure() && steps.prlabel.conclusion == 'failure'}} - run: true