From 59d3fc5f6bee621606e44ffe3acb9a1973746880 Mon Sep 17 00:00:00 2001 From: Sander Roet Date: Mon, 19 Aug 2024 15:09:59 +0200 Subject: [PATCH] Get tutorial-tests.yml working (#226) * reset working directory install step tutorial-tests.yml * temporarily only run on test branch * also install curl * and unzip * Update tutorial-tests.yml * no * expansion on github workflow shell, it seems * actually structure the data correctly * see if file actually runs * elaborate more on the codeblocks * more debug prints * test behavior some more * try to strip out extra code-block typing * sanitize input to subprocess * stop test if something fails * don't change .map to .mrc * fix template filename in Tutorial.md * switch to unbuffered python output for my sanity * reduce tqdm clutter * Install complete suite instead of just dev * deal with stdout rerouting * stdout needs to be an open file * allow for non-existent output file * undo all debug stuff * try to compile cupy instead * GCC is also needed now * revert back to state: 9c89c20 --- .github/workflows/tutorial-tests.yml | 17 +++++++++++++---- docs/tutorials/Tutorial.md | 2 +- docs/tutorials/tests/test_tutorial.py | 26 +++++++++++++++++++++++++- 3 files changed, 39 insertions(+), 6 deletions(-) diff --git a/.github/workflows/tutorial-tests.yml b/.github/workflows/tutorial-tests.yml index 0f63596c..89b62f83 100644 --- a/.github/workflows/tutorial-tests.yml +++ b/.github/workflows/tutorial-tests.yml @@ -4,6 +4,11 @@ on: push: branches: - main + tags: + - "[0-9]+.[0-9]+.[0-9]+" + schedule: + # Weekly on saturday 23:59 + - cron: "59 23 * * 6" jobs: @@ -19,10 +24,11 @@ jobs: - name: Pull code uses: actions/checkout@v4 - name: Install dependencies, code, and list everything + working-directory: ./ run: | - conda install -y -c conda-forge python=3 cupy cuda-version=11.8 + conda install -y -c conda-forge python=3 cupy cuda-version=11.8 curl unzip python -m pip install coverage mdextractor #mdextractor is new and might need to be replaced later - python -m pip install .[dev] + python -m pip install .[all] conda list - name: Grab files needed for tests run: | @@ -34,12 +40,15 @@ jobs: cp ../data/6qzp_60S.mrc . curl https://files.wwpdb.org/pub/emdb/structures/EMD-2938/map/emd_2938.map.gz -o emd_2938.map.gz gunzip emd_2938.map.gz - mv emd_2938.map emd_2938.mrc cd ../dataset curl -L -O -J -H "X-Dataverse-key:${{ secrets.DATAVERSE_API_TOKEN }}" https://dataverse.nl/api/access/datafiles/384731,384724,384706,384718 unzip dataverse_files.zip + # this inflates into a 'tutorial' folder, moving everything out + mv tutorial/* . + - name: Set TQDM_MININTERVAL + run: echo "TQDM_MININTERVAL=10" >> "$GITHUB_ENV" - name: Run Tutorial test run: | # Hardcode the conversion line for x in dataset/*.mrc; do python -c "import mrcfile; mrc = mrcfile.mmap('$x', 'r+'); mrc.voxel_size = 13.79"; done - python tests/test_tutorial.py + python -u tests/test_tutorial.py diff --git a/docs/tutorials/Tutorial.md b/docs/tutorials/Tutorial.md index 606d1a0d..19df2985 100644 --- a/docs/tutorials/Tutorial.md +++ b/docs/tutorials/Tutorial.md @@ -25,7 +25,7 @@ tm_tutorial/ ¦ +- ... +- templates/ ¦ +- 6qzp_60S.mrc -¦ +- emd_2938.mrc +¦ +- emd_2938.map +- results_80S/ +- results_60S/ ``` diff --git a/docs/tutorials/tests/test_tutorial.py b/docs/tutorials/tests/test_tutorial.py index 6d84e634..f6755673 100644 --- a/docs/tutorials/tests/test_tutorial.py +++ b/docs/tutorials/tests/test_tutorial.py @@ -2,9 +2,33 @@ import subprocess from mdextractor import extract_md_blocks + +def sanitize_block(block): + block = block.split() + out = [i for i in block if i and i != "\\"] + return out + + +print("Doing tutorial tests") lines = "".join(open("Tutorial.md").readlines()) blocks = extract_md_blocks(lines) +n_blocks = len(blocks) +print(f"Found {n_blocks} code blocks") +if n_blocks == 0: + raise ValueError("Did not find any code blocks") for block in blocks: + # strip out extra typing + block = block.strip("bash") if block.split()[0].endswith(".py"): print(f"Running: {block}") - subprocess.run(block) + + block = sanitize_block(block) + outfile = None + # Deal with stdout redirect + if block[-2] == ">": + outfile = open(block[-1], "a+") + block = block[:-2] + # Check=True makes sure this code returns early + subprocess.run(block, check=True, stdout=outfile) + if outfile is not None: + outfile.close()