|
5 | 5 | */ |
6 | 6 |
|
7 | 7 | import { dirname, join, relative } from "path/mod.ts"; |
| 8 | +import { satisfies } from "semver/mod.ts"; |
8 | 9 |
|
9 | 10 | import { existsSync } from "fs/mod.ts"; |
10 | 11 |
|
| 12 | +import { error, info } from "log/mod.ts"; |
| 13 | + |
11 | 14 | import * as ld from "../../core/lodash.ts"; |
12 | 15 |
|
13 | 16 | import { readYamlFromMarkdown } from "../../core/yaml.ts"; |
@@ -98,6 +101,7 @@ import { |
98 | 101 | } from "./percent.ts"; |
99 | 102 | import { execProcess } from "../../core/process.ts"; |
100 | 103 | import { inputFilesDir, isServerShinyPython } from "../../core/render.ts"; |
| 104 | +import { jupyterCapabilities } from "../../core/jupyter/capabilities.ts"; |
101 | 105 |
|
102 | 106 | export const jupyterEngine: ExecutionEngine = { |
103 | 107 | name: kJupyterEngine, |
@@ -431,6 +435,36 @@ export const jupyterEngine: ExecutionEngine = { |
431 | 435 | }, |
432 | 436 |
|
433 | 437 | 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 | + |
434 | 468 | let running = false; |
435 | 469 | const [_dir, stem] = dirAndStem(options.input); |
436 | 470 | const appFile = `${stem}-app.py`; |
|
0 commit comments