• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

pyta-uoft / python-ta-vscode-extension / 37787297499

08 Oct 2026 01:48PM UTC coverage: 63.623% (+12.1%) from 51.54%
37787297499

Pull #27

github

web-flow
Merge 2f82154c0 into ea28131ab
Pull Request #27: Bump astral-sh/setup-uv from 9.0.0 to 10.2.0

72 of 109 branches covered (66.06%)

Branch coverage included in aggregate %.

820 of 1293 relevant lines covered (63.42%)

1.25 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

60.84
/src/common/python.ts
1
import { commands, Disposable, Event, EventEmitter, Uri } from 'vscode';
1 ✔
2
import { traceError, traceLog } from './log/logging';
1 ✔
3
import { PythonExtension, ResolvedEnvironment } from '@vscode/python-extension';
1 ✔
4
import { PythonEnvironmentApi, PythonEnvironments } from '@vscode/python-environments';
1 ✔
5

1 ✔
6
export interface IInterpreterDetails {
1 ✔
7
    path?: string[];
1 ✔
8
    resource?: Uri;
1 ✔
9
}
1 ✔
10

1 ✔
11
const onDidChangePythonInterpreterEvent = new EventEmitter<IInterpreterDetails>();
1 ✔
12
export const onDidChangePythonInterpreter: Event<IInterpreterDetails> = onDidChangePythonInterpreterEvent.event;
1 ✔
13

1 ✔
14
let _api: PythonExtension | undefined;
1 ✔
15
async function getPythonExtensionAPI(): Promise<PythonExtension | undefined> {
1 ✔
16
    if (_api) {
1 !
17
        return _api;
×
18
    }
×
19
    _api = await PythonExtension.api();
1 ✔
20
    return _api;
1 ✔
21
}
1 ✔
22

1 ✔
23
let _envsApi: PythonEnvironmentApi | undefined;
1 ✔
24
async function getEnvironmentsExtensionAPI(): Promise<PythonEnvironmentApi | undefined> {
5 ✔
25
    if (_envsApi) {
5 ✔
26
        return _envsApi;
4 ✔
27
    }
4 ✔
28
    try {
1 ✔
29
        _envsApi = await PythonEnvironments.api();
1 ✔
30
    } catch {
5 !
31
        return undefined;
×
32
    }
×
33
    return _envsApi;
1 ✔
34
}
1 ✔
35

1 ✔
36
export async function initializePython(disposables: Disposable[]): Promise<void> {
1 ✔
37
    try {
1 ✔
38
        // // Prefer the Python Environments extension if it's available, as it provides a more comprehensive view of the available environments.
1 ✔
39
        const envsApi = await getEnvironmentsExtensionAPI();
1 ✔
40

1 ✔
41
        if (envsApi) {
1 ✔
42
            disposables.push(
1 ✔
43
                envsApi.onDidChangeEnvironment((e) => {
1 ✔
44
                    onDidChangePythonInterpreterEvent.fire({
2 ✔
45
                        path: e.new ? [e.new.execInfo.run.executable] : undefined,
2 !
46
                        resource: e.uri,
2 ✔
47
                    });
2 ✔
48
                }),
1 ✔
49
            );
1 ✔
50

1 ✔
51
            traceLog('Waiting for interpreter from python environments extension.');
1 ✔
52
            onDidChangePythonInterpreterEvent.fire(await getInterpreterDetails());
1 ✔
53
            return;
1 ✔
54
        }
1 ✔
55

×
56
        // Fall back to legacy ms-python.python extension API
×
57
        const api = await getPythonExtensionAPI();
×
58

×
59
        if (api) {
×
60
            disposables.push(
×
61
                api.environments.onDidChangeActiveEnvironmentPath((e) => {
×
62
                    const resource = e.resource instanceof Uri ? e.resource : e.resource?.uri;
×
63
                    onDidChangePythonInterpreterEvent.fire({ path: [e.path], resource });
×
64
                }),
×
65
            );
×
66

×
67
            traceLog('Waiting for interpreter from python extension.');
×
68
            onDidChangePythonInterpreterEvent.fire(await getInterpreterDetails());
×
69
        }
×
70
    } catch (error) {
1 !
71
        traceError('Error initializing python: ', error);
×
72
    }
×
73
}
1 ✔
74

1 ✔
75
export async function resolveInterpreter(interpreter: string[]): Promise<ResolvedEnvironment | undefined> {
1 ✔
76
    const api = await getPythonExtensionAPI();
×
77
    return api?.environments.resolveEnvironment(interpreter[0]);
×
78
}
×
79

1 ✔
80
export async function getInterpreterDetails(resource?: Uri): Promise<IInterpreterDetails> {
1 ✔
81
    // Prefer the Python Environments extension if it's available, as it provides a more comprehensive view of the available environments.
4 ✔
82
    const envsApi = await getEnvironmentsExtensionAPI();
4 ✔
83
    if (envsApi) {
4 ✔
84
        const environment = await envsApi.getEnvironment(resource);
4 ✔
85
        if (environment) {
4 ✔
86
            return {
4 ✔
87
                path: [environment.execInfo.run.executable],
4 ✔
88
                resource,
4 ✔
89
            };
4 ✔
90
        }
4 ✔
91
        return { path: undefined, resource };
×
92
    }
×
93

×
94
    // Fall back to legacy ms-python.python extension API
×
95
    const api = await getPythonExtensionAPI();
×
96
    const environment = await api?.environments.resolveEnvironment(
4 ✔
97
        api?.environments.getActiveEnvironmentPath(resource),
4 !
98
    );
4 ✔
99
    if (environment?.executable.uri && checkVersion(environment)) {
4 !
100
        return { path: [environment?.executable.uri.fsPath], resource };
×
101
    }
×
102
    return { path: undefined, resource };
×
103
}
×
104

1 ✔
105
export async function getDebuggerPath(): Promise<string | undefined> {
1 ✔
106
    const api = await getPythonExtensionAPI();
1 ✔
107
    return api?.debug.getDebuggerPackagePath();
1 ✔
108
}
1 ✔
109

1 ✔
110
export async function runPythonExtensionCommand(command: string, ...rest: any[]) {
1 ✔
111
    await getPythonExtensionAPI();
×
112
    return await commands.executeCommand(command, ...rest);
×
113
}
×
114

1 ✔
115
export function checkVersion(resolved: ResolvedEnvironment | undefined): boolean {
×
116
    const version = resolved?.version;
×
117
    if (version?.major === 3 && version?.minor >= 10) {
×
118
        return true;
×
119
    }
×
120
    traceError(`Python version ${version?.major}.${version?.minor} is not supported.`);
×
121
    traceError(`Selected python path: ${resolved?.executable.uri?.fsPath}`);
×
122
    traceError('Supported versions are 3.10 and above.');
×
123
    return false;
×
124
}
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc