Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

馃悰 Set notebook path relative to session manager path #1078

Merged
merged 4 commits into from
Apr 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/tiny-bikes-invite.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"myst-execute": patch
"myst-cli": patch
---

Define kernel path relative to server base-path
1 change: 1 addition & 0 deletions packages/myst-cli/src/process/mdast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ export async function transformMdast(
if (execute) {
const cachePath = path.join(session.buildPath(), 'execute');
await kernelExecutionTransform(mdast, vfile, {
basePath: session.sourcePath(),
cache: new LocalDiskCache<(IExpressionResult | IOutput[])[]>(cachePath),
sessionFactory: () => session.jupyterSessionManager(),
frontmatter: frontmatter,
Expand Down
1 change: 1 addition & 0 deletions packages/myst-cli/src/session/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export type ISession = {
log: Logger;
reload(): ISession;
clone(): ISession;
sourcePath(): string;
buildPath(): string;
sitePath(): string;
contentPath(): string;
Expand Down
3 changes: 2 additions & 1 deletion packages/myst-execute/src/execute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@ function applyComputedOutputsToNodes(
}

export type Options = {
basePath: string;
cache: ICache<(IExpressionResult | IOutput[])[]>;
sessionFactory: () => Promise<SessionManager | undefined>;
frontmatter: PageFrontmatter;
Expand Down Expand Up @@ -309,7 +310,7 @@ export async function kernelExecutionTransform(tree: GenericParent, vfile: VFile
else {
let sessionConnection: Session.ISessionConnection | undefined;
const sessionOpts = {
path: vfile.path,
path: path.relative(opts.basePath, vfile.path),
type: 'notebook',
name: path.basename(vfile.path),
kernel: {
Expand Down
25 changes: 19 additions & 6 deletions packages/myst-execute/src/manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,21 @@ export async function launchJupyterServer(
const proc = spawn(pythonPath, ['-m', 'jupyter_server', '--ServerApp.root_dir', contentPath]);

const reader = proc.stderr;

let timerID: ReturnType<typeof setTimeout> | undefined;
const settings = await new Promise<JupyterServerSettings>((resolve, reject) => {
// Fail after 20 seconds of nothing happening
const id = setTimeout(() => {
log.error(`馃獝 ${chalk.redBright('Jupyter server did not respond')}\n ${chalk.dim(url)}`);
timerID = setTimeout(() => {
log.error(`馃獝 ${chalk.redBright('Jupyter server did not respond')}`);
reject();
}, 20_000);

// Fail because process exits
proc.on('exit', () => {
log.error(`馃獝 ${chalk.redBright('Jupyter server did not start')}`);
reject();
});

reader.on('data', (buf) => {
const data = buf.toString();
// Wait for server to declare itself up
Expand All @@ -97,9 +105,6 @@ export async function launchJupyterServer(
// Pull out the match information
const [, addr, token] = match;

// Cancel timeout error now
clearTimeout(id);

// Resolve the promise
resolve({
baseUrl: addr,
Expand All @@ -108,7 +113,15 @@ export async function launchJupyterServer(
});
}).finally(
// Don't keep listening to messages
() => reader.removeAllListeners('data'),
() => {
reader.removeAllListeners('data');
proc.removeAllListeners('exit');

// Cancel timeout error now
if (timerID !== undefined) {
clearTimeout(timerID);
}
},
);

// Inform log
Expand Down
1 change: 1 addition & 0 deletions packages/myst-execute/tests/run.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ casesList.forEach(({ title, cases }) => {
file.path = path.join(__dirname, 'notebook.ipynb');

await kernelExecutionTransform(before, file, {
basePath: __dirname,
sessionFactory: async () => await sessionManagerFactory.load(),
cache: noOpCache,
frontmatter: {
Expand Down