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

Unify node/web kernel and remove iw reference in kernel component #10853

Merged
merged 10 commits into from
Jul 20, 2022

Conversation

rebornix
Copy link
Member

@rebornix rebornix commented Jul 18, 2022

Attempt to unify kernel.web/node.base. While trying to merge them, I found that the major difference between them is how we should generate start up code for interactive window debugging. It feels wrong that kernel needs to be aware of the logic of interactive window debugging so this PR tries to switch this to provider model.

@DonJayamanne let's meet offline and discuss about this PR.

  • Pull request represents a single change (i.e. not fixing disparate/unrelated things in a single PR).
  • Title summarizes what is changing.
  • Has a news entry file (remember to thank yourself!).
  • Appropriate comments and documentation strings in the code.
  • Has sufficient logging.
  • Has telemetry for feature-requests.
  • Unit tests & system/integration tests are added/updated.
  • Test plan is updated as appropriate.
  • package-lock.json has been regenerated by running npm install (if dependencies have changed).

@rebornix rebornix force-pushed the rebornix/unify-kernel branch from c89f1e3 to a95286f Compare July 18, 2022 23:17
@codecov-commenter
Copy link

codecov-commenter commented Jul 19, 2022

Codecov Report

Merging #10853 (e6a3ac8) into main (4910e9b) will increase coverage by 10%.
The diff coverage is 89%.

❗ Current head e6a3ac8 differs from pull request most recent head 832a4d8. Consider uploading reports for the commit 832a4d8 to get more accurate results

@@           Coverage Diff            @@
##            main   #10853     +/-   ##
========================================
+ Coverage     52%      63%    +10%     
========================================
  Files        486      483      -3     
  Lines      33762    33711     -51     
  Branches    5500     5501      +1     
========================================
+ Hits       17757    21366   +3609     
+ Misses     14284    10305   -3979     
- Partials    1721     2040    +319     
Impacted Files Coverage Δ
src/kernels/kernelStartupCodeProvider.node.ts 80% <80%> (ø)
...active-window/debugger/startupCodeProvider.node.ts 88% <88%> (ø)
...-window/debugger/interactiveWindowDebugger.node.ts 68% <100%> (+56%) ⬆️
src/interactive-window/serviceRegistry.node.ts 100% <100%> (ø)
src/kernels/kernel.ts 81% <100%> (ø)
src/kernels/kernelProvider.node.ts 100% <100%> (+1%) ⬆️
src/kernels/serviceRegistry.node.ts 95% <100%> (+<1%) ⬆️
src/kernels/types.ts 100% <100%> (ø)
...ide/dataviewer/dataViewerDependencyService.node.ts 86% <0%> (-14%) ⬇️
.../kernels/raw/launcher/kernelEnvVarsService.node.ts 71% <0%> (-10%) ⬇️
... and 263 more

@rebornix rebornix marked this pull request as ready for review July 19, 2022 20:23
@rebornix rebornix requested a review from a team as a code owner July 19, 2022 20:23
import { IExtensionContext } from '../../platform/common/types';

@injectable()
export class InteractiveWindowDebuggingStartupCodeProvider implements IStartupCodeProvider {
Copy link
Contributor

Choose a reason for hiding this comment

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

Seems like these could be the same. Just use the fs.readFile on the extension URI for both.

Copy link
Contributor

Choose a reason for hiding this comment

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

From what I remember, this same code applies to desktop extension as well, when debugging using remote jupyter kernels. Hence we need this same code for non-web extension as well

Copy link
Contributor

Choose a reason for hiding this comment

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

aaah, I can see that this is the same code in InteractiveWindowDebuggingStartupCodeProvider.node & .web
Yeah, would prefer if we could have the same class to do both, rather than having two seprate classes with the same logic, then the logic for debugging remote jupyter kernels is in one place, instead of being split across two files.

Copy link
Member Author

Choose a reason for hiding this comment

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

yep, agree.


async getCode(kernel: IKernel): Promise<string[]> {
if (!this.isWebExtension) {
const useNewDebugger = this.configService.getSettings(undefined).forceIPyKernelDebugger === true;
Copy link
Member Author

Choose a reason for hiding this comment

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

Now I merged the code for both Web and Node. I'm not sure though if the setting check on Node is still necessary but I kept it @rchiodo

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah this is really confusing. Maybe a comment? The addRunCellHook is necessary when using ipykernel 6 with the old interactive window debugger.

The old interactive window debugger only supported local though.

if (
!(
isLocalConnection(kernel.kernelConnectionMetadata) &&
!this.configService.getSettings(undefined).forceIPyKernelDebugger
Copy link
Contributor

Choose a reason for hiding this comment

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

is it necessary to pass undefined as a parameter?

traceInfo('UpdateWorkingDirectoryAndPath in Kernel');
return this.getChangeDirectoryCode(kernel, suggestedDir);
}
}
Copy link
Contributor

@sadasant sadasant Jul 19, 2022

Choose a reason for hiding this comment

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

I'm not sure how much it would make sense to merge the tow ways to resolve the suggested dir, but I feel that with a new local method the code can be much simpler to parse. Something like:

private async resolveDirectory(kernel: IKernel, path?: Uri): Promise<Uri | undefined> {
    let dir: Uri | undefined;
    if (!path) {
        dir = await calculateWorkingDirectory(
            this.configService,
            this.workspaceService,
            this.fs,
            kernel.resourceUri
        )
    } else {
        dir = Uri.file(
            expandWorkingDir(
                getFilePath(path),
                kernel.resourceUri,
                this.workspaceService,
                this.configService.getSettings(kernel.resourceUri)
            )
        );
    }
    if (dir && (await this.fs.exists(dir))) {
        return dir;
    }
    return;
}

Would allow us to do something like:

        if (
             isLocalConnection(kernel.kernelConnectionMetadata) ||
             isLocalHostConnection(kernel.kernelConnectionMetadata)
         ) {
             let suggestedDir = await this.resolveDirectory(kernel);
             if (kernel.resourceUri && (await this.fs.exists(kernel.resourceUri))) {
                 suggestedDir = await this.resolveDirectory(kernel, suggestedDir);
             }
             if (suggestedDir) {
                 traceInfo('UpdateWorkingDirectoryAndPath in Kernel');
                 return this.getChangeDirectoryCode(kernel, suggestedDir);
             }
         }

Copy link
Contributor

@sadasant sadasant Jul 19, 2022

Choose a reason for hiding this comment

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

if this doesn't look valuable, feel free to resolve/ignore it!

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks, I'll consider having a new PR taking this suggestion!

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.

5 participants