Skip to content

Commit

Permalink
🚫 Add page frontmatter option to disable execution (#1842)
Browse files Browse the repository at this point in the history
  • Loading branch information
agoose77 authored Feb 6, 2025
1 parent 03d35f1 commit 7448083
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 2 deletions.
6 changes: 6 additions & 0 deletions .changeset/dirty-ducks-tie.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"myst-frontmatter": patch
"myst-cli": patch
---

Add support for skipping execution of individual notebooks
18 changes: 18 additions & 0 deletions docs/execute-notebooks.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,24 @@ name = input("What is your name?")

Additional [cell tags](#tbl:notebook-cell-tags) to hide, remove, or raise exceptions are also possible.

## Skip entire notebooks

You may wish to disable execution for certain notebooks. This can be done by setting the top-level `skip_execution` frontmatter option to `true`, e.g.

````markdown
---
kernelspec:
name: python3
display_name: Python 3

skip_execution: true
---

```{code-cell}
print("This will never be executed!")
```
````

## Cache execution outputs

When MyST executes your notebook, it will store the outputs in a cache in a folder called `execute/` in your MyST build folder.
Expand Down
5 changes: 4 additions & 1 deletion docs/frontmatter.md
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,9 @@ The following table lists the available frontmatter fields, a brief description
* - `kernelspec`
- configuration for the kernel (see [](#kernel-specification))
- page only
* - `skip_execution`
- opt-out of execution for a particular document (see [](./execute-notebooks))
- page only
```
+++
Expand Down Expand Up @@ -850,4 +853,4 @@ These fields provide a more complete superset of publication metadata than the [
> Old-timey bibliographic info for this work. This is mostly useful only in citation/reference contexts. These are all strings because sometimes you'll get fun values like "Spring" and "Inside cover."
If MyST frontmatter includes an OpenAlex `biblio` object, it will be coerced to valid publication metadata.
If MyST frontmatter includes an OpenAlex `biblio` object, it will be coerced to valid publication metadata.
2 changes: 1 addition & 1 deletion packages/myst-cli/src/process/mdast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ export async function transformMdast(
// Combine file-specific citation renderers with project renderers from bib files
const fileCitationRenderer = combineCitationRenderers(cache, ...rendererFiles);

if (execute) {
if (execute && !frontmatter.skip_execution) {
const cachePath = path.join(session.buildPath(), 'execute');
await kernelExecutionTransform(mdast, vfile, {
basePath: session.sourcePath(),
Expand Down
3 changes: 3 additions & 0 deletions packages/myst-frontmatter/src/page/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export const PAGE_FRONTMATTER_KEYS = [
'site',
'enumerator',
'content_includes_title',
'skip_execution',
];

export type PageFrontmatter = ProjectAndPageFrontmatter & {
Expand All @@ -21,6 +22,8 @@ export type PageFrontmatter = ProjectAndPageFrontmatter & {
jupytext?: Jupytext;
tags?: string[];
enumerator?: string;
// Disable execution for this page
skip_execution?: boolean;
/** Flag if frontmatter title is duplicated in content
*
* Set during initial file/frontmatter load
Expand Down
6 changes: 6 additions & 0 deletions packages/myst-frontmatter/src/page/validators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ export function validatePageFrontmatterKeys(value: Record<string, any>, opts: Va
if (defined(value.jupytext)) {
output.jupytext = validateJupytext(value.jupytext, incrementOptions('jupytext', opts));
}
if (defined(value.skip_execution)) {
output.skip_execution = validateBoolean(
value.skip_execution,
incrementOptions('skip_execution', opts),
);
}
if (defined(value.enumerator)) {
output.enumerator = validateString(value.enumerator, incrementOptions('enumerator', opts));
}
Expand Down

0 comments on commit 7448083

Please sign in to comment.