forked from microsoft/vscode-python-environments
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpipListUtils.ts
More file actions
37 lines (36 loc) · 1.14 KB
/
pipListUtils.ts
File metadata and controls
37 lines (36 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
export interface PipPackage {
name: string;
version: string;
displayName: string;
description: string;
}
export function isValidVersion(version: string): boolean {
return /^([1-9][0-9]*!)?(0|[1-9][0-9]*)(\.(0|[1-9][0-9]*))*((a|b|rc)(0|[1-9][0-9]*))?(\.post(0|[1-9][0-9]*))?(\.dev(0|[1-9][0-9]*))?$/.test(
version,
);
}
export function parsePipList(data: string): PipPackage[] {
const collection: PipPackage[] = [];
const lines = data.split('\n').splice(2);
for (let line of lines) {
if (line.trim() === '' || line.startsWith('Package') || line.startsWith('----') || line.startsWith('[')) {
continue;
}
const parts = line.split(' ').filter((e) => e);
if (parts.length === 2) {
const name = parts[0].trim();
const version = parts[1].trim();
if (!isValidVersion(version)) {
continue;
}
const pkg = {
name,
version,
displayName: name,
description: version,
};
collection.push(pkg);
}
}
return collection;
}