Skip to content

Commit

Permalink
customize nb2w cache (#106)
Browse files Browse the repository at this point in the history
  • Loading branch information
volodymyrss authored Sep 11, 2023
1 parent 4f8544b commit ac6605a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
5 changes: 3 additions & 2 deletions nb2workflow/nbadapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -544,8 +544,9 @@ def inject_output_gathering(self):
sb.glue(variable_name + "_content", encoded)
else:
# TODO: make a customizable upload to different DL platforms; before that it should be enabled with caution
os.makedirs("/tmp/nb2w-store", exist_ok=True)
url = "file:///tmp/nb2w-store/" + str(hashlib.md5(content).hexdigest())
nb2w_store_base = os.getenv("NB2W_CACHE", os.getenv("HOME") + "/.cache/nb2workflow/bigoutputs")
os.makedirs(nb2w_store_base, exist_ok=True)
url = "file://" + nb2w_store_base + "/" + str(hashlib.md5(content).hexdigest())
print("storing file to URL", url)
with open(url.replace("file://", ""), "wb") as f:
f.write(content)
Expand Down
5 changes: 2 additions & 3 deletions tests/test_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,7 @@ def test_nb_attach_file(test_notebook, limit):
assert 'spectrum_png_content' in r
else:
assert 'spectrum_png_url' in r
assert r['spectrum_png_url'].startswith("file:///tmp/nb2w-store/")
assert "cache/nb2workflow/bigoutputs" in r['spectrum_png_url']

assert r['energies_fits_file'] == "energies.fits"
assert r['energies_fits_file_url'].startswith("file:///tmp/nb2w-store/")

assert "cache/nb2workflow/bigoutputs" in r['energies_fits_file_url']

0 comments on commit ac6605a

Please sign in to comment.