Skip to content

feat: use pip3 if available #79

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 3, 2023
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
24 changes: 24 additions & 0 deletions packages/pyright-scip/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions packages/pyright-scip/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down
20 changes: 18 additions & 2 deletions packages/pyright-scip/src/virtualenv/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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('---');
}
Expand Down