Skip to content

Commit 3806f21

Browse files
authored
feat: use pip3 if available (#79)
1 parent a326d7a commit 3806f21

File tree

3 files changed

+44
-2
lines changed

3 files changed

+44
-2
lines changed

packages/pyright-scip/package-lock.json

Lines changed: 24 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/pyright-scip/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
"@sourcegraph/eslint-config": "0.26.0",
2525
"@sourcegraph/prettierrc": "3.0.3",
2626
"@sourcegraph/tsconfig": "4.0.1",
27+
"@types/command-exists": "^1.2.0",
2728
"@types/diff": "^5.0.2",
2829
"@types/glob": "^7.2.0",
2930
"@types/google-protobuf": "^3.15.5",
@@ -43,6 +44,7 @@
4344
},
4445
"dependencies": {
4546
"@iarna/toml": "2.2.5",
47+
"command-exists": "^1.2.9",
4648
"commander": "^9.2.0",
4749
"diff": "^5.0.0",
4850
"glob": "^7.2.0",

packages/pyright-scip/src/virtualenv/environment.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import * as child_process from 'child_process';
33
import PythonPackage from './PythonPackage';
44
import PythonEnvironment from './PythonEnvironment';
55
import { withStatus } from 'src/status';
6+
import { sync as commandExistsSync } from 'command-exists';
67

78
// Some future improvements:
89
// - Could use `importlib` and execute some stuff from Python
@@ -12,14 +13,29 @@ interface PipInformation {
1213
version: string;
1314
}
1415

16+
let pipCommand: string | undefined;
17+
let getPipCommand = () => {
18+
if (pipCommand === undefined) {
19+
if (commandExistsSync('pip3')) {
20+
pipCommand = 'pip3';
21+
} else if (commandExistsSync('pip')) {
22+
pipCommand = 'pip';
23+
} else {
24+
throw new Error('Could not find valid pip command');
25+
}
26+
}
27+
28+
return pipCommand;
29+
};
30+
1531
function pipList(): PipInformation[] {
16-
return JSON.parse(child_process.execSync('pip list --format=json').toString()) as PipInformation[];
32+
return JSON.parse(child_process.execSync(`${getPipCommand()} list --format=json`).toString()) as PipInformation[];
1733
}
1834

1935
function pipBulkShow(names: string[]): string[] {
2036
// TODO: This probably breaks with enough names. Should batch them into 512 or whatever the max for bash would be
2137
return child_process
22-
.execSync(`pip show -f ${names.join(' ')}`)
38+
.execSync(`${getPipCommand()} show -f ${names.join(' ')}`)
2339
.toString()
2440
.split('---');
2541
}

0 commit comments

Comments
 (0)