Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/resources/jupyter/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import sys
import logging
import os
import inspect

TRACE = 25

Expand Down Expand Up @@ -40,4 +41,5 @@ def log_error(msg, exc_info = False):
logging.getLogger().log(logging.ERROR, msg, exc_info = exc_info, stack_info = not exc_info)

def trace(msg):
log(TRACE, msg)
prev_frame = inspect.stack()[1]
log(TRACE, "%s:%s - %s" % (prev_frame.filename, prev_frame.lineno, msg))
7 changes: 6 additions & 1 deletion src/resources/jupyter/notebook.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def set_env_vars(options):
os.environ["QUARTO_FIG_DPI"] = str(options["fig_dpi"])
os.environ["QUARTO_FIG_FORMAT"] = options["fig_format"]

def retrieve_nb_from_cache(nb, status, **kwargs):
def retrieve_nb_from_cache(nb, status, input, **kwargs):
cache = kwargs["cache"]
# are we using the cache, if so connect to the cache, and then if we aren't in 'refresh'
# (forced re-execution) mode then try to satisfy the execution request from the cache
Expand Down Expand Up @@ -464,22 +464,27 @@ def nb_language_cell(name, kernelspec, resource_dir, allow_empty, **args):

def nb_from_cache(nb, nb_cache, nb_meta = ("kernelspec", "language_info", "widgets")):
try:
trace("nb_from_cache match")
cache_record = nb_cache.match_cache_notebook(nb)
trace("nb_from_cache get buncle")
cache_bundle = nb_cache.get_cache_bundle(cache_record.pk)
cache_nb = cache_bundle.nb
nb = copy.deepcopy(nb)
# selected (execution-oriented) metadata
trace("nb_from_cache processing metadata")
if nb_meta is None:
nb.metadata = cache_nb.metadata
else:
for key in nb_meta:
if key in cache_nb.metadata:
nb.metadata[key] = cache_nb.metadata[key]
# code cells
trace("nb_from_cache processing cells")
for idx in range(len(nb.cells)):
if nb.cells[idx].cell_type == "code":
cache_cell = cache_nb.cells.pop(0)
nb.cells[idx] = cache_cell
trace("nb_from_cache returning")
return nb
except KeyError:
return None
Expand Down
1 change: 1 addition & 0 deletions tests/Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ ipyleaflet = "*"
seaborn = "*"
shiny = "*"
itables = "*"
jupyter-cache = "*"

[dev-packages]

Expand Down
599 changes: 373 additions & 226 deletions tests/Pipfile.lock

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions tests/docs/jupyter/cache/test.qmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
title: test1
cache: true
---

```{python}
1+1
```
24 changes: 24 additions & 0 deletions tests/smoke/jupyter/cache.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* cache.test.ts
*
* Copyright (C) 2023 Posit Software, PBC
*/
import { quarto } from "../../../src/quarto.ts";
import { test } from "../../test.ts";
import { assertEquals } from "testing/asserts.ts";

test({
name: "jupyter:cache:test-1",
context: {},
execute: async () => {
// return await new Promise((_resolve, reject) => {
// setTimeout(reject, 10000, "timed out after 10 seconds");
// })
// https://github.com/quarto-dev/quarto-cli/issues/9618
// repeated executions to trigger jupyter cache
await quarto(["render", "docs/jupyter/cache/test.qmd", "--no-execute-daemon"]);
await quarto(["render", "docs/jupyter/cache/test.qmd", "--no-execute-daemon"]);
},
verify: [],
type: "smoke",
});
2 changes: 1 addition & 1 deletion tests/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ export function test(test: TestDescriptor) {
try {
await test.execute();
} catch (e) {
logError(e)
logError(e);
}

// Cleanup the output logging
Expand Down