Skip to content

Commit

Permalink
Upload figures
Browse files Browse the repository at this point in the history
  • Loading branch information
dhadka committed Sep 5, 2024
1 parent f15c5b6 commit ebf1f66
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
9 changes: 9 additions & 0 deletions .github/workflows/examples.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ jobs:
EXAMPLE_DIR=$(dirname "${EXAMPLE}")
EXAMPLE_FILE=$(basename "${EXAMPLE}")
mkdir -p figs
python rhodium/test/plot_to_savefig.py "${EXAMPLE}" "$(realpath figs/)"
pushd "${EXAMPLE_DIR}"
if [ -f "Makefile" ]; then
Expand All @@ -67,3 +70,9 @@ jobs:
LD_LIBRARY_PATH="$(pwd):${LD_LIBRARY_PATH}"
python "${EXAMPLE_FILE}"
- name: Upload figures
uses: actions/upload-artifact@v4
with:
name: figures
path: figs/
30 changes: 30 additions & 0 deletions rhodium/test/plot_to_savefig.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import sys
import re
import pathlib

if __name__ == "__main__":
if len(sys.argv) != 3:
print("Usage: " + __file__ + " [file] [fig_path]")
sys.exit(-1)

fig_index = 1
fig_basename = pathlib.Path(sys.argv[2]) / pathlib.Path(__file__).stem
pyplot_alias = "matplotlib.pyplot"
result = []

with open(sys.argv[1], "r") as f:
for line in f:
m = re.match(r"import matplotlib.pyplot as ([a-zA-Z_]+)", line)
if m:
pyplot_alias = m.group(1)

m = re.match(pyplot_alias + r".show\(\)", line)
if m:
line = line[:m.start()] + pyplot_alias + ".savefig('" + str(fig_basename) + "." + str(fig_index) + ".png')" + line[m.end():]
fig_index += 1

result.append(line)

with open(sys.argv[1], "w") as f:
for line in result:
f.write(line)

0 comments on commit ebf1f66

Please sign in to comment.