Skip to content

Commit 78e69e3

Browse files
committed
fix: package versions
1 parent 5b087e7 commit 78e69e3

File tree

1 file changed

+36
-3
lines changed

1 file changed

+36
-3
lines changed

src/managers/poetry/poetryPackageManager.ts

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import * as ch from 'child_process';
2+
import * as fsapi from 'fs-extra';
3+
import * as path from 'path';
24
import {
35
CancellationError,
46
CancellationToken,
@@ -192,24 +194,55 @@ export class PoetryPackageManager implements PackageManager, Disposable {
192194
}
193195

194196
private async refreshPackages(environment: PythonEnvironment): Promise<Package[]> {
197+
let cwd = process.cwd();
198+
const projects = this.api.getPythonProjects();
199+
if (projects.length === 1) {
200+
const stat = await fsapi.stat(projects[0].uri.fsPath);
201+
if (stat.isDirectory()) {
202+
cwd = projects[0].uri.fsPath;
203+
} else {
204+
cwd = path.dirname(projects[0].uri.fsPath);
205+
}
206+
} else if (projects.length > 1) {
207+
const dirs = new Set<string>();
208+
await Promise.all(
209+
projects.map(async (project) => {
210+
const e = await this.api.getEnvironment(project.uri);
211+
if (e?.envId.id === environment.envId.id) {
212+
const stat = await fsapi.stat(projects[0].uri.fsPath);
213+
const dir = stat.isDirectory() ? projects[0].uri.fsPath : path.dirname(projects[0].uri.fsPath);
214+
if (dirs.has(dir)) {
215+
dirs.add(dir);
216+
}
217+
}
218+
}),
219+
);
220+
if (dirs.size > 0) {
221+
// ensure we have the deepest directory node picked
222+
cwd = Array.from(dirs.values()).sort((a, b) => (a.length - b.length) * -1)[0];
223+
}
224+
}
225+
195226
const poetryPackages: { name: string; version: string; displayName: string; description: string }[] = [];
196227

197228
try {
198229
this.log.info(`Running: ${await getPoetry()} show --no-ansi`);
199-
const result = await runPoetry(['show', '--no-ansi'], undefined, this.log);
230+
const result = await runPoetry(['show', '--no-ansi'], cwd, this.log);
200231

201232
// Parse poetry show output
202233
// Format: name version description
203234
const lines = result.split('\n');
204235
for (const line of lines) {
205-
const match = line.match(/^([^\s]+)\s+([^\s]+)\s+(.*)/);
236+
// Updated regex to properly handle lines with the format:
237+
// "package (!) version description"
238+
const match = line.match(/^(\S+)(?:\s+\([!]\))?\s+(\S+)\s+(.*)/);
206239
if (match) {
207240
const [, name, version, description] = match;
208241
poetryPackages.push({
209242
name,
210243
version,
211244
displayName: name,
212-
description: description?.trim() || version,
245+
description: `${version} - ${description?.trim() || ''}`,
213246
});
214247
}
215248
}

0 commit comments

Comments
 (0)