Skip to content

Commit

Permalink
Get tutorial-tests.yml working (#226)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
sroet authored Aug 19, 2024
1 parent 26c2935 commit 59d3fc5
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 6 deletions.
17 changes: 13 additions & 4 deletions .github/workflows/tutorial-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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: |
Expand All @@ -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
2 changes: 1 addition & 1 deletion docs/tutorials/Tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ tm_tutorial/
¦ +- ...
+- templates/
¦ +- 6qzp_60S.mrc
¦ +- emd_2938.mrc
¦ +- emd_2938.map
+- results_80S/
+- results_60S/
```
Expand Down
26 changes: 25 additions & 1 deletion docs/tutorials/tests/test_tutorial.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

0 comments on commit 59d3fc5

Please sign in to comment.