Skip to content

Commit 5c445b9

Browse files
committed
verify shiny package version
1 parent deed090 commit 5c445b9

File tree

3 files changed

+36
-0
lines changed

3 files changed

+36
-0
lines changed

src/core/jupyter/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ export interface JupyterCapabilities {
6666
nbformat: string | null;
6767
nbclient: string | null;
6868
ipykernel: string | null;
69+
shiny: string | null;
6970
}
7071

7172
export interface JupyterCapabilitiesEx extends JupyterCapabilities {

src/execute/jupyter/jupyter.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,12 @@
55
*/
66

77
import { dirname, join, relative } from "path/mod.ts";
8+
import { satisfies } from "semver/mod.ts";
89

910
import { existsSync } from "fs/mod.ts";
1011

12+
import { error, info } from "log/mod.ts";
13+
1114
import * as ld from "../../core/lodash.ts";
1215

1316
import { readYamlFromMarkdown } from "../../core/yaml.ts";
@@ -98,6 +101,7 @@ import {
98101
} from "./percent.ts";
99102
import { execProcess } from "../../core/process.ts";
100103
import { inputFilesDir, isServerShinyPython } from "../../core/render.ts";
104+
import { jupyterCapabilities } from "../../core/jupyter/capabilities.ts";
101105

102106
export const jupyterEngine: ExecutionEngine = {
103107
name: kJupyterEngine,
@@ -431,6 +435,36 @@ export const jupyterEngine: ExecutionEngine = {
431435
},
432436

433437
run: async (options: RunOptions): Promise<void> => {
438+
// semver doesn't support 4th component
439+
const asSemVer = (version: string) => {
440+
const v = version.split(".");
441+
if (v.length > 3) {
442+
return `${v[0]}.${v[1]}.${v.slice(2).join("")}`;
443+
} else {
444+
return version;
445+
}
446+
};
447+
448+
// confirm required version of shiny
449+
const kShinyVersion = ">=0.5.1.9002";
450+
let shinyError: string | undefined;
451+
const caps = await jupyterCapabilities();
452+
if (!caps?.shiny) {
453+
shinyError =
454+
"The shiny package is required for documents with server: shiny";
455+
} else if (!satisfies(asSemVer(caps.shiny), asSemVer(kShinyVersion))) {
456+
shinyError =
457+
`The shiny package version must be ${kShinyVersion} for documents with server: shiny`;
458+
}
459+
if (shinyError) {
460+
shinyError +=
461+
"\n\nInstall the development version of the shiny package with: \n\n" +
462+
"pip install git+https://github.com/posit-dev/py-htmltools.git@html-text-doc#egg=htmltools\n" +
463+
"pip install git+https://github.com/posit-dev/py-shiny.git@quarto-ext#egg=shiny\n";
464+
error(shinyError);
465+
throw new Error();
466+
}
467+
434468
let running = false;
435469
const [_dir, stem] = dirAndStem(options.input);
436470
const appFile = `${stem}-app.py`;

src/resources/capabilities/jupyter.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,6 @@ def discover_package(pkg):
2525
discover_package('nbformat')
2626
discover_package('nbclient')
2727
discover_package('ipykernel')
28+
discover_package('shiny')
2829

2930

0 commit comments

Comments
 (0)