From b7550c0d0bf0cc71a8f467ac8c17f5c32d383a14 Mon Sep 17 00:00:00 2001 From: Andy Bayer Roswell Date: Tue, 23 Jul 2024 23:56:47 +0200 Subject: [PATCH] adding rmd support --- vreapis/containerizer/views.py | 9 ++++++++- vreapis/requirements.txt | 1 + 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/vreapis/containerizer/views.py b/vreapis/containerizer/views.py index d5bd464..22efce6 100644 --- a/vreapis/containerizer/views.py +++ b/vreapis/containerizer/views.py @@ -28,6 +28,7 @@ import jsonschema from slugify import slugify from github import Github, UnknownObjectException +import jupytext from catalog.serializers import CellSerializer from containerizer.RContainerizer import RContainerizer @@ -88,9 +89,15 @@ def get(self, request: Request): def post(self, request: Request): payload = request.data common.logger.debug('ExtractorHandler. payload: ' + json.dumps(payload, indent=4)) + if 'rmarkdown' in payload: + Rmd = jupytext.reads(payload['rmarkdown'], fmt='Rmd') + ipynb = jupytext.writes(Rmd, fmt='ipynb') + payload['notebook'] = ipynb kernel = payload['kernel'] cell_index = payload['cell_index'] - notebook = nbformat.reads(json.dumps(payload['notebook']), nbformat.NO_CONVERT) + if isinstance(payload['notebook'], dict): + payload['notebook'] = json.dumps(payload['notebook']) + notebook = nbformat.reads(payload['notebook'], nbformat.NO_CONVERT) source = notebook.cells[cell_index].source diff --git a/vreapis/requirements.txt b/vreapis/requirements.txt index 8979a7a..848d433 100644 --- a/vreapis/requirements.txt +++ b/vreapis/requirements.txt @@ -22,3 +22,4 @@ pytype autopep8 distro pygithub +jupytext