@@ -10,10 +10,8 @@ import { FSWatchingLocator } from './fsWatchingLocator';
1010import { pathExists } from 'fs-extra' ;
1111import * as crypto from 'crypto' ;
1212
13-
1413import { exec } from 'child_process' ;
15- import ContextManager from '../composite/envsCollectionService' ;
16- import { PySparkParam } from '../../../../browser/extension' ;
14+ import CacheMap from '../composite/envsReducer' ;
1715
1816function exportCondaEnv ( name : string ) : Promise < string > {
1917 return new Promise ( ( resolve , reject ) => {
@@ -36,16 +34,16 @@ function preprocessAndHashDependencies(value: string): string {
3634 const lines = value . split ( '\n' ) ;
3735
3836 // 找到 `dependencies:` 的起始行
39- const dependenciesStartIndex = lines . findIndex ( line => line . trim ( ) === 'dependencies:' ) ;
37+ const dependenciesStartIndex = lines . findIndex ( ( line ) => line . trim ( ) === 'dependencies:' ) ;
4038
4139 // 找到 `dependencies:` 之后的 `prefix:` 行,表示 dependencies 结束
42- const prefixStartIndex = lines . findIndex ( line => line . trim ( ) . startsWith ( 'prefix:' ) ) ;
40+ const prefixStartIndex = lines . findIndex ( ( line ) => line . trim ( ) . startsWith ( 'prefix:' ) ) ;
4341
4442 // 提取 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 ( ) ) ;
4644
4745 // 去除空行
48- const filteredDependencies = dependencies . filter ( line => line !== '' ) ;
46+ const filteredDependencies = dependencies . filter ( ( line ) => line !== '' ) ;
4947
5048 // 对 dependencies 内容进行排序
5149 const sortedDependencies = filteredDependencies . sort ( ) ;
@@ -64,7 +62,7 @@ async function compareDetails(storeDetail: string, detail: string | undefined):
6462 try {
6563 const storeDetailHash = preprocessAndHashDependencies ( storeDetail ) ;
6664 const detailHash = preprocessAndHashDependencies ( detail ) ;
67-
65+
6866 return storeDetailHash === detailHash ;
6967 } catch ( error ) {
7068 traceError ( 'Error comparing details:' , error ) ;
@@ -86,34 +84,38 @@ interface PySparkEnvironmentMeta {
8684
8785async function fetchEnvironments ( ) : Promise < PySparkEnvironmentMeta [ ] > {
8886 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 ') ;
9189
92- let proId = "0" ;
90+ let proId = '0' ;
9391 // 检查是否成功获取到数据
94- if ( pySparkParam ) {
92+ // if (pySparkParam) {
93+ if ( projectId && projectCode ) {
9594 // 通过属性名获取 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+ // }
105104 } else {
106105 console . log ( 'No PySparkParam found in global state.' ) ;
107106 }
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+ } ,
115117 } ,
116- } ) ;
118+ ) ;
117119
118120 if ( ! response . ok ) {
119121 throw new Error ( 'Network response was not ok' ) ;
@@ -123,7 +125,7 @@ async function fetchEnvironments(): Promise<PySparkEnvironmentMeta[]> {
123125 return environments ;
124126 } catch ( error ) {
125127 console . error ( 'Error fetching environments:' , error ) ;
126- traceError ( `Error fetching environments: ${ error } ` )
128+ traceError ( `Error fetching environments: ${ error } ` ) ;
127129 return [ ] ; // 返回空数组作为错误处理
128130 }
129131}
@@ -162,21 +164,6 @@ export class CondaEnvironmentLocator extends FSWatchingLocator {
162164
163165 // eslint-disable-next-line class-methods-use-this
164166 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- // }
180167
181168 const conda = await Conda . getConda ( ) ;
182169 if ( conda === undefined ) {
@@ -240,7 +227,7 @@ export class CondaEnvironmentLocator extends FSWatchingLocator {
240227 name : `${ environment . name } ` , // 动态生成 name
241228 status : 0 ,
242229 detail : environment . detail ,
243- level : environment . level
230+ level : environment . level ,
244231 } ;
245232
246233 // 创建目录,本地目录存在则表示该环境也存在,不做拉取
@@ -253,11 +240,8 @@ export class CondaEnvironmentLocator extends FSWatchingLocator {
253240 . then ( async ( output ) => {
254241 traceInfo ( 'Exported environment:' ) ;
255242 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 } ` ) ;
261245 } )
262246 . catch ( ( error ) => {
263247 console . error ( error ) ;
@@ -279,7 +263,7 @@ export class CondaEnvironmentLocator extends FSWatchingLocator {
279263 // (env) => (env.prefix === expectedBasicEnv.prefix || env.name === expectedBasicEnv.name) && env.status === expectedBasicEnv.status,
280264 // );
281265
282- const exists = checkAndReplaceEnv ( envs , expectedBasicEnv )
266+ const exists = checkAndReplaceEnv ( envs , expectedBasicEnv ) ;
283267
284268 // 如果不存在,则将 expectedBasicEnv 添加到 envs 数组中
285269 if ( ! exists ) {
@@ -293,7 +277,7 @@ export class CondaEnvironmentLocator extends FSWatchingLocator {
293277 }
294278 } else {
295279 console . log ( 'envs_dirs 不存在或为空' ) ;
296- traceError ( `envs_dirs 不存在或为空` )
280+ traceError ( `envs_dirs 不存在或为空` ) ;
297281 }
298282
299283 // 继续处理本地 conda 环境
@@ -302,9 +286,9 @@ export class CondaEnvironmentLocator extends FSWatchingLocator {
302286 traceVerbose ( `Looking into conda env for executable: ${ JSON . stringify ( env ) } ` ) ;
303287 const executablePath = await conda . getInterpreterPathForEnvironment ( env ) ;
304288 traceVerbose ( `Found conda executable: ${ executablePath } ` ) ;
305- yield {
306- kind : PythonEnvKind . Conda ,
307- executablePath,
289+ yield {
290+ kind : PythonEnvKind . Conda ,
291+ executablePath,
308292 envPath : env . prefix ,
309293 status : env . status ?? 1 ,
310294 detail : env . detail ,
0 commit comments