mwouts / jupytext

Jupyter Notebooks as Markdown Documents, Julia, Python or R scripts
https://jupytext.readthedocs.io
MIT License
6.65k stars 386 forks source link

MyST to notebook kernel metadata not taken into account #1153

Closed cmarmo closed 1 year ago

cmarmo commented 1 year ago

Dear maintainers, I am using jupytext 1.15.2 to convert MyST markdown files to .ipynb notebooks.

My notebooks make use of a C++17 kernel (provided by xeus-cling) in jupyter lab.

I am converting something like test.md running

jupytext test.md --to ipynb
The generated notebook looks like ``` { "cells": [ { "cell_type": "code", "execution_count": null, "id": "3de99dac", "metadata": {}, "outputs": [], "source": [ "#include\n", "\n", "int I;\n", "I = 5;" ] } ], "metadata": { "jupyter": { "jupytext": { "text_representation": { "extension": ".md", "format_name": "myst" } }, "kernelspec": { "display_name": "C++17", "language": "C++17", "name": "xcpp17" } } }, "nbformat": 4, "nbformat_minor": 5 } ```

And when I open it with jupyter lab I am asked to manually select the kernel.

However, running

jupytext test.md --set-kernel xcpp17 --to ipynb
generates the following notebook ``` { "cells": [ { "cell_type": "code", "execution_count": null, "id": "e0d336a0", "metadata": {}, "outputs": [], "source": [ "#include\n", "\n", "int I;\n", "I = 5;" ] } ], "metadata": { "jupyter": { "jupytext": { "text_representation": { "extension": ".md", "format_name": "myst" } }, "kernelspec": { "display_name": "C++17", "language": "C++17", "name": "xcpp17" } }, "kernelspec": { "display_name": "C++17", "language": "C++17", "name": "xcpp17" } }, "nbformat": 4, "nbformat_minor": 5 } ```

and this time the kernel is correctly taken into account when I open the notebook with jupyter lab.

It looks like in the first case the "kernelspec" related metadata are outside the "metadata" property and this prevents a correct json parsing... is that expected?

Thank you for your attention and for your time in developing jupytext!

cmarmo commented 1 year ago

After reading the code I realized my issue.. I have to unindent the "kernelspec" keyword like in

---
jupyter:
  jupytext:
    text_representation:
      extension: .md
      format_name: myst
kernelspec:
  display_name: C++17
  language: C++17
  name: xcpp17
---

I am closing the issue... sorry for the noise.