-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Fix markdown cell marker formatting for export to Python #14360
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
Conversation
Our tests didn't catch this because the export/import test doesn't verify that the contents of a notebook explicitly match some expected string; it only verifies that the cell markers and chdir code are present, and the result of the import is totally stubbed out. I realized this after I wrote a test to defend against this specific bug and found that notebook.functional.test.ts currently uses a MockPythonService and MockProcessService for the Python daemon, so I'd really like to run the following with a real Python interpreter--do we already do that anywhere in our testing infrastructure? runTest('Export simple notebook to Python file', async () => {
const notebookJson = `{
"metadata": {
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
}
},
"orig_nbformat": 4,
"kernelspec": {
"name": "JUNK",
"display_name": "JUNK"
}
},
"nbformat": 4,
"nbformat_minor": 2,
"cells": [
{
"source": [
"# This is markdown"
],
"cell_type": "markdown",
"metadata": {}
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"This is code\n"
]
}
],
"source": [
"print('This is code')"
]
}
]
}`;
const expectedOutput =
"# To add a new cell, type '# %%'\n# To add a new markdown cell, type '# %% [markdown]'\n# %% [markdown]\n# # This is markdown\n\n# %%\nprint('This is code')\n";
const exportInterpreterFinder = ioc.serviceManager.get<ExportInterpreterFinder>(
ExportInterpreterFinder
);
const fileSystem = ioc.serviceManager.get<IDataScienceFileSystem>(IDataScienceFileSystem);
const temp = await fileSystem.createTemporaryLocalFile('.ipynb');
await fileSystem.writeLocalFile(temp.filePath, notebookJson);
const usable = await exportInterpreterFinder.getExportInterpreter(ExportFormat.python, undefined);
assert.isDefined(usable);
const importer = ioc.serviceManager.get<INotebookImporter>(INotebookImporter);
const results = await importer.importFromFile(Uri.file(temp.filePath), usable!);
assert.include(results, expectedOutput);
}); |
Codecov Report
@@ Coverage Diff @@
## main #14360 +/- ##
=======================================
Coverage 59.44% 59.44%
=======================================
Files 716 716
Lines 39953 39953
Branches 5789 5789
=======================================
Hits 23750 23750
Misses 14946 14946
Partials 1257 1257 Continue to review full report at Codecov.
|
@@ -36,7 +36,7 @@ export class JupyterImporter implements INotebookImporter { | |||
{% endblock codecell %} | |||
{% block in_prompt %}{% endblock in_prompt %} | |||
{% block input %}{{ cell.source | ipython2python }}{% endblock input %} | |||
{% block markdowncell scoped %}{0} [markdown] | |||
{% block markdowncell scoped %}{1} [markdown] |
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.
Ahhh, good catch. I think that I had that change with my convert fixes, but accidentally reverted it before checkin. Thanks for the fix.
@joyceerhl These same tests run with real interpreters as well in our nightly flake tests, just depends on the ENV vars that are set. Thanks to Rich's recent changes they will even run on real interpreters on PR submission in vscode-jupyter. |
@IanMatthewHuff, got it, I should've noticed that we do run with real Python. In that case I just added an extra line to the test to guard against this particular case. |
Kudos, SonarCloud Quality Gate passed!
|
…-jupyter (#194) * Fix sample notebook to state that you can double click to edit a cell (#14238) * Disable surveys if running in codespaces (#14332) * Disable surveys if running in codespaces * Disable gather survey in codespaces too * For gather, show a description without the survey * Fixes for IW tests where UIKind is not defined * Fix all the tests where UIKind is not defined * Appease hygiene * Disable mailing list if running in Codespaces (#14347) * Show tensor dimensions in variable explorer (#14244) * Fix markdown cell marker formatting for export to Python (#14360)
For https://github.com/microsoft/vscode-python/issues/14359
We changed how we format
nbconvertBaseTemplateFormat
, the template itself also needed updating:vscode-python/src/client/datascience/jupyter/jupyterImporter.ts
Line 39 in 74253ef
and
vscode-python/src/client/datascience/jupyter/jupyterImporter.ts
Lines 183 to 185 in 74253ef
package-lock.json
has been regenerated by runningnpm install
(if dependencies have changed).