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

fix importing notebooks #2569

Merged
merged 2 commits into from
Jan 4, 2023
Merged

fix importing notebooks #2569

merged 2 commits into from
Jan 4, 2023

Conversation

colombod
Copy link
Member

@colombod colombod commented Dec 19, 2022

importing notebooks with markdown cells adds those to the ui.

image

This will add all markdown cells after the cell executing the import and all outputs that the imported notebook will generate

@colombod colombod added the bug Something isn't working label Dec 19, 2022
@colombod colombod linked an issue Dec 19, 2022 that may be closed by this pull request
17 tasks
@colombod
Copy link
Member Author

@marckruzik I still see a problem as the markdown cell will be added below the cell executing the #!import command. This will cause to see all other output events just under the #!import and then all the markdown after that, this looks confusing.

Can you describe the scenario you are after?

@marckruzik
Copy link
Contributor

Can you describe the scenario you are after?

I saw that markdown cells are causing an error display, so I supposed (maybe wrongly) that markdown should be displayed as well. If markdown is not displayed, that's fine by me.

[Theory]
[InlineData(".ipynb")]
[InlineData(".dib")]
public async Task It_imports_and_forwards_markdown_content_to_frontend(string notebookExt)
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure I understand the test name here. What if there is no frontend?

}
else
{
await kernel.RootKernel.SendAsync(new SubmitCode(element.Contents, element.KernelName));
Copy link
Contributor

Choose a reason for hiding this comment

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

A bunch of repeated logic in the if blocks. These can probably be hoisted up to the switch or else maybe switch is inappropriate.

@colombod
Copy link
Member Author

colombod commented Jan 4, 2023

I think this is the right shape:
image

@marckruzik what are your thoughts?

@colombod colombod marked this pull request as ready for review January 4, 2023 16:39
clear


handling markdown cells as output
@colombod colombod enabled auto-merge (rebase) January 4, 2023 18:28
@colombod colombod merged commit 63007ee into dotnet:main Jan 4, 2023
@brettfo brettfo deleted the fix_import branch January 4, 2023 19:30
var @event = new DisplayedValueProduced(element.Contents, context.Command, new[]
{
new FormattedValue("text/markdown", element.Contents),
new FormattedValue(PlainTextFormatter.MimeType, element.Contents)
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't see the plain text output being tested, and I'm not convinced this is the correct value for it. I could make the argument that the plain text version should remove the formatting characters from the Markdown, e.g. convert it to HTML and then grab the inner text from the HTML.

Copy link
Member Author

Choose a reason for hiding this comment

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

Makes sense

{
var document = await InteractiveDocument.LoadAsync(
notebookFile,
CreateKernelInfos(kernel.RootKernel as CompositeKernel));

foreach (var element in document.Elements)
{
await kernel.RootKernel.SendAsync(new SubmitCode(element.Contents, element.KernelName));
switch (element.KernelName?.ToLowerInvariant())
Copy link
Contributor

Choose a reason for hiding this comment

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

At this point this should be based on the language name, not the kernel name.

Copy link
Member Author

Choose a reason for hiding this comment

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

Correct, will do this in a new pr

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Import magic command displays errors for Markdown cells
4 participants