Skip to content

Commit bd915ad

Browse files
authored
Cache remote files for tests (#2313)
Cache remote files for tests locally via pooch, and cache the pooch cache for GitHub actions. Today, I had dozens of workflow failures due to rate-limiting or unavailability of biomodels. This is avoidable.
1 parent eda7ad0 commit bd915ad

File tree

4 files changed

+34
-21
lines changed

4 files changed

+34
-21
lines changed

.github/workflows/test_python_cplusplus.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,13 @@ jobs:
1818
python-version: [ "3.9" ]
1919

2020
steps:
21+
- name: Cache
22+
uses: actions/cache@v3
23+
with:
24+
path: |
25+
~/.cache/pooch
26+
key: ${{ runner.os }}-py${{ matrix.python-version }}-${{ github.job }}
27+
2128
- name: Set up Python ${{ matrix.python-version }}
2229
uses: actions/setup-python@v5
2330
with:
@@ -265,6 +272,13 @@ jobs:
265272
runs-on: macos-latest
266273

267274
steps:
275+
- name: Cache
276+
uses: actions/cache@v3
277+
with:
278+
path: |
279+
~/Library/Caches/pooch
280+
key: ${{ runner.os }}-py${{ matrix.python-version }}-${{ github.job }}
281+
268282
- name: Set up Python
269283
uses: actions/setup-python@v5
270284
with:

python/sdist/setup.cfg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ test =
6262
# unsupported x86_64 / x86_64h
6363
antimony!=2.14; platform_system=='Darwin' and platform_machine in 'x86_64h'
6464
scipy
65+
pooch
6566
vis =
6667
matplotlib
6768
seaborn

python/tests/test_conserved_quantities_demartino.py

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -155,15 +155,15 @@
155155
def data_demartino2014():
156156
"""Get tests from DeMartino2014 Suppl. Material"""
157157
import gzip
158-
import io
159-
import urllib.request
158+
import pooch
160159

161160
# stoichiometric matrix
162-
response = urllib.request.urlopen(
163-
r"https://github.com/AMICI-dev/AMICI/files/11430971/DeMartinoDe2014_test-ecoli.dat.gz",
164-
timeout=10,
161+
data = gzip.GzipFile(
162+
pooch.retrieve(
163+
"https://github.com/AMICI-dev/AMICI/files/11430971/DeMartinoDe2014_test-ecoli.dat.gz",
164+
known_hash="md5:899873f8f1c413d13c3f8e94c1496b7e",
165+
)
165166
)
166-
data = gzip.GzipFile(fileobj=io.BytesIO(response.read()))
167167
S = [
168168
int(item)
169169
for sl in [
@@ -174,14 +174,13 @@ def data_demartino2014():
174174
]
175175

176176
# metabolite / row names
177-
response = urllib.request.urlopen(
178-
r"https://github.com/AMICI-dev/AMICI/files/11430970/test-ecoli-met.txt",
179-
timeout=10,
180-
)
181-
row_names = [
182-
entry.decode("ascii").strip() for entry in io.BytesIO(response.read())
183-
]
184-
177+
with open(
178+
pooch.retrieve(
179+
"https://github.com/AMICI-dev/AMICI/files/11430970/test-ecoli-met.txt",
180+
known_hash="md5:d71e711a3655311390b38d00dcd6aa7f",
181+
)
182+
) as f:
183+
row_names = [entry.strip() for entry in f.readlines()]
185184
return S, row_names
186185

187186

python/tests/test_sbml_import.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import re
44
from numbers import Number
55
from pathlib import Path
6-
from urllib.request import urlopen
76

87
import amici
98
import libsbml
@@ -543,13 +542,13 @@ def test_sympy_exp_monkeypatch():
543542
monkeypatching sympy.Pow._eval_derivative in order to be able to compute
544543
non-nan sensitivities
545544
"""
546-
url = (
547-
"https://www.ebi.ac.uk/biomodels/model/download/BIOMD0000000529.2?"
548-
"filename=BIOMD0000000529_url.xml"
549-
)
550-
importer = amici.SbmlImporter(
551-
urlopen(url, timeout=20).read().decode("utf-8"), from_file=False
545+
import pooch
546+
547+
model_file = pooch.retrieve(
548+
url="https://www.ebi.ac.uk/biomodels/model/download/BIOMD0000000529.2?filename=BIOMD0000000529_url.xml",
549+
known_hash="md5:c6e0b298397485b93d7acfab80b21fd4",
552550
)
551+
importer = amici.SbmlImporter(model_file)
553552
module_name = "BIOMD0000000529"
554553

555554
with TemporaryDirectory() as outdir:

0 commit comments

Comments
 (0)