GeezerVison is showing github.com — Use activated python proc to check if modules are installed (#9644) · evaperon/vscode-python@97bad7d
File treeExpand file treeCollapse file tree Open diff view settings pythonFiles/datascience/daemon datascience/jupyter/kernels
datascience/jupyter/kernels
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboard +1Lines changed: 1 addition & 0 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +Use the correct interpreter when creating the Python execution service used as a fallback by the Daemon. |
Collapse file Copy file name to clipboard +1Lines changed: 1 addition & 0 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +Use an activated environment python process to check if modules are installed. |
Collapse file Copy file name to clipboardExpand all lines: pythonFiles/datascience/daemon/daemon_python.py +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -82,7 +82,7 @@ def __getitem__(self, item): | 82 | 82 | self.log.debug("Ignoring non-exit method during shutdown: %s", item) | 83 | 83 | raise KeyError | 84 | 84 |
| 85 | | - self.log.info("Execute rpc method %s", item) | | 85 | + self.log.info("Execute rpc method %s from %s", item, sys.executable) | 86 | 86 | return super().__getitem__(item) | 87 | 87 |
| 88 | 88 | def start(self): | |
Collapse file Copy file name to clipboardExpand all lines: src/client/common/installer/productInstaller.ts +4-2Lines changed: 4 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -78,13 +78,15 @@ export abstract class BaseInstaller { | 78 | 78 | return true; | 79 | 79 | } | 80 | 80 | // User may have customized the module name or provided the fully qualified path. | 81 | | - const pythonPath = isResource(resource) ? undefined : resource.path; | | 81 | + const interpreter = isResource(resource) ? undefined : resource; | 82 | 82 | const uri = isResource(resource) ? resource : undefined; | 83 | 83 | const executableName = this.getExecutableNameFromSettings(product, uri); | 84 | 84 |
| 85 | 85 | const isModule = this.isExecutableAModule(product, uri); | 86 | 86 | if (isModule) { | 87 | | - const pythonProcess = await this.serviceContainer.get<IPythonExecutionFactory>(IPythonExecutionFactory).create({ resource: uri, pythonPath }); | | 87 | + const pythonProcess = await this.serviceContainer | | 88 | + .get<IPythonExecutionFactory>(IPythonExecutionFactory) | | 89 | + .createActivatedEnvironment({ resource: uri, interpreter, allowEnvironmentFetchExceptions: true }); | 88 | 90 | return pythonProcess.isModuleInstalled(executableName); | 89 | 91 | } else { | 90 | 92 | const process = await this.serviceContainer.get<IProcessServiceFactory>(IProcessServiceFactory).create(uri); | |
Collapse file Copy file name to clipboardExpand all lines: src/client/common/process/pythonExecutionFactory.ts +4-4Lines changed: 4 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -63,15 +63,15 @@ export class PythonExecutionFactory implements IPythonExecutionFactory { | 63 | 63 | const disposables = this.serviceContainer.get<IDisposableRegistry>(IDisposableRegistry); | 64 | 64 | const interpreterService = this.serviceContainer.get<IInterpreterService>(IInterpreterService); | 65 | 65 | const logger = this.serviceContainer.get<IProcessLogger>(IProcessLogger); | | 66 | + | | 67 | + const interpreter = await interpreterService.getInterpreterDetails(pythonPath); | 66 | 68 | const activatedProcPromise = this.createActivatedEnvironment({ | 67 | 69 | allowEnvironmentFetchExceptions: true, | 68 | | - pythonPath: pythonPath, | | 70 | + interpreter: interpreter, | 69 | 71 | resource: options.resource, | 70 | 72 | bypassCondaExecution: true | 71 | 73 | }); | 72 | | - | 73 | 74 | // No daemon support in Python 2.7. | 74 | | - const interpreter = await interpreterService.getInterpreterDetails(pythonPath); | 75 | 75 | if (interpreter?.version && interpreter.version.major < 3) { | 76 | 76 | return activatedProcPromise!; | 77 | 77 | } | @@ -90,7 +90,7 @@ export class PythonExecutionFactory implements IPythonExecutionFactory { | 90 | 90 | return daemon; | 91 | 91 | }; | 92 | 92 |
| 93 | | - // Ensure we do not create muliple daemon pools for the same python interpreter. | | 93 | + // Ensure we do not create multiple daemon pools for the same python interpreter. | 94 | 94 | let promise = this.daemonsPerPythonService.get(daemonPoolKey); | 95 | 95 | if (!promise) { | 96 | 96 | promise = start(); | |
Collapse file Copy file name to clipboardExpand all lines: src/client/common/process/types.ts -1Lines changed: 0 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -99,7 +99,6 @@ export type DaemonExecutionFactoryCreationOptions = ExecutionFactoryCreationOpti | 99 | 99 | }; | 100 | 100 | export type ExecutionFactoryCreateWithEnvironmentOptions = { | 101 | 101 | resource?: Uri; | 102 | | - pythonPath?: string; | 103 | 102 | interpreter?: PythonInterpreter; | 104 | 103 | allowEnvironmentFetchExceptions?: boolean; | 105 | 104 | /** | |
Collapse file Copy file name to clipboardExpand all lines: src/client/datascience/jupyter/kernels/kernelService.ts +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -227,7 +227,7 @@ export class KernelService { | 227 | 227 | throw new Error('Interpreter does not have a display name'); | 228 | 228 | } | 229 | 229 |
| 230 | | - const execServicePromise = this.execFactory.create({ pythonPath: interpreter.path }); | | 230 | + const execServicePromise = this.execFactory.createActivatedEnvironment({ interpreter, allowEnvironmentFetchExceptions: true, bypassCondaExecution: true }); | 231 | 231 | // Swallow errors if we get out of here and not resolve this. | 232 | 232 | execServicePromise.ignoreErrors(); | 233 | 233 | const name = this.generateKernelNameForIntepreter(interpreter); | |
Collapse file Copy file name to clipboardExpand all lines: src/test/common/installer/installer.unit.test.ts +2-2Lines changed: 2 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -476,7 +476,7 @@ suite('Module Installer only', () => { | 476 | 476 | const pythonExecutionFactory = TypeMoq.Mock.ofType<IPythonExecutionFactory>(); | 477 | 477 | const pythonExecutionService = TypeMoq.Mock.ofType<IPythonExecutionService>(); | 478 | 478 | serviceContainer.setup(c => c.get(TypeMoq.It.isValue(IPythonExecutionFactory))).returns(() => pythonExecutionFactory.object); | 479 | | - pythonExecutionFactory.setup(p => p.create(TypeMoq.It.isAny())).returns(() => Promise.resolve(pythonExecutionService.object)); | | 479 | + pythonExecutionFactory.setup(p => p.createActivatedEnvironment(TypeMoq.It.isAny())).returns(() => Promise.resolve(pythonExecutionService.object)); | 480 | 480 | pythonExecutionService | 481 | 481 | // tslint:disable-next-line: no-any | 482 | 482 | .setup(p => (p as any).then) | @@ -496,7 +496,7 @@ suite('Module Installer only', () => { | 496 | 496 | const pythonExecutionFactory = TypeMoq.Mock.ofType<IPythonExecutionFactory>(); | 497 | 497 | const pythonExecutionService = TypeMoq.Mock.ofType<IPythonExecutionService>(); | 498 | 498 | serviceContainer.setup(c => c.get(TypeMoq.It.isValue(IPythonExecutionFactory))).returns(() => pythonExecutionFactory.object); | 499 | | - pythonExecutionFactory.setup(p => p.create(TypeMoq.It.isAny())).returns(() => Promise.resolve(pythonExecutionService.object)); | | 499 | + pythonExecutionFactory.setup(p => p.createActivatedEnvironment(TypeMoq.It.isAny())).returns(() => Promise.resolve(pythonExecutionService.object)); | 500 | 500 | pythonExecutionService | 501 | 501 | // tslint:disable-next-line: no-any | 502 | 502 | .setup(p => (p as any).then) | |
Collapse file Copy file name to clipboardExpand all lines: src/test/datascience/jupyter/kernels/kernelService.unit.test.ts +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -51,7 +51,7 @@ suite('Data Science - KernelService', () => { | 51 | 51 | execService = mock(PythonExecutionService); | 52 | 52 | installer = mock(ProductInstaller); | 53 | 53 | jupyterInterpreterExecutionService = mock(JupyterCommandFinderInterpreterExecutionService); | 54 | | - when(execFactory.create(anything())).thenResolve(instance(execService)); | | 54 | + when(execFactory.createActivatedEnvironment(anything())).thenResolve(instance(execService)); | 55 | 55 | // tslint:disable-next-line: no-any | 56 | 56 | (instance(execService) as any).then = undefined; | 57 | 57 |
| |
|