forked from microsoft/vscode-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathremoteTestHelpers.ts
More file actions
61 lines (55 loc) · 2.31 KB
/
remoteTestHelpers.ts
File metadata and controls
61 lines (55 loc) · 2.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import { traceInfo } from '../../client/common/logger';
import { IPythonExecutionFactory, IPythonExecutionService, Output } from '../../client/common/process/types';
import { IDisposableRegistry } from '../../client/common/types';
import { createDeferred, sleep } from '../../client/common/utils/async';
import { DataScienceIocContainer } from './dataScienceIocContainer';
import { getIPConnectionInfo } from './jupyterHelpers';
export async function createPythonService(
ioc: DataScienceIocContainer,
versionRequirement?: number
): Promise<IPythonExecutionService | undefined> {
if (!ioc.mockJupyter) {
const python = await ioc.getJupyterCapableInterpreter();
const pythonFactory = ioc.get<IPythonExecutionFactory>(IPythonExecutionFactory);
if (python && python.version?.major && (!versionRequirement || python.version?.major > versionRequirement)) {
return pythonFactory.createActivatedEnvironment({
resource: undefined,
interpreter: python,
allowEnvironmentFetchExceptions: true,
bypassCondaExecution: true
});
}
}
}
export async function startRemoteServer(
ioc: DataScienceIocContainer,
pythonService: IPythonExecutionService,
args: string[]
): Promise<string> {
const connectionFound = createDeferred();
const exeResult = pythonService.execObservable(args, {
throwOnStdErr: false
});
ioc.get<IDisposableRegistry>(IDisposableRegistry).push(exeResult);
exeResult.out.subscribe(
(output: Output<string>) => {
traceInfo(`Remote server output: ${output.out}`);
const connectionURL = getIPConnectionInfo(output.out);
if (connectionURL) {
connectionFound.resolve(connectionURL);
}
},
(e) => {
traceInfo(`Remote server error: ${e}`);
connectionFound.reject(e);
}
);
traceInfo('Connecting to remote server');
const connString = await connectionFound.promise;
const uri = connString as string;
// Wait another 3 seconds to give notebook time to be ready. Not sure
// how else to know when it's okay to connect to. Mac on azure seems
// to connect too fast and then is unable to actually communicate.
await sleep(3000);
return uri;
}