Skip to content
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 17 commits into from
Jul 14, 2022
Merged

Conversation

DonJayamanne
Copy link
Contributor

Fixes #7538

@@ -169,7 +170,9 @@ async function activateUnsafe(

const [serviceManager, serviceContainer] = initializeGlobals(context);
activatedServiceContainer = serviceContainer;
initializeTelemetryGlobals(serviceContainer);
initializeTelemetryGlobals((interpreter) =>
Copy link
Contributor Author

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.

let globalContainer: IServiceContainer | undefined = undefined;

export function initializeGlobals(serviceContainer: IServiceContainer) {
globalContainer = serviceContainer;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We no longer need to inject the entire service container, just a callback is sufficient.

@codecov-commenter
Copy link

codecov-commenter commented Jul 13, 2022

Codecov Report

Merging #10787 (12d9f03) into main (dd892b5) will increase coverage by 0%.
The diff coverage is 75%.

@@           Coverage Diff           @@
##            main   #10787    +/-   ##
=======================================
  Coverage     63%      63%            
=======================================
  Files        476      481     +5     
  Lines      33058    33371   +313     
  Branches    5391     5437    +46     
=======================================
+ Hits       20875    21087   +212     
- Misses     10185    10255    +70     
- Partials    1998     2029    +31     
Impacted Files Coverage Δ
src/kernels/errors/types.ts 100% <ø> (ø)
.../notebooks/controllers/vscodeNotebookController.ts 79% <ø> (ø)
src/notebooks/notebookCommandListener.ts 52% <ø> (ø)
src/telemetry.ts 100% <ø> (ø)
src/platform/errors/errorUtils.ts 72% <48%> (-4%) ⬇️
src/kernels/errors/kernelErrorHandler.node.ts 50% <50%> (ø)
src/kernels/errors/kernelErrorHandler.ts 61% <60%> (-2%) ⬇️
src/platform/common/utils/localize.ts 75% <64%> (-1%) ⬇️
...ne/diagnostics/reservedFileNameDiagnostics.node.ts 71% <71%> (ø)
...c/platform/interpreter/interpreterPackages.node.ts 80% <75%> (ø)
... and 35 more

@@ -169,7 +170,9 @@ async function activateUnsafe(

const [serviceManager, serviceContainer] = initializeGlobals(context);
activatedServiceContainer = serviceContainer;
initializeTelemetryGlobals(serviceContainer);
initializeTelemetryGlobals((interpreter) =>
serviceContainer.get<IInterpreterPackages>(IInterpreterPackages).getPackageVersions(interpreter)
Copy link
Contributor Author

Choose a reason for hiding this comment

The 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.

@@ -29,13 +29,13 @@ import {
import { noop } from '../../platform/common/utils/misc';
import { IServiceContainer } from '../../platform/ioc/types';
import { sendTelemetryEvent, Telemetry } from '../../telemetry';
import { InterpreterPackages } from '../../platform/telemetry/interpreterPackages.node';
import { InterpreterPackages } from '../../platform/interpreter/interpreterPackages.node';
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed dependency issues, installation code does not need to depend on telemetry for things like getting packages

import { PythonEnvironment } from '../pythonEnvironments/info';
import { IInterpreterPackages } from '../../telemetry';
import { IInterpreterPackages } from './types';
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved out of telemetry into interpreter.

}

export const IInterpreterPackages = Symbol('IInterpreterPackages');
export interface IInterpreterPackages {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved from telemetry folder

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I need to reference this from the new code, hence moved this from telemtry into Interrpeter & ensured telemetry doesnt depend on this.

@@ -50,6 +54,15 @@ export function registerTypes(serviceManager: IServiceManager) {
KernelProgressReporter
);

serviceManager.addSingleton<IInterpreterPackages>(IInterpreterPackages, InterpreterPackages);
serviceManager.addSingleton<IExtensionSyncActivationService>(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These things that have to do with interpeters is now in interpeters folder and no longer in telemetry folder.

@@ -1,23 +0,0 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yay (i think), service registrations in telemetry folder anymore

@@ -106,13 +105,6 @@ export type ResourceSpecificTelemetryProperties = Partial<{
kernelLiveCount: number;
}>;

export const IInterpreterPackages = Symbol('IInterpreterPackages');
export interface IInterpreterPackages {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved out of here

@DonJayamanne DonJayamanne marked this pull request as ready for review July 14, 2022 04:15
@DonJayamanne DonJayamanne requested a review from a team as a code owner July 14, 2022 04:15
Copy link
Member

@IanMatthewHuff IanMatthewHuff left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool this will be great for customers (still want Python to own this, but that can always come later). One minor question was on the listPackages possibly guarding against python extension install internally.

@DonJayamanne DonJayamanne merged commit 4d1a5c7 into main Jul 14, 2022
@DonJayamanne DonJayamanne deleted the issue7538Updated branch July 14, 2022 18:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Warn users when files override built in packages that could have caused the kernel to fail
4 participants