Skip to content

Commit 9499794

Browse files
author
msxfscyx
committed
3.9.3 环境管理
1 parent 71f56a6 commit 9499794

File tree

4 files changed

+35
-6
lines changed

4 files changed

+35
-6
lines changed

src/client/environmentApi.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,8 +235,18 @@ export function buildEnvironmentApi(
235235
},
236236
get known(): Environment[] {
237237
sendApiTelemetry('known');
238-
return discoveryApi
239-
.getEnvs()
238+
const envs = discoveryApi.getEnvs()
239+
envs.sort((a, b) => {
240+
// Move items with level 0 to the front
241+
if (a.level === 0 && b.level !== 0) {
242+
return -1; // a should come before b
243+
}
244+
if (a.level !== 0 && b.level === 0) {
245+
return 1; // b should come before a
246+
}
247+
return 0; // keep original order if both are 0 or neither is 0
248+
});
249+
return envs
240250
.filter((e) => filterUsingVSCodeContext(e))
241251
.map((e) => convertEnvInfoAndGetReference(e));
242252
},

src/client/extension.ts

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ import { ProposedExtensionAPI } from './proposedApiTypes';
4848
import { buildProposedApi } from './proposedApi';
4949
import ContextManager from './pythonEnvironments/base/locators/composite/envsCollectionService';
5050
import { PySparkParam } from './browser/extension';
51+
import * as fs from 'fs';
52+
import * as path from 'path';
5153

5254
durations.codeLoadingTime = stopWatch.elapsedTime;
5355

@@ -60,6 +62,17 @@ let activatedServiceContainer: IServiceContainer | undefined;
6062
/////////////////////////////
6163
// public functions
6264

65+
// Function to write PySparkParam to a file
66+
function writePySparkParamToFile(params: PySparkParam, filePath: string): void {
67+
// Convert the object to a string in the required format
68+
const content = Object.entries(params)
69+
.map(([key, value]) => `${key} = ${value}`)
70+
.join(',\n');
71+
72+
// Write the content to the specified file
73+
fs.writeFileSync(filePath, content);
74+
}
75+
6376
export async function activate(context: IExtensionContext): Promise<PythonExtension> {
6477
let api: PythonExtension;
6578
let ready: Promise<void>;
@@ -75,12 +88,12 @@ export async function activate(context: IExtensionContext): Promise<PythonExtens
7588
}),
7689
);
7790

78-
let gatewayUri = "http://10.245.23.158:8080";
91+
let gatewayUri = 'http://easdsp-gateway-bdpenv3-test.msxf.msxfyun.test';
7992
const runEnv = process.env.RUN_ENV;
8093

8194
if (runEnv === 'online') {
8295
console.log('当前运行环境: online');
83-
gatewayUri = "http://easdsp-gateway.msxf.lo";
96+
gatewayUri = 'http://easdsp-gateway.msxf.lo';
8497
} else {
8598
console.log('当前运行环境: 非 online');
8699
}
@@ -90,6 +103,11 @@ export async function activate(context: IExtensionContext): Promise<PythonExtens
90103
commands.registerCommand('pyspark.paramRegister.copy', (pySparkParam: PySparkParam) => {
91104
console.log(`PySparkParam-python: ${JSON.stringify(pySparkParam)}`);
92105
context.globalState.update('pyspark.paramRegister.copy', pySparkParam);
106+
// 将项目信息写到本地
107+
const filePath = path.join('/tmp', 'pySparkParam.txt');
108+
// Write the pySparkParam to the file
109+
writePySparkParamToFile(pySparkParam, filePath);
110+
console.log(`pySparkParam has been written to ${filePath}`);
93111
}),
94112
);
95113

src/client/pythonEnvironments/base/locators/lowLevel/condaLocator.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ async function fetchEnvironments(): Promise<PySparkEnvironmentMeta[]> {
106106
console.log('No PySparkParam found in global state.');
107107
}
108108

109-
const response = await fetch(`${ContextManager.getInstance().getContext().globalState.get<string>('gateway.addr')}/env/pyspark/list?proId=${proId}`, {
109+
const response = await fetch(`${ContextManager.getInstance().getContext().globalState.get<string>('gateway.addr')}/api/v1/env/pyspark/list?proId=${proId}`, {
110110
method: 'GET',
111111
headers: {
112112
Cookie: 'token=2345fc15-fe44-4e3b-afbc-24688c2f5f70;userId=idegw',

src/test/pythonEnvironments/base/common.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,8 @@ export function sortedEnvs(envs: PythonEnvInfo[]): PythonEnvInfo[] {
230230
return envs.sort((env1, env2) => {
231231
const env1str = `${env1.kind}-${env1.executable.filename}-${getVersionString(env1.version)}`;
232232
const env2str = `${env2.kind}-${env2.executable.filename}-${getVersionString(env2.version)}`;
233-
return env1str.localeCompare(env2str);
233+
// return env1str.localeCompare(env2str);
234+
return env2str.localeCompare(env1str);
234235
});
235236
}
236237

0 commit comments

Comments
 (0)