Skip to content

Commit 55bb1cd

Browse files
authored
Merge pull request #183 from skogsbaer/sw/fixes-2025-10-08
Minor fixes after first semester week
2 parents 314fccb + 9964788 commit 55bb1cd

File tree

5 files changed

+74
-23
lines changed

5 files changed

+74
-23
lines changed

ChangeLog.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Write Your Python Program - CHANGELOG
22

3+
* 2.0.6 (2025-10-08)
4+
* Settings for language #180
5+
* Only warn of settings cannot be saved #182
6+
* Remove unnecessary warning line #181
37
* 2.0.1 - 2.0.5 (2025-09-24)
48
* Many minor fixes
59
* 2.0.0 (2025-09-24)

package.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"displayName": "Write Your Python Program!",
44
"description": "A user friendly python environment for beginners",
55
"license": "See license in LICENSE",
6-
"version": "2.0.5",
6+
"version": "2.0.6",
77
"publisher": "StefanWehr",
88
"icon": "icon.png",
99
"engines": {
@@ -68,6 +68,12 @@
6868
"type": "boolean",
6969
"required": false,
7070
"description": "Disable checking of type annotations."
71+
},
72+
"write-your-python-program.language": {
73+
"type": "string",
74+
"enum": ["german", "english", "system default"],
75+
"default": "system default",
76+
"description": "Choose the language for error messages."
7177
}
7278
}
7379
}

python/code/wypp/i18n.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,6 @@ def tr(key: str, **kws) -> str:
155155
'all successful': 'alle erfolgreich',
156156
'and stop of execution': 'und Abbruch der Ausführung',
157157

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

python/code/wypp/interactive.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,6 @@ def enterInteractive(userDefs: dict, checkTypes: bool, loadingFailed: bool):
4141
for k, v in userDefs.items():
4242
globals()[k] = v
4343
print()
44-
if loadingFailed:
45-
print(i18n.tr('NOTE: running the code failed, some definitions might not be available in the interactive window!'))
46-
print()
4744
if checkTypes:
4845
consoleClass = TypecheckedInteractiveConsole
4946
else:

src/extension.ts

Lines changed: 63 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ const extensionId = 'write-your-python-program';
1313
const python3ConfigKey = 'python3Cmd';
1414
const verboseConfigKey = 'verbose';
1515
const debugConfigKey = 'debug';
16+
const languageKey = 'language';
1617
const disableTypecheckingConfigKey = 'disableTypechecking';
1718
const isWindows = process.platform === "win32";
1819
const exeExt = isWindows ? ".exe" : "";
@@ -217,6 +218,19 @@ function disableTypechecking(context: vscode.ExtensionContext): boolean {
217218
return !!config[disableTypecheckingConfigKey];
218219
}
219220

221+
function getLanguage(context: vscode.ExtensionContext): 'en' | 'de' | undefined {
222+
const config = vscode.workspace.getConfiguration(extensionId);
223+
const lang = config[languageKey];
224+
if (lang === 'english') {
225+
return 'en';
226+
} else if (lang === 'german') {
227+
return 'de';
228+
} else {
229+
return undefined;
230+
}
231+
}
232+
233+
220234
async function fixPylanceConfig(
221235
context: vscode.ExtensionContext,
222236
folder?: vscode.WorkspaceFolder
@@ -231,6 +245,30 @@ async function fixPylanceConfig(
231245
const target = folder ? vscode.ConfigurationTarget.WorkspaceFolder
232246
: vscode.ConfigurationTarget.Workspace;
233247

248+
const errors: string[] = [];
249+
250+
// Two special errors
251+
const noWorkspaceOpen = '__NO_WORKSPACE_OPEN__';
252+
253+
// helper to update config and collect errors; treat "no folder open" specially
254+
async function tryUpdate(key: string, value: any) {
255+
// If target is workspace-wide and there is no workspace open at all
256+
const workspaceFolders = vscode.workspace.workspaceFolders;
257+
if (!workspaceFolders || workspaceFolders.length === 0) {
258+
// nothing to update at workspace level
259+
errors.push(noWorkspaceOpen);
260+
return;
261+
}
262+
263+
try {
264+
await cfg.update(key, value, target);
265+
} catch (e) {
266+
// If the error message explicitly mentions the workspace/folder, capture it, but prefer the proactive checks above
267+
const msg = e instanceof Error ? e.message : String(e);
268+
errors.push(`Failed to update ${key}: ${msg}`);
269+
}
270+
}
271+
234272
// wildcard warnings
235273
const keyOverride = 'analysis.diagnosticSeverityOverrides';
236274
const overrides = cfg.get<Record<string, string>>(keyOverride) ?? {};
@@ -239,33 +277,36 @@ async function fixPylanceConfig(
239277
...overrides,
240278
reportWildcardImportFromLibrary: 'none',
241279
};
242-
await cfg.update(
243-
'analysis.diagnosticSeverityOverrides',
244-
updated,
245-
target
246-
);
280+
await tryUpdate(keyOverride, updated);
247281
}
248282

249283
// extraPaths
250284
const keyExtraPaths = 'analysis.extraPaths';
251285
const extra = cfg.get<string[]>(keyExtraPaths) ?? [];
252286
if (extra.length !== 1 || extra[0] !== libDir) {
253-
await cfg.update(
254-
keyExtraPaths,
255-
[libDir],
256-
target
257-
);
287+
await tryUpdate(keyExtraPaths, [libDir]);
258288
}
259289

260290
// typechecking off
261291
const keyMode = 'analysis.typeCheckingMode';
262292
const mode = cfg.get<string>(keyMode) ?? '';
263293
if (mode !== 'off') {
264-
await cfg.update(
265-
'analysis.typeCheckingMode',
266-
'off',
267-
target
268-
);
294+
await tryUpdate(keyMode, 'off');
295+
}
296+
297+
if (errors.length > 0) {
298+
let msg: string;
299+
if (errors.every(e => e === noWorkspaceOpen)) {
300+
msg = 'Write Your Python Program: settings were not changed because no folder is open. Open a folder to apply wypp settings.';
301+
} else {
302+
const sanitized = errors.map(e => e === noWorkspaceOpen ? 'Skipped workspace update because no folder is open' : e);
303+
msg = `Write Your Python Program: failed to update settings. ` + sanitized.join('. ');
304+
}
305+
try {
306+
vscode.window.showWarningMessage(msg);
307+
} catch (_e) {
308+
// ignore any error while showing the warning
309+
}
269310
}
270311
}
271312

@@ -386,7 +427,6 @@ export async function activate(context: vscode.ExtensionContext) {
386427
"run",
387428
"▶ RUN",
388429
async (cmdId) => {
389-
await fixPylanceConfig(context);
390430
const file =
391431
(vscode.window.activeTextEditor) ?
392432
vscode.window.activeTextEditor.document.fileName :
@@ -399,6 +439,7 @@ export async function activate(context: vscode.ExtensionContext) {
399439
vscode.window.showWarningMessage('Not a python file');
400440
return;
401441
}
442+
await fixPylanceConfig(context);
402443
await vscode.window.activeTextEditor?.document.save();
403444
const pyCmd = getPythonCmd(pyExt);
404445
let verboseOpt = "";
@@ -410,14 +451,19 @@ export async function activate(context: vscode.ExtensionContext) {
410451
if (verboseOpt !== "") {
411452
verboseOpt = " " + verboseOpt + " --no-clear";
412453
}
454+
const lang = getLanguage(context);
455+
let langOpt = "";
456+
if (lang) {
457+
langOpt = " --lang " + lang;
458+
}
413459
const disableOpt = disableTypechecking(context) ? " --no-typechecking" : "";
414460
if (pyCmd.kind !== "error") {
415461
const pythonCmd = commandListToArgument(pyCmd.cmd);
416462
const cmdTerm = await startTerminal(
417463
terminals[cmdId]?.terminal,
418464
"WYPP - RUN",
419465
pythonCmd + " " + fileToCommandArgument(runProg) + verboseOpt +
420-
disableOpt +
466+
disableOpt + langOpt +
421467
" --interactive " +
422468
" --change-directory " +
423469
fileToCommandArgument(file)

0 commit comments

Comments
 (0)