Skip to content

Commit a542089

Browse files
committed
correct check for shiny server python
1 parent 5c445b9 commit a542089

File tree

3 files changed

+26
-16
lines changed

3 files changed

+26
-16
lines changed

src/command/preview/cmd.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ import { Format } from "../../config/types.ts";
5050
import { isServerShiny, isServerShinyPython } from "../../core/render.ts";
5151
import { previewShiny } from "./preview-shiny.ts";
5252
import { serve } from "../serve/serve.ts";
53+
import { fileExecutionEngine } from "../../execute/engine.ts";
5354

5455
export const previewCommand = new Command()
5556
.name("preview")
@@ -280,7 +281,8 @@ export const previewCommand = new Command()
280281
const renderFormat = (await renderFormats(file, format, project))
281282
?.[format] as Format | undefined;
282283
if (renderFormat && isServerShiny(renderFormat)) {
283-
if (isServerShinyPython(renderFormat)) {
284+
const engine = fileExecutionEngine(file, flags);
285+
if (isServerShinyPython(renderFormat, engine?.name)) {
284286
const result = await previewShiny({
285287
input: file,
286288
render: !!options.render,

src/core/render.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,10 @@ export function isServerShiny(format?: Format) {
3030
return server?.["type"] === "shiny";
3131
}
3232

33-
export function isServerShinyPython(format?: Format, engine?: string) {
33+
export function isServerShinyPython(
34+
format: Format,
35+
engine: string | undefined,
36+
) {
3437
return isServerShiny(format) && engine === kJupyterEngine;
3538
}
3639

src/execute/jupyter/jupyter.ts

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,11 @@ import {
100100
markdownFromJupyterPercentScript,
101101
} from "./percent.ts";
102102
import { execProcess } from "../../core/process.ts";
103-
import { inputFilesDir, isServerShinyPython } from "../../core/render.ts";
103+
import {
104+
inputFilesDir,
105+
isServerShiny,
106+
isServerShinyPython,
107+
} from "../../core/render.ts";
104108
import { jupyterCapabilities } from "../../core/jupyter/capabilities.ts";
105109

106110
export const jupyterEngine: ExecutionEngine = {
@@ -512,19 +516,20 @@ export const jupyterEngine: ExecutionEngine = {
512516

513517
postRender: async (files: RenderResultFile[], _context?: ProjectContext) => {
514518
// discover non _files dir resources for server: shiny and ammend app.py with them
515-
files.filter((file) => isServerShinyPython(file.format)).forEach((file) => {
516-
const [dir, stem] = dirAndStem(file.input);
517-
const filesDir = join(dir, inputFilesDir(file.input));
518-
const extraResources = file.resourceFiles
519-
.filter((resource) => !resource.startsWith(filesDir))
520-
.map((resource) => relative(dir, resource));
521-
const appScript = join(dir, `${stem}-app.py`);
522-
if (existsSync(appScript)) {
523-
// TODO: extraResoures is an array of relative paths to resources
524-
// that are NOT in the _files dir. these should be injected into
525-
// the appropriate place in appScript
526-
}
527-
});
519+
files.filter((file) => isServerShiny(file.format))
520+
.forEach((file) => {
521+
const [dir, stem] = dirAndStem(file.input);
522+
const filesDir = join(dir, inputFilesDir(file.input));
523+
const extraResources = file.resourceFiles
524+
.filter((resource) => !resource.startsWith(filesDir))
525+
.map((resource) => relative(dir, resource));
526+
const appScript = join(dir, `${stem}-app.py`);
527+
if (existsSync(appScript)) {
528+
// TODO: extraResoures is an array of relative paths to resources
529+
// that are NOT in the _files dir. these should be injected into
530+
// the appropriate place in appScript
531+
}
532+
});
528533
},
529534

530535
postprocess: (options: PostProcessOptions) => {

0 commit comments

Comments
 (0)