Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion source/vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@
"notebook/cell/title": [
{
"command": "qsharp-vscode.learningNotebookExplain",
"when": "notebookType == 'jupyter-notebook' && qsharp-vscode.learningWorkspaceDetected",
"when": "qsharp-vscode.learningNotebookActive",
"group": "inline/cell@50"
}
],
Expand Down
15 changes: 14 additions & 1 deletion source/vscode/src/learning/python/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ import type {
import { PythonEnvironments } from "@vscode/python-environments";
import * as vscode from "vscode";

/**
* Dotted Python module name. Import checks come from author-supplied
* `course.json`, and reach a `python -c` command line.
*/
const MODULE_NAME = /^[A-Za-z_]\w*(\.[A-Za-z_]\w*)*$/;

/**
* Manages per-course Python environments for `python-notebook` courses.
*
Expand Down Expand Up @@ -146,6 +152,11 @@ export class EnvironmentManager {

const results: { module: string; ok: boolean }[] = [];
for (const module of modules) {
if (!MODULE_NAME.test(module)) {
log.warn(`Not a valid Python module name, skipping: ${module}`);
results.push({ module, ok: false });
continue;
}
const code = await runPython(api, env, ["-c", `import ${module}`]);
results.push({ module, ok: code === 0 });
}
Expand Down Expand Up @@ -196,7 +207,9 @@ export class EnvironmentManager {
return envs[0];
default:
log.warn(
`Found multiple virtual environments, using first: ${envs.join(", ")}`,
`Found multiple virtual environments, using first: ${envs
.map((e) => e.name)
.join(", ")}`,
);
return envs[0];
}
Expand Down