MCPcopy Create free account
hub / github.com/deepnote/vscode-deepnote / OldPythonApiProvider

Class OldPythonApiProvider

src/platform/api/pythonApi.ts:106–225  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

104/* eslint-disable max-classes-per-file */
105@injectable()
106export class OldPythonApiProvider implements IPythonApiProvider {
107 private readonly api = createDeferred<PythonApi>();
108 private readonly didActivatePython = new EventEmitter<void>();
109 private readonly _pythonExtensionHooked = createDeferred<void>();
110 public get onDidActivatePythonExtension() {
111 return this.didActivatePython.event;
112 }
113
114 // This promise will resolve when the python extension is hooked
115 public get pythonExtensionHooked(): Promise<void> {
116 return this._pythonExtensionHooked.promise;
117 }
118 public get pythonExtensionVersion(): SemVer | undefined {
119 return this._pythonExtensionVersion;
120 }
121
122 private initialized?: boolean;
123 private hooksRegistered?: boolean;
124 private _pythonExtensionVersion?: SemVer | undefined;
125
126 constructor(
127 @inject(IDisposableRegistry) private readonly disposables: IDisposableRegistry,
128 @inject(IPythonExtensionChecker) private extensionChecker: IPythonExtensionChecker
129 ) {
130 const previouslyInstalled = this.extensionChecker.isPythonExtensionInstalled;
131 if (!previouslyInstalled) {
132 extensions.onDidChange(
133 async () => {
134 if (this.extensionChecker.isPythonExtensionInstalled) {
135 await this.registerHooks();
136 }
137 },
138 this,
139 this.disposables
140 );
141 }
142 this.disposables.push(this.didActivatePython);
143 }
144
145 public getApi(): Promise<PythonApi> {
146 this.init().catch(noop);
147 return this.api.promise;
148 }
149 public async getNewApi(): Promise<PythonExtensionApi | undefined> {
150 await this.init();
151 const extension = extensions.getExtension<PythonExtensionApi>(PythonExtension);
152 if (extension?.packageJSON?.version) {
153 this._pythonExtensionVersion = new SemVer(extension?.packageJSON?.version);
154 }
155 if (extension?.exports) {
156 setPythonApi(extension.exports);
157 extension.exports.environments.known.forEach((e) => {
158 trackInterpreterDiscovery(e);
159 });
160 }
161 return extension?.exports;
162 }
163

Callers

nothing calls this directly

Calls 1

createDeferredFunction · 0.90

Tested by

no test coverage detected