gpoore / codebraid

Live code in Pandoc Markdown
BSD 3-Clause "New" or "Revised" License
376 stars 13 forks source link

Overly aggressive caching #57

Closed erooke closed 2 years ago

erooke commented 2 years ago

If a file fails to run code due to a failed import codebraid will not try to run that code again until the cache is cleared.

If we have the following file test.md

```{.python .cb-nb}
import numpy as np
and compile it with the command
```sh
codebraid pandoc -f markdown -t markdown -o out.md test.md 

if numpy is not available in the environment we get the following out.md

``` {.python .numberLines startFrom="1"}
import numpy as np
Traceback (most recent call last):
  File "source.py", line 1, in <module>
    import numpy as np
ModuleNotFoundError: No module named 'numpy'

realizing our mistake we install numpy and attempt to recompile
```sh
pip install numpy
codebraid pandoc -f markdown -t markdown -o out.md test.md --overwrite

we will get the exact same out.md. Clearing the cache with rm -rf _codebraid and rerunning corrects the error.

This is very non-obvious behavior to me. I would expect any code block which failed to run to be re-run on the next attempt.

gpoore commented 2 years ago

That's a bug. These sorts of cases are cached so that the output is as complete as possible if code execution is disabled on a subsequent run, but I need to add cache invalidation for these cases whenever code execution is permitted. It looks like just a few small changes should fix this.

gpoore commented 2 years ago

This should be fixed in the dev version on GitHub. A new release including this will be on PyPI soon.

erooke commented 2 years ago

Thanks! This is fixed on my end using the GitHub version