-
Notifications
You must be signed in to change notification settings - Fork 294
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Warn when files could override Python modules #10787
Merged
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
3e030fd
Misc
DonJayamanne 8b63a24
Fixes
DonJayamanne 873a200
Changes
DonJayamanne ea4d303
misc
DonJayamanne bb02afc
Add tests
DonJayamanne 5b0db64
Fixes
DonJayamanne bff8c98
Misc
DonJayamanne 38df452
Fix tests
DonJayamanne 7b989cd
Misc
DonJayamanne 22d60bd
Remove console logging
DonJayamanne 267fc95
More fixes
DonJayamanne c3c9a4a
Added tests
DonJayamanne 641afe1
Misc
DonJayamanne e861778
Move files
DonJayamanne 3e2bdc4
More tests
DonJayamanne ec23f76
Misc
DonJayamanne 1d1360a
Address code review comments
DonJayamanne File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Warn users when a Python file could override an existing Python package (there by interfering with the kernels. [More info](https://aka.ms/JupyterKernelStartFailureOverrideReservedName)). | ||
This feature could be turned off via the setting `"jupyter.diagnostics.reservedPythonNames.enabled": false`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -70,7 +70,6 @@ import { registerTypes as registerKernelTypes } from './kernels/serviceRegistry. | |
import { registerTypes as registerNotebookTypes } from './notebooks/serviceRegistry.node'; | ||
import { registerTypes as registerInteractiveTypes } from './interactive-window/serviceRegistry.node'; | ||
import { registerTypes as registerStandaloneTypes } from './standalone/serviceRegistry.node'; | ||
import { registerTypes as registerTelemetryTypes } from './platform/telemetry/serviceRegistry.node'; | ||
import { registerTypes as registerWebviewTypes } from './webviews/extension-side/serviceRegistry.node'; | ||
import { IExtensionActivationManager } from './platform/activation/types'; | ||
import { | ||
|
@@ -93,6 +92,7 @@ import { ConsoleLogger } from './platform/logging/consoleLogger'; | |
import { FileLogger } from './platform/logging/fileLogger.node'; | ||
import { createWriteStream } from 'fs-extra'; | ||
import { initializeGlobals as initializeTelemetryGlobals } from './platform/telemetry/telemetry'; | ||
import { IInterpreterPackages } from './platform/interpreter/types'; | ||
|
||
durations.codeLoadingTime = stopWatch.elapsedTime; | ||
|
||
|
@@ -169,7 +169,9 @@ async function activateUnsafe( | |
|
||
const [serviceManager, serviceContainer] = initializeGlobals(context); | ||
activatedServiceContainer = serviceContainer; | ||
initializeTelemetryGlobals(serviceContainer); | ||
initializeTelemetryGlobals((interpreter) => | ||
serviceContainer.get<IInterpreterPackages>(IInterpreterPackages).getPackageVersions(interpreter) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Moved IInterpreterPackages from telemetry folder into Interprter folder, and passed just a callback into interpreters layer, we don't need everything, a callback is sufficient. |
||
); | ||
const activationPromise = activateComponents(context, serviceManager, serviceContainer); | ||
|
||
//=============================================== | ||
|
@@ -317,7 +319,6 @@ async function activateLegacy( | |
|
||
// Register the rest of the types (platform is first because it's needed by others) | ||
registerPlatformTypes(serviceManager); | ||
registerTelemetryTypes(serviceManager); | ||
registerKernelTypes(serviceManager, isDevMode); | ||
registerNotebookTypes(serviceManager); | ||
registerInteractiveTypes(serviceManager); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
import { inject, injectable, optional } from 'inversify'; | ||
import { Uri } from 'vscode'; | ||
import { IApplicationShell, ICommandManager, IWorkspaceService } from '../../platform/common/application/types'; | ||
import { | ||
IBrowserService, | ||
IConfigurationService, | ||
IExtensions, | ||
IsWebExtension, | ||
Resource | ||
} from '../../platform/common/types'; | ||
import { DataScience, Common } from '../../platform/common/utils/localize'; | ||
import { IKernelDependencyService } from '../types'; | ||
import { IJupyterInterpreterDependencyManager, IJupyterServerUriStorage } from '../jupyter/types'; | ||
import * as path from '../../platform/vscode-path/resources'; | ||
import { IReservedPythonNamedProvider } from '../../platform/interpreter/types'; | ||
import { JupyterKernelStartFailureOverrideReservedName } from '../../platform/interpreter/constants'; | ||
import { DataScienceErrorHandler } from './kernelErrorHandler'; | ||
import { getDisplayPath } from '../../platform/common/platform/fs-paths'; | ||
|
||
@injectable() | ||
export class DataScienceErrorHandlerNode extends DataScienceErrorHandler { | ||
constructor( | ||
@inject(IApplicationShell) applicationShell: IApplicationShell, | ||
@inject(IJupyterInterpreterDependencyManager) | ||
@optional() | ||
dependencyManager: IJupyterInterpreterDependencyManager | undefined, | ||
@inject(IBrowserService) browser: IBrowserService, | ||
@inject(IConfigurationService) configuration: IConfigurationService, | ||
@inject(IKernelDependencyService) | ||
@optional() | ||
kernelDependency: IKernelDependencyService | undefined, | ||
@inject(IWorkspaceService) workspaceService: IWorkspaceService, | ||
@inject(IJupyterServerUriStorage) serverUriStorage: IJupyterServerUriStorage, | ||
@inject(ICommandManager) commandManager: ICommandManager, | ||
@inject(IsWebExtension) isWebExtension: boolean, | ||
@inject(IExtensions) extensions: IExtensions, | ||
@inject(IReservedPythonNamedProvider) private readonly reservedPythonNames: IReservedPythonNamedProvider | ||
) { | ||
super( | ||
applicationShell, | ||
dependencyManager, | ||
browser, | ||
configuration, | ||
kernelDependency, | ||
workspaceService, | ||
serverUriStorage, | ||
commandManager, | ||
isWebExtension, | ||
extensions | ||
); | ||
} | ||
protected override async addErrorMessageIfPythonArePossiblyOverridingPythonModules( | ||
messages: string[], | ||
resource: Resource | ||
) { | ||
// Looks like some other module is missing. | ||
// Sometimes when you create files like xml.py, then kernel startup fails due to xml.dom module not being found. | ||
const problematicFiles = await this.getFilesInWorkingDirectoryThatCouldPotentiallyOverridePythonModules( | ||
resource | ||
); | ||
if (problematicFiles.length > 0) { | ||
const cwd = resource ? path.dirname(resource) : undefined; | ||
const fileLinks = problematicFiles.map((item) => { | ||
if (item.type === 'file') { | ||
const displayPath = resource ? getDisplayPath(item.uri, [], cwd) : path.basename(item.uri); | ||
return `<a href='${item.uri.toString()}?line=1'>${displayPath}</a>`; | ||
} else { | ||
const displayPath = resource | ||
? getDisplayPath(item.uri, [], cwd) | ||
: `${path.basename(path.dirname(item.uri))}/__init__.py`; | ||
return `<a href='${item.uri.toString()}?line=1'>${displayPath}</a>`; | ||
} | ||
}); | ||
let files = ''; | ||
if (fileLinks.length === 1) { | ||
files = fileLinks[0]; | ||
} else { | ||
files = `${fileLinks.slice(0, -1).join(', ')} ${Common.and()} ${fileLinks.slice(-1)}`; | ||
} | ||
messages.push( | ||
DataScience.filesPossiblyOverridingPythonModulesMayHavePreventedKernelFromStarting().format(files) | ||
); | ||
messages.push(DataScience.listOfFilesWithLinksThatMightNeedToBeRenamed().format(files)); | ||
messages.push(Common.clickHereForMoreInfoWithHtml().format(JupyterKernelStartFailureOverrideReservedName)); | ||
} | ||
} | ||
protected override async getFilesInWorkingDirectoryThatCouldPotentiallyOverridePythonModules( | ||
resource: Resource | ||
): Promise<{ uri: Uri; type: 'file' | '__init__' }[]> { | ||
return resource ? this.reservedPythonNames.getUriOverridingReservedPythonNames(path.dirname(resource)) : []; | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just pass a callback instead of passing the entire interface, as we dont want the telemetry layer to have any dependencies on interpreter code.