Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/managers/builtin/pipListUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ export interface PipPackage {
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[] = [];

Expand All @@ -13,9 +18,12 @@ export function parsePipList(data: string): PipPackage[] {
continue;
}
const parts = line.split(' ').filter((e) => e);
if (parts.length > 1) {
if (parts.length === 2) {
const name = parts[0].trim();
const version = parts[1].trim();
if (!isValidVersion(version)) {
continue;
}
const pkg = {
name,
version,
Expand Down
6 changes: 3 additions & 3 deletions src/test/managers/builtin/pipListUtils.unit.test.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import assert from 'assert';
import * as fs from 'fs-extra';
import * as path from 'path';
import { EXTENSION_TEST_ROOT } from '../../constants';
import { parsePipList } from '../../../managers/builtin/pipListUtils';
import assert from 'assert';
import { EXTENSION_TEST_ROOT } from '../../constants';

const TEST_DATA_ROOT = path.join(EXTENSION_TEST_ROOT, 'managers', 'builtin');

suite('Pip List Parser tests', () => {
const testNames = ['piplist1', 'piplist2'];
const testNames = ['piplist1', 'piplist2', 'piplist3'];

testNames.forEach((testName) => {
test(`Test parsing pip list output ${testName}`, async () => {
Expand Down
11 changes: 11 additions & 0 deletions src/test/managers/builtin/piplist3.actual.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Package Version
---------- -------
altgraph 0.17.2
future 0.18.2
macholib 1.15.2
pip 21.2.4
setuptools 58.0.4
six 1.15.0
wheel 0.37.0
WARNING: You are using pip version 21.2.4; however, version 25.2 is available.
You should consider upgrading via the '/Library/Developer/CommandLineTools/usr/bin/python3 -m pip install --upgrade pip' command.
11 changes: 11 additions & 0 deletions src/test/managers/builtin/piplist3.expected.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"packages": [
{ "name": "altgraph", "version": "0.17.2" },
{ "name": "future", "version": "0.18.2" },
{ "name": "macholib", "version": "1.15.2" },
{ "name": "pip", "version": "21.2.4" },
{ "name": "setuptools", "version": "58.0.4" },
{ "name": "six", "version": "1.15.0" },
{ "name": "wheel", "version": "0.37.0" }
]
}
Loading