@@ -10,10 +10,8 @@ import { FSWatchingLocator } from './fsWatchingLocator';
10
10
import { pathExists } from 'fs-extra' ;
11
11
import * as crypto from 'crypto' ;
12
12
13
-
14
13
import { exec } from 'child_process' ;
15
- import ContextManager from '../composite/envsCollectionService' ;
16
- import { PySparkParam } from '../../../../browser/extension' ;
14
+ import CacheMap from '../composite/envsReducer' ;
17
15
18
16
function exportCondaEnv ( name : string ) : Promise < string > {
19
17
return new Promise ( ( resolve , reject ) => {
@@ -36,16 +34,16 @@ function preprocessAndHashDependencies(value: string): string {
36
34
const lines = value . split ( '\n' ) ;
37
35
38
36
// 找到 `dependencies:` 的起始行
39
- const dependenciesStartIndex = lines . findIndex ( line => line . trim ( ) === 'dependencies:' ) ;
37
+ const dependenciesStartIndex = lines . findIndex ( ( line ) => line . trim ( ) === 'dependencies:' ) ;
40
38
41
39
// 找到 `dependencies:` 之后的 `prefix:` 行,表示 dependencies 结束
42
- const prefixStartIndex = lines . findIndex ( line => line . trim ( ) . startsWith ( 'prefix:' ) ) ;
40
+ const prefixStartIndex = lines . findIndex ( ( line ) => line . trim ( ) . startsWith ( 'prefix:' ) ) ;
43
41
44
42
// 提取 dependencies 部分的内容(跳过 `dependencies:` 行)
45
- const dependencies = lines . slice ( dependenciesStartIndex + 1 , prefixStartIndex ) . map ( line => line . trim ( ) ) ;
43
+ const dependencies = lines . slice ( dependenciesStartIndex + 1 , prefixStartIndex ) . map ( ( line ) => line . trim ( ) ) ;
46
44
47
45
// 去除空行
48
- const filteredDependencies = dependencies . filter ( line => line !== '' ) ;
46
+ const filteredDependencies = dependencies . filter ( ( line ) => line !== '' ) ;
49
47
50
48
// 对 dependencies 内容进行排序
51
49
const sortedDependencies = filteredDependencies . sort ( ) ;
@@ -64,7 +62,7 @@ async function compareDetails(storeDetail: string, detail: string | undefined):
64
62
try {
65
63
const storeDetailHash = preprocessAndHashDependencies ( storeDetail ) ;
66
64
const detailHash = preprocessAndHashDependencies ( detail ) ;
67
-
65
+
68
66
return storeDetailHash === detailHash ;
69
67
} catch ( error ) {
70
68
traceError ( 'Error comparing details:' , error ) ;
@@ -86,34 +84,38 @@ interface PySparkEnvironmentMeta {
86
84
87
85
async function fetchEnvironments ( ) : Promise < PySparkEnvironmentMeta [ ] > {
88
86
try {
89
- // 获取存储的 PySparkParam 对象
90
- const pySparkParam = ContextManager . getInstance ( ) . getContext ( ) . globalState . get < PySparkParam > ( 'pyspark.paramRegister.copy ') ;
87
+ const projectId = CacheMap . getInstance ( ) . get ( 'projectId' ) ;
88
+ const projectCode = CacheMap . getInstance ( ) . get ( 'projectCode ') ;
91
89
92
- let proId = "0" ;
90
+ let proId = '0' ;
93
91
// 检查是否成功获取到数据
94
- if ( pySparkParam ) {
92
+ // if (pySparkParam) {
93
+ if ( projectId && projectCode ) {
95
94
// 通过属性名获取 projectId 和 projectCode
96
- const { projectId } = pySparkParam ;
97
- const { projectCode } = pySparkParam ;
98
-
99
- console . log ( `Project ID: ${ projectId } ` ) ;
100
- console . log ( `Project Code: ${ projectCode } ` ) ;
101
-
102
- if ( projectId ) {
103
- proId = projectId ;
104
- }
95
+ // const { projectId } = pySparkParam;
96
+ // const { projectCode } = pySparkParam;
97
+
98
+ console . log ( `fetchEnvironments Project ID: ${ projectId } ` ) ;
99
+ console . log ( `fetchEnvironments Project Code: ${ projectCode } ` ) ;
100
+ proId = projectId ;
101
+ // if (projectId) {
102
+ // proId = projectId;
103
+ // }
105
104
} else {
106
105
console . log ( 'No PySparkParam found in global state.' ) ;
107
106
}
108
-
109
- const response = await fetch ( `${ ContextManager . getInstance ( ) . getContext ( ) . globalState . get < string > ( 'gateway.addr' ) } /api/v1/env/pyspark/list?proId=${ proId } ` , {
110
- method : 'GET' ,
111
- headers : {
112
- Cookie : 'token=2345fc15-fe44-4e3b-afbc-24688c2f5f70;userId=idegw' ,
113
- 'content-type' : 'application/json' ,
114
- operator : 'hu.tan@msxf.com' ,
107
+
108
+ const response = await fetch (
109
+ `${ CacheMap . getInstance ( ) . get ( 'gatewayUri' ) } /api/v1/env/pyspark/list?proId=${ proId } ` ,
110
+ {
111
+ method : 'GET' ,
112
+ headers : {
113
+ Cookie : 'token=2345fc15-fe44-4e3b-afbc-24688c2f5f70;userId=idegw' ,
114
+ 'content-type' : 'application/json' ,
115
+ operator : 'hu.tan@msxf.com' ,
116
+ } ,
115
117
} ,
116
- } ) ;
118
+ ) ;
117
119
118
120
if ( ! response . ok ) {
119
121
throw new Error ( 'Network response was not ok' ) ;
@@ -123,7 +125,7 @@ async function fetchEnvironments(): Promise<PySparkEnvironmentMeta[]> {
123
125
return environments ;
124
126
} catch ( error ) {
125
127
console . error ( 'Error fetching environments:' , error ) ;
126
- traceError ( `Error fetching environments: ${ error } ` )
128
+ traceError ( `Error fetching environments: ${ error } ` ) ;
127
129
return [ ] ; // 返回空数组作为错误处理
128
130
}
129
131
}
@@ -162,21 +164,6 @@ export class CondaEnvironmentLocator extends FSWatchingLocator {
162
164
163
165
// eslint-disable-next-line class-methods-use-this
164
166
public async * doIterEnvs ( ) : IPythonEnvsIterator < BasicEnvInfo > {
165
-
166
- // // 测试用:获取存储的 PySparkParam 对象
167
- // const pySparkParam = ContextManager.getInstance().getContext().globalState.get<PySparkParam>('pyspark.paramRegister.copy');
168
-
169
- // // 检查是否成功获取到数据
170
- // if (pySparkParam) {
171
- // // 通过属性名获取 projectId 和 projectCode
172
- // const { projectId } = pySparkParam;
173
- // const { projectCode } = pySparkParam;
174
-
175
- // console.log(`Project ID: ${projectId}`);
176
- // console.log(`Project Code: ${projectCode}`);
177
- // } else {
178
- // console.log('No PySparkParam found in global state.');
179
- // }
180
167
181
168
const conda = await Conda . getConda ( ) ;
182
169
if ( conda === undefined ) {
@@ -240,7 +227,7 @@ export class CondaEnvironmentLocator extends FSWatchingLocator {
240
227
name : `${ environment . name } ` , // 动态生成 name
241
228
status : 0 ,
242
229
detail : environment . detail ,
243
- level : environment . level
230
+ level : environment . level ,
244
231
} ;
245
232
246
233
// 创建目录,本地目录存在则表示该环境也存在,不做拉取
@@ -253,11 +240,8 @@ export class CondaEnvironmentLocator extends FSWatchingLocator {
253
240
. then ( async ( output ) => {
254
241
traceInfo ( 'Exported environment:' ) ;
255
242
traceInfo ( output ) ;
256
- isSync = await compareDetails (
257
- environment . detail ,
258
- output ,
259
- ) ;
260
- traceError ( `aaaaa: ${ isSync } ` )
243
+ isSync = await compareDetails ( environment . detail , output ) ;
244
+ traceError ( `aaaaa: ${ isSync } ` ) ;
261
245
} )
262
246
. catch ( ( error ) => {
263
247
console . error ( error ) ;
@@ -279,7 +263,7 @@ export class CondaEnvironmentLocator extends FSWatchingLocator {
279
263
// (env) => (env.prefix === expectedBasicEnv.prefix || env.name === expectedBasicEnv.name) && env.status === expectedBasicEnv.status,
280
264
// );
281
265
282
- const exists = checkAndReplaceEnv ( envs , expectedBasicEnv )
266
+ const exists = checkAndReplaceEnv ( envs , expectedBasicEnv ) ;
283
267
284
268
// 如果不存在,则将 expectedBasicEnv 添加到 envs 数组中
285
269
if ( ! exists ) {
@@ -293,7 +277,7 @@ export class CondaEnvironmentLocator extends FSWatchingLocator {
293
277
}
294
278
} else {
295
279
console . log ( 'envs_dirs 不存在或为空' ) ;
296
- traceError ( `envs_dirs 不存在或为空` )
280
+ traceError ( `envs_dirs 不存在或为空` ) ;
297
281
}
298
282
299
283
// 继续处理本地 conda 环境
@@ -302,9 +286,9 @@ export class CondaEnvironmentLocator extends FSWatchingLocator {
302
286
traceVerbose ( `Looking into conda env for executable: ${ JSON . stringify ( env ) } ` ) ;
303
287
const executablePath = await conda . getInterpreterPathForEnvironment ( env ) ;
304
288
traceVerbose ( `Found conda executable: ${ executablePath } ` ) ;
305
- yield {
306
- kind : PythonEnvKind . Conda ,
307
- executablePath,
289
+ yield {
290
+ kind : PythonEnvKind . Conda ,
291
+ executablePath,
308
292
envPath : env . prefix ,
309
293
status : env . status ?? 1 ,
310
294
detail : env . detail ,
0 commit comments