@@ -7,7 +7,6 @@ import * as fs from 'fs'
77import * as path from 'path'
88import * as vscode from 'vscode'
99
10- import { resolveVariables } from '../../core/config'
1110import { error , log , notifyError , notifyInfo , notifyWarn } from '../../core/log'
1211import { safeExecAsync } from '../../core/shell'
1312import { killAllDmypyDaemons } from './mypyConfig'
@@ -170,24 +169,6 @@ function defaultDmypyPath(wsFolder: vscode.WorkspaceFolder): string {
170169 return path . join ( wsFolder . uri . fsPath , '.venv' , 'bin' , 'dmypy' )
171170}
172171
173- /** Decide whether a `mypy.dmypyExecutable` value is one of the Checkmk
174- * default forms (and therefore safe to take over when switching to jemalloc
175- * mode), versus a user-managed custom path we should leave alone.
176- *
177- * Accepted forms:
178- * - `${cmk-ext:workspaceFolder}/.venv/bin/dmypy` — current Checkmk bundled default.
179- * - `${workspaceFolder}/.venv/bin/dmypy` — legacy form still present in
180- * existing `.code-workspace` files from before the switch to `cmk-ext:`.
181- * - `<workspace>/.venv/bin/dmypy` — the resolved absolute path written
182- * after `resolveVariables` expands the bundled default.
183- * We compare strings only; we do not re-expand VS Code's native variables. */
184- export function isDefaultDmypyValue ( value : string , wsFolder : vscode . WorkspaceFolder ) : boolean {
185- const resolvedByExt = resolveVariables ( value ) as string
186- return (
187- resolvedByExt === defaultDmypyPath ( wsFolder ) || value === '${workspaceFolder}/.venv/bin/dmypy'
188- )
189- }
190-
191172function readAllocatorMode ( ) : AllocatorMode {
192173 const v = vscode . workspace . getConfiguration ( ) . get < string > ( SETTING_ALLOCATOR , 'default' )
193174 return v === 'jemalloc' ? 'jemalloc' : 'default'
@@ -277,48 +258,35 @@ function deleteWrapperIfPresent(wrapperPath: string): void {
277258/** Reconcile `mypy.dmypyExecutable` to match `cmk.mypy.allocator`. Idempotent.
278259 * - `"jemalloc"` + probe hit → write wrapper, point dmypyExecutable at it.
279260 * - `"jemalloc"` + probe miss → notify once, leave setting armed.
280- * - `"default"` → release ownership (unset dmypyExecutable if it's ours),
281- * delete wrapper.
282- * Never overwrites a manual `mypy.dmypyExecutable` override — if the current
283- * value is neither unset nor our own wrapper path, we log and skip . */
261+ * - `"default"` → restore the bundled venv default, delete wrapper.
262+ * The extension owns `mypy.dmypyExecutable`: it unconditionally overrides any
263+ * pre-existing value (including a custom path or one carried over from before
264+ * the extension was installed) so the venv-pinned dmypy is always used . */
284265export async function applyAllocatorSetting (
285266 context : vscode . ExtensionContext ,
286267 wsFolder : vscode . WorkspaceFolder
287268) : Promise < void > {
288269 const wrapperPath = wrapperPathFor ( context )
289270 const mode = readAllocatorMode ( )
290271 const current = readCurrentDmypyExecutable ( wsFolder )
291- const weOwn =
292- current === undefined || current === wrapperPath || isDefaultDmypyValue ( current , wsFolder )
293272
294273 if ( mode === 'default' ) {
295274 // Restore the bundled defaults instead of leaving the keys unset — matangover
296275 // falls back to `python -m mypy.dmypy` when `mypy.dmypyExecutable` is empty,
297- // which breaks the venv-pinned setup. Only overwrite when we owned the prior
298- // value (our wrapper, the bundled default literal, or unset) — never clobber
299- // a custom user-managed dmypy path.
300- if ( weOwn ) {
301- const previousDmypy = current
302- const previousRun = vscode . workspace
303- . getConfiguration ( 'mypy' , wsFolder )
304- . get < boolean > ( RUN_USING_INTERPRETER_SETTING )
305- await updateDmypyExecutable ( wsFolder , defaultDmypyPath ( wsFolder ) )
306- await updateRunUsingInterpreter ( wsFolder , true )
307- log (
308- `cmk.mypy.allocator=default — restored mypy.dmypyExecutable=${ defaultDmypyPath ( wsFolder ) } , runUsingActiveInterpreter=true`
309- )
310- if ( previousDmypy === wrapperPath || previousRun === false ) {
311- await killAllDmypyDaemons ( )
312- }
313- }
314- deleteWrapperIfPresent ( wrapperPath )
315- return
316- }
317-
318- if ( ! weOwn ) {
276+ // which breaks the venv-pinned setup.
277+ const target = defaultDmypyPath ( wsFolder )
278+ const previousRun = vscode . workspace
279+ . getConfiguration ( 'mypy' , wsFolder )
280+ . get < boolean > ( RUN_USING_INTERPRETER_SETTING )
281+ if ( current !== target ) await updateDmypyExecutable ( wsFolder , target )
282+ if ( previousRun !== true ) await updateRunUsingInterpreter ( wsFolder , true )
319283 log (
320- `cmk.mypy.allocator=jemalloc but mypy.dmypyExecutable is set to a custom path ( ${ current } ) — leaving user override in place `
284+ `cmk.mypy.allocator=default — set mypy.dmypyExecutable= ${ target } , runUsingActiveInterpreter=true `
321285 )
286+ if ( current === wrapperPath || previousRun === false ) {
287+ await killAllDmypyDaemons ( )
288+ }
289+ deleteWrapperIfPresent ( wrapperPath )
322290 return
323291 }
324292
0 commit comments