Skip to content

Commit 4ddd5bc

Browse files
committed
update fileInformationCache based on keep-ipynb
1 parent 7e98950 commit 4ddd5bc

File tree

4 files changed

+27
-11
lines changed

4 files changed

+27
-11
lines changed

src/command/render/render-contexts.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ export async function renderContexts(
298298

299299
// if this isn't for execute then cleanup context
300300
if (!forExecute && engine.executeTargetSkipped) {
301-
engine.executeTargetSkipped(target, formats[formatKey].format);
301+
engine.executeTargetSkipped(target, formats[formatKey].format, project);
302302
}
303303
}
304304
return contexts;

src/command/render/render-files.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,11 @@ export async function renderExecute(
200200

201201
// notify engine that we skipped execute
202202
if (context.engine.executeTargetSkipped) {
203-
context.engine.executeTargetSkipped(context.target, context.format);
203+
context.engine.executeTargetSkipped(
204+
context.target,
205+
context.format,
206+
context.project,
207+
);
204208
}
205209

206210
// return results

src/execute/jupyter/jupyter.ts

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import { readYamlFromMarkdown } from "../../core/yaml.ts";
1717
import { isInteractiveSession } from "../../core/platform.ts";
1818
import { partitionMarkdown } from "../../core/pandoc/pandoc-partition.ts";
1919

20-
import { dirAndStem, normalizePath, removeIfExists } from "../../core/path.ts";
20+
import { dirAndStem, normalizePath } from "../../core/path.ts";
2121
import { runningInCI } from "../../core/ci-info.ts";
2222

2323
import {
@@ -109,7 +109,10 @@ import {
109109
import { jupyterCapabilities } from "../../core/jupyter/capabilities.ts";
110110
import { runExternalPreviewServer } from "../../preview/preview-server.ts";
111111
import { onCleanup } from "../../core/cleanup.ts";
112-
import { projectOutputDir } from "../../project/project-shared.ts";
112+
import {
113+
ensureFileInformationCache,
114+
projectOutputDir,
115+
} from "../../project/project-shared.ts";
113116
import { assert } from "testing/asserts";
114117

115118
export const jupyterEngine: ExecutionEngine = {
@@ -436,7 +439,7 @@ export const jupyterEngine: ExecutionEngine = {
436439

437440
// if it's a transient notebook then remove it
438441
// (unless keep-ipynb was specified)
439-
cleanupNotebook(options.target, options.format);
442+
cleanupNotebook(options.target, options.format, options.project);
440443

441444
// Create markdown from the result
442445
const outputs = result.cellOutputs.map((output) => output.markdown);
@@ -713,12 +716,17 @@ async function disableDaemonForNotebook(target: ExecutionTarget) {
713716
return false;
714717
}
715718

716-
function cleanupNotebook(target: ExecutionTarget, format: Format) {
717-
// remove transient notebook if appropriate
719+
function cleanupNotebook(
720+
target: ExecutionTarget,
721+
format: Format,
722+
project: ProjectContext,
723+
) {
724+
// Make notebook non-transient when keep-ipynb is set
718725
const data = target.data as JupyterTargetData;
719-
if (data.transient) {
720-
if (!format.execute[kKeepIpynb]) {
721-
removeIfExists(target.input);
726+
const cached = ensureFileInformationCache(project, target.source);
727+
if (data.transient && format.execute[kKeepIpynb]) {
728+
if (cached.target && cached.target.data) {
729+
(cached.target.data as JupyterTargetData).transient = false;
722730
}
723731
}
724732
}

src/execute/types.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,11 @@ export interface ExecutionEngine {
4949
format: Format,
5050
) => Format;
5151
execute: (options: ExecuteOptions) => Promise<ExecuteResult>;
52-
executeTargetSkipped?: (target: ExecutionTarget, format: Format) => void;
52+
executeTargetSkipped?: (
53+
target: ExecutionTarget,
54+
format: Format,
55+
project: ProjectContext,
56+
) => void;
5357
dependencies: (options: DependenciesOptions) => Promise<DependenciesResult>;
5458
postprocess: (options: PostProcessOptions) => Promise<void>;
5559
canFreeze: boolean;

0 commit comments

Comments
 (0)