diff --git a/packages/pyright-scip/package-lock.json b/packages/pyright-scip/package-lock.json index c85c45142..55b833391 100644 --- a/packages/pyright-scip/package-lock.json +++ b/packages/pyright-scip/package-lock.json @@ -10,6 +10,7 @@ "license": "MIT", "dependencies": { "@iarna/toml": "2.2.5", + "command-exists": "^1.2.9", "commander": "^9.2.0", "diff": "^5.0.0", "glob": "^7.2.0", @@ -24,6 +25,7 @@ "@sourcegraph/eslint-config": "0.26.0", "@sourcegraph/prettierrc": "3.0.3", "@sourcegraph/tsconfig": "4.0.1", + "@types/command-exists": "^1.2.0", "@types/diff": "^5.0.2", "@types/glob": "^7.2.0", "@types/google-protobuf": "^3.15.5", @@ -1581,6 +1583,12 @@ "@babel/types": "^7.3.0" } }, + "node_modules/@types/command-exists": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/@types/command-exists/-/command-exists-1.2.0.tgz", + "integrity": "sha512-ugsxEJfsCuqMLSuCD4PIJkp5Uk2z6TCMRCgYVuhRo5cYQY3+1xXTQkSlPtkpGHuvWMjS2KTeVQXxkXRACMbM6A==", + "dev": true + }, "node_modules/@types/diff": { "version": "5.0.2", "resolved": "https://registry.npmjs.org/@types/diff/-/diff-5.0.2.tgz", @@ -2967,6 +2975,11 @@ "node": ">= 0.8" } }, + "node_modules/command-exists": { + "version": "1.2.9", + "resolved": "https://registry.npmjs.org/command-exists/-/command-exists-1.2.9.tgz", + "integrity": "sha512-LTQ/SGc+s0Xc0Fu5WaKnR0YiygZkm9eKFvyS+fRsU7/ZWFF8ykFM6Pc9aCVf1+xasOOZpO3BAVgVrKvsqKHV7w==" + }, "node_modules/commander": { "version": "9.2.0", "resolved": "https://registry.npmjs.org/commander/-/commander-9.2.0.tgz", @@ -11039,6 +11052,12 @@ "@babel/types": "^7.3.0" } }, + "@types/command-exists": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/@types/command-exists/-/command-exists-1.2.0.tgz", + "integrity": "sha512-ugsxEJfsCuqMLSuCD4PIJkp5Uk2z6TCMRCgYVuhRo5cYQY3+1xXTQkSlPtkpGHuvWMjS2KTeVQXxkXRACMbM6A==", + "dev": true + }, "@types/diff": { "version": "5.0.2", "resolved": "https://registry.npmjs.org/@types/diff/-/diff-5.0.2.tgz", @@ -12107,6 +12126,11 @@ "delayed-stream": "~1.0.0" } }, + "command-exists": { + "version": "1.2.9", + "resolved": "https://registry.npmjs.org/command-exists/-/command-exists-1.2.9.tgz", + "integrity": "sha512-LTQ/SGc+s0Xc0Fu5WaKnR0YiygZkm9eKFvyS+fRsU7/ZWFF8ykFM6Pc9aCVf1+xasOOZpO3BAVgVrKvsqKHV7w==" + }, "commander": { "version": "9.2.0", "resolved": "https://registry.npmjs.org/commander/-/commander-9.2.0.tgz", diff --git a/packages/pyright-scip/package.json b/packages/pyright-scip/package.json index 3c56221a6..413baaf4b 100644 --- a/packages/pyright-scip/package.json +++ b/packages/pyright-scip/package.json @@ -24,6 +24,7 @@ "@sourcegraph/eslint-config": "0.26.0", "@sourcegraph/prettierrc": "3.0.3", "@sourcegraph/tsconfig": "4.0.1", + "@types/command-exists": "^1.2.0", "@types/diff": "^5.0.2", "@types/glob": "^7.2.0", "@types/google-protobuf": "^3.15.5", @@ -43,6 +44,7 @@ }, "dependencies": { "@iarna/toml": "2.2.5", + "command-exists": "^1.2.9", "commander": "^9.2.0", "diff": "^5.0.0", "glob": "^7.2.0", diff --git a/packages/pyright-scip/src/virtualenv/environment.ts b/packages/pyright-scip/src/virtualenv/environment.ts index a888d05ab..691f5ed48 100644 --- a/packages/pyright-scip/src/virtualenv/environment.ts +++ b/packages/pyright-scip/src/virtualenv/environment.ts @@ -3,6 +3,7 @@ import * as child_process from 'child_process'; import PythonPackage from './PythonPackage'; import PythonEnvironment from './PythonEnvironment'; import { withStatus } from 'src/status'; +import { sync as commandExistsSync } from 'command-exists'; // Some future improvements: // - Could use `importlib` and execute some stuff from Python @@ -12,14 +13,29 @@ interface PipInformation { version: string; } +let pipCommand: string | undefined; +let getPipCommand = () => { + if (pipCommand === undefined) { + if (commandExistsSync('pip3')) { + pipCommand = 'pip3'; + } else if (commandExistsSync('pip')) { + pipCommand = 'pip'; + } else { + throw new Error('Could not find valid pip command'); + } + } + + return pipCommand; +}; + function pipList(): PipInformation[] { - return JSON.parse(child_process.execSync('pip list --format=json').toString()) as PipInformation[]; + return JSON.parse(child_process.execSync(`${getPipCommand()} list --format=json`).toString()) as PipInformation[]; } function pipBulkShow(names: string[]): string[] { // TODO: This probably breaks with enough names. Should batch them into 512 or whatever the max for bash would be return child_process - .execSync(`pip show -f ${names.join(' ')}`) + .execSync(`${getPipCommand()} show -f ${names.join(' ')}`) .toString() .split('---'); }