File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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" ,
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" ,
Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ import * as child_process from 'child_process';
33import PythonPackage from './PythonPackage' ;
44import PythonEnvironment from './PythonEnvironment' ;
55import { 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+
1531function 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
1935function 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}
You can’t perform that action at this time.
0 commit comments