Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Write Your Python Program - CHANGELOG

* 2.0.6 (2025-10-08)
* Settings for language #180
* Only warn of settings cannot be saved #182
* Remove unnecessary warning line #181
* 2.0.1 - 2.0.5 (2025-09-24)
* Many minor fixes
* 2.0.0 (2025-09-24)
Expand Down
8 changes: 7 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"displayName": "Write Your Python Program!",
"description": "A user friendly python environment for beginners",
"license": "See license in LICENSE",
"version": "2.0.5",
"version": "2.0.6",
"publisher": "StefanWehr",
"icon": "icon.png",
"engines": {
Expand Down Expand Up @@ -68,6 +68,12 @@
"type": "boolean",
"required": false,
"description": "Disable checking of type annotations."
},
"write-your-python-program.language": {
"type": "string",
"enum": ["german", "english", "system default"],
"default": "system default",
"description": "Choose the language for error messages."
}
}
}
Expand Down
2 changes: 0 additions & 2 deletions python/code/wypp/i18n.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,6 @@ def tr(key: str, **kws) -> str:
'all successful': 'alle erfolgreich',
'and stop of execution': 'und Abbruch der Ausführung',

'NOTE: running the code failed, some definitions might not be available in the interactive window!':
'ACHTUNG: Das Ausführen des Codes ist fehlgeschlagen; einige Definitionen sind möglicherweise im interaktiven Fenster nicht verfügbar!',
'=== WELCOME to ': '=== WILLKOMMEN bei '
}

Expand Down
3 changes: 0 additions & 3 deletions python/code/wypp/interactive.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,6 @@ def enterInteractive(userDefs: dict, checkTypes: bool, loadingFailed: bool):
for k, v in userDefs.items():
globals()[k] = v
print()
if loadingFailed:
print(i18n.tr('NOTE: running the code failed, some definitions might not be available in the interactive window!'))
print()
if checkTypes:
consoleClass = TypecheckedInteractiveConsole
else:
Expand Down
80 changes: 63 additions & 17 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const extensionId = 'write-your-python-program';
const python3ConfigKey = 'python3Cmd';
const verboseConfigKey = 'verbose';
const debugConfigKey = 'debug';
const languageKey = 'language';
const disableTypecheckingConfigKey = 'disableTypechecking';
const isWindows = process.platform === "win32";
const exeExt = isWindows ? ".exe" : "";
Expand Down Expand Up @@ -217,6 +218,19 @@ function disableTypechecking(context: vscode.ExtensionContext): boolean {
return !!config[disableTypecheckingConfigKey];
}

function getLanguage(context: vscode.ExtensionContext): 'en' | 'de' | undefined {
const config = vscode.workspace.getConfiguration(extensionId);
const lang = config[languageKey];
if (lang === 'english') {
return 'en';
} else if (lang === 'german') {
return 'de';
} else {
return undefined;
}
}


async function fixPylanceConfig(
context: vscode.ExtensionContext,
folder?: vscode.WorkspaceFolder
Expand All @@ -231,6 +245,30 @@ async function fixPylanceConfig(
const target = folder ? vscode.ConfigurationTarget.WorkspaceFolder
: vscode.ConfigurationTarget.Workspace;

const errors: string[] = [];

// Two special errors
const noWorkspaceOpen = '__NO_WORKSPACE_OPEN__';

// helper to update config and collect errors; treat "no folder open" specially
async function tryUpdate(key: string, value: any) {
// If target is workspace-wide and there is no workspace open at all
const workspaceFolders = vscode.workspace.workspaceFolders;
if (!workspaceFolders || workspaceFolders.length === 0) {
// nothing to update at workspace level
errors.push(noWorkspaceOpen);
return;
}

try {
await cfg.update(key, value, target);
} catch (e) {
// If the error message explicitly mentions the workspace/folder, capture it, but prefer the proactive checks above
const msg = e instanceof Error ? e.message : String(e);
errors.push(`Failed to update ${key}: ${msg}`);
}
}

// wildcard warnings
const keyOverride = 'analysis.diagnosticSeverityOverrides';
const overrides = cfg.get<Record<string, string>>(keyOverride) ?? {};
Expand All @@ -239,33 +277,36 @@ async function fixPylanceConfig(
...overrides,
reportWildcardImportFromLibrary: 'none',
};
await cfg.update(
'analysis.diagnosticSeverityOverrides',
updated,
target
);
await tryUpdate(keyOverride, updated);
}

// extraPaths
const keyExtraPaths = 'analysis.extraPaths';
const extra = cfg.get<string[]>(keyExtraPaths) ?? [];
if (extra.length !== 1 || extra[0] !== libDir) {
await cfg.update(
keyExtraPaths,
[libDir],
target
);
await tryUpdate(keyExtraPaths, [libDir]);
}

// typechecking off
const keyMode = 'analysis.typeCheckingMode';
const mode = cfg.get<string>(keyMode) ?? '';
if (mode !== 'off') {
await cfg.update(
'analysis.typeCheckingMode',
'off',
target
);
await tryUpdate(keyMode, 'off');
}

if (errors.length > 0) {
let msg: string;
if (errors.every(e => e === noWorkspaceOpen)) {
msg = 'Write Your Python Program: settings were not changed because no folder is open. Open a folder to apply wypp settings.';
} else {
const sanitized = errors.map(e => e === noWorkspaceOpen ? 'Skipped workspace update because no folder is open' : e);
msg = `Write Your Python Program: failed to update settings. ` + sanitized.join('. ');
}
try {
vscode.window.showWarningMessage(msg);
} catch (_e) {
// ignore any error while showing the warning
}
}
}

Expand Down Expand Up @@ -386,7 +427,6 @@ export async function activate(context: vscode.ExtensionContext) {
"run",
"▶ RUN",
async (cmdId) => {
await fixPylanceConfig(context);
const file =
(vscode.window.activeTextEditor) ?
vscode.window.activeTextEditor.document.fileName :
Expand All @@ -399,6 +439,7 @@ export async function activate(context: vscode.ExtensionContext) {
vscode.window.showWarningMessage('Not a python file');
return;
}
await fixPylanceConfig(context);
await vscode.window.activeTextEditor?.document.save();
const pyCmd = getPythonCmd(pyExt);
let verboseOpt = "";
Expand All @@ -410,14 +451,19 @@ export async function activate(context: vscode.ExtensionContext) {
if (verboseOpt !== "") {
verboseOpt = " " + verboseOpt + " --no-clear";
}
const lang = getLanguage(context);
let langOpt = "";
if (lang) {
langOpt = " --lang " + lang;
}
const disableOpt = disableTypechecking(context) ? " --no-typechecking" : "";
if (pyCmd.kind !== "error") {
const pythonCmd = commandListToArgument(pyCmd.cmd);
const cmdTerm = await startTerminal(
terminals[cmdId]?.terminal,
"WYPP - RUN",
pythonCmd + " " + fileToCommandArgument(runProg) + verboseOpt +
disableOpt +
disableOpt + langOpt +
" --interactive " +
" --change-directory " +
fileToCommandArgument(file)
Expand Down