@@ -8,11 +8,29 @@ import path from 'path';
8
8
const rootAppDir = process . resourcesPath ,
9
9
condaDirName = 'conda' ,
10
10
condaDir = path . join ( rootAppDir , condaDirName ) ,
11
+ dllDir = path . join ( rootAppDir , condaDirName , 'DLLs' ) ,
11
12
libDir = path . join ( rootAppDir , condaDirName , 'Lib' ) ,
13
+ sitePackagesDir = path . join ( rootAppDir , condaDirName , 'Lib' , 'site-packages' ) ,
12
14
scriptsDir = path . join ( rootAppDir , condaDirName , 'Scripts' ) ;
13
15
14
16
console . log ( { rootAppDir, condaDirName, condaDir, libDir, scriptsDir, dirname : __dirname } ) ;
15
17
18
+ function splitList ( list ) {
19
+ if ( process . platform === 'win32' ) {
20
+ return list . split ( ';' ) ;
21
+ } else {
22
+ return list . split ( ':' ) ;
23
+ }
24
+ }
25
+
26
+ function joinList ( list ) {
27
+ if ( process . platform === 'win32' ) {
28
+ return list . join ( ';' ) ;
29
+ } else {
30
+ return list . join ( ':' ) ;
31
+ }
32
+ }
33
+
16
34
function prependToPath ( fullPath , pathPart ) {
17
35
if ( ! _ . includes ( fullPath , pathPart ) ) {
18
36
fullPath . unshift ( pathPart ) ;
@@ -42,31 +60,43 @@ function addBonusVariables(env) {
42
60
function prependBuiltinPath ( env ) {
43
61
const myPath = getPath ( env ) ;
44
62
45
- prependToPath ( myPath , condaDir ) ;
46
- prependToPath ( myPath , libDir ) ;
47
63
prependToPath ( myPath , scriptsDir ) ;
64
+ prependToPath ( myPath , libDir ) ;
65
+ prependToPath ( myPath , condaDir ) ;
48
66
49
67
return setPath ( env , myPath ) ;
50
68
}
51
69
70
+ function addOurPythonPath ( env ) {
71
+ if ( process . platform === 'win32' ) {
72
+ const list = env . PYTHONPATH ? splitList ( env . PYTHONPATH ) : [ ] ;
73
+
74
+ prependToPath ( list , sitePackagesDir ) ;
75
+ prependToPath ( list , libDir ) ;
76
+ prependToPath ( list , dllDir ) ;
77
+
78
+ env . PYTHONPATH = joinList ( [ dllDir , libDir , sitePackagesDir ] , list ) ;
79
+ }
80
+
81
+ return env ;
82
+ }
83
+
52
84
function applyBuiltinPython ( env ) {
53
85
const useBuiltinPython = local . get ( 'useBuiltinPython' ) || 'failover' ,
54
- hasPythonFailedOver = session . get ( 'hasPythonFailedOver' ) || false ;
86
+ hasPythonFailedOver = session . get ( 'hasPythonFailedOver' ) || false ,
87
+ hasPythonPath = env . PYTHONPATH ;
55
88
56
- if ( useBuiltinPython === 'yes' || ( hasPythonFailedOver && useBuiltinPython === 'failover' ) ) {
89
+ if ( ! hasPythonPath || useBuiltinPython === 'yes' || ( hasPythonFailedOver && useBuiltinPython === 'failover' ) ) {
90
+ addOurPythonPath ( env ) ;
57
91
env = prependBuiltinPath ( env ) ;
58
92
}
59
93
60
94
return env ;
61
95
}
62
96
63
97
function getEnvironmentVariables ( env ) {
64
-
65
- console . log ( 'what, HUH?' , env ) ;
66
-
67
98
if ( ! env ) {
68
99
env = local . get ( 'environmentVariables' ) ;
69
- console . log ( 'wait, WHY?' , env ) ;
70
100
}
71
101
72
102
if ( env ) {
@@ -94,11 +124,7 @@ function getPath(env) {
94
124
let result ;
95
125
96
126
if ( path ) {
97
- if ( process . platform === 'win32' ) {
98
- result = path . split ( ';' ) ;
99
- } else {
100
- result = path . split ( ':' ) ;
101
- }
127
+ result = splitList ( path ) ;
102
128
} else {
103
129
result = [ ] ;
104
130
}
@@ -108,28 +134,23 @@ function getPath(env) {
108
134
109
135
function setExistingPath ( env , value ) {
110
136
if ( env . PATH ) {
111
- env . PATH = value ;
137
+ delete value . PATH ;
112
138
} else if ( env . Path ) {
113
- env . Path = value ;
139
+ delete value . Path ;
114
140
} else if ( env . path ) {
115
- env . path = value ;
116
- } else {
117
- // most OS's use all capitals, and if this is not set, the user has done something WEIRD
118
- env . PATH = value ;
141
+ delete env . path ;
119
142
}
120
143
144
+ env . PATH = value ;
145
+
121
146
return env ;
122
147
}
123
148
124
149
function setPath ( env , newPath ) {
125
150
let result ;
126
151
127
152
if ( _ . isArray ( newPath ) ) {
128
- if ( process . platform === 'win32' ) {
129
- result = newPath . join ( ';' ) ;
130
- } else {
131
- result = newPath . join ( ':' ) ;
132
- }
153
+ result = joinList ( newPath ) ;
133
154
134
155
env = setExistingPath ( env , result ) ;
135
156
local . set ( 'environmentVariables' , env ) ;
0 commit comments