File tree Expand file tree Collapse file tree 3 files changed +44
-2
lines changed Expand file tree Collapse file tree 3 files changed +44
-2
lines changed Original file line number Diff line number Diff line change 24
24
"@sourcegraph/eslint-config" : " 0.26.0" ,
25
25
"@sourcegraph/prettierrc" : " 3.0.3" ,
26
26
"@sourcegraph/tsconfig" : " 4.0.1" ,
27
+ "@types/command-exists" : " ^1.2.0" ,
27
28
"@types/diff" : " ^5.0.2" ,
28
29
"@types/glob" : " ^7.2.0" ,
29
30
"@types/google-protobuf" : " ^3.15.5" ,
43
44
},
44
45
"dependencies" : {
45
46
"@iarna/toml" : " 2.2.5" ,
47
+ "command-exists" : " ^1.2.9" ,
46
48
"commander" : " ^9.2.0" ,
47
49
"diff" : " ^5.0.0" ,
48
50
"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';
3
3
import PythonPackage from './PythonPackage' ;
4
4
import PythonEnvironment from './PythonEnvironment' ;
5
5
import { withStatus } from 'src/status' ;
6
+ import { sync as commandExistsSync } from 'command-exists' ;
6
7
7
8
// Some future improvements:
8
9
// - Could use `importlib` and execute some stuff from Python
@@ -12,14 +13,29 @@ interface PipInformation {
12
13
version : string ;
13
14
}
14
15
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
+
15
31
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 [ ] ;
17
33
}
18
34
19
35
function pipBulkShow ( names : string [ ] ) : string [ ] {
20
36
// TODO: This probably breaks with enough names. Should batch them into 512 or whatever the max for bash would be
21
37
return child_process
22
- . execSync ( `pip show -f ${ names . join ( ' ' ) } ` )
38
+ . execSync ( `${ getPipCommand ( ) } show -f ${ names . join ( ' ' ) } ` )
23
39
. toString ( )
24
40
. split ( '---' ) ;
25
41
}
You can’t perform that action at this time.
0 commit comments