Skip to content

Export Jupyter notebooks to percent script format (Python & R)#14152

Open
seeM wants to merge 1 commit into
mainfrom
feature/notebook-export
Open

Export Jupyter notebooks to percent script format (Python & R)#14152
seeM wants to merge 1 commit into
mainfrom
feature/notebook-export

Conversation

@seeM

@seeM seeM commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

Toward #9791.

This PR adds functionality to export Jupyter notebooks to other file formats. It's designed so that third party extensions can contribute their own notebook exporters. I packaged this in a new extension (rather than the positron-notebooks-helper extension) since it has a public-facing API.

Here is the corresponding PR setting up an exporter in the Quarto extension: quarto-dev/quarto#999.

Demo:

Screen.Recording.2026-06-10.at.17.29.06.mov

Release Notes

New Features

Bug Fixes

  • N/A

Validation Steps

@positron-notebooks @:web

  1. Open a Python or R Jupyter notebook
  2. Click the "..." menu in the notebook toolbar
  3. Click "Export..."
  4. Choose Python or R
  5. Verify that the exported file is opened in a new, untitled editor tab

@seeM seeM requested a review from nstrayer June 10, 2026 12:41
@github-actions

github-actions Bot commented Jun 10, 2026

Copy link
Copy Markdown

E2E Tests 🚀
This PR will run tests tagged with: @:critical @:web

readme  valid tags

@github-actions

Copy link
Copy Markdown

PETE's assessment 🧪

Verdict: 🟢 Adequate -- The PR ships both extension-host tests for the command/registration flow and unit-style tests for the percent-script conversion, covering the new behavior at the cheapest viable levels.

What changed

  • New positron-notebook-export extension contributing a notebook.export command, a public registerNotebookExporter API, and builtin Python/R percent-script exporters (#9791).
  • Core conversion logic lives in percentNotebookExporter.ts (notebookToPercentScript); command/picker orchestration in notebookExportCommand.ts; language detection in util/notebook.ts.
  • Plus build wiring (dirs.ts, gulpfile.extensions.ts, .vscode-test.js) and a one-line positron-notebooks/tsconfig.json cleanup.

Tests in this PR

  • Unit (Vitest/Mocha) ✅ (percentNotebookExporter.test.ts -- code/markdown/raw/multi-cell/custom-prefix cases)
  • Extension host ✅ (extension.test.ts -- empty picker, language filtering, export invocation, dispose/unregister)
  • E2E (Playwright) ✅ (not warranted -- export logic is unit-covered; picker flow is stub-covered at ext-host level)

Existing coverage

The two new test files are the primary coverage and exercise the changed behavior directly: percentNotebookExporter.test.ts asserts exact output for every cell type and a custom comment prefix; extension.test.ts drives the real notebook.export command through the registration API, language filtering, selection, and disposal. No existing tests were relied upon.

Suggested additions

None required. Minor optional gap: getNotebookLanguage (util/notebook.ts) is only exercised via the metadata branch (the test notebook declares language_info.name: "test" and has no cells). The cell-language fallback (lines 26-31) and the undefined return are untested -- a small percentNotebookExporter-style or direct unit test of getNotebookLanguage covering a metadata-less notebook would close that.

Deployment note (optional)

The PR body tags @:web, which is appropriate: export() opens an untitled document via workspace.openTextDocument/showTextDocument, and the picker uses ThemeIcon.File + a file resourceUri -- both behave differently or are constrained in the web build (no native file backing). The ext-host tests stub showQuickPick and the exporter's export, so the real untitled-editor round-trip isn't exercised on web at PR time. The @:web tag is in place, but no @:positron-notebooks- or @:web-tagged e2e currently exercises notebook export specifically; consider a follow-up e2e (per the validation steps in the PR body) once the feature stabilizes.


PETE (Positron Extreme Test Experiment) - LLM-based test-coverage advisor, in pilot. Triggers on PR open and on /recheck-tests comments. Wrong verdict? Comment /recheck-tests (or /rePETE) on this PR to re-run. Please share feedback on how PETE performed here.

@seeM

seeM commented Jun 10, 2026

Copy link
Copy Markdown
Contributor Author

The failing unit tests seem to be an issue on main, since I'm seeing the same failures in other PRs.

seeM added a commit to quarto-dev/quarto that referenced this pull request Jun 11, 2026
This PR sets up a "notebook exporter" for Quarto when inside Positron, which reuses the same implementation as the `quarto.convertToQmd` command (i.e. the `quarto convert` CLI). The `quarto.convertToQmd` command is also hidden when the exporter is registered (i.e. in Positron).

Until posit-dev/positron#14152 is merged, you'll have to test against that branch. Should have no effect in VS Code.

Demo:

https://github.com/user-attachments/assets/8af2714b-1fe7-4ccc-9791-321d3d967367

I also added the outline of a test, but can't yet run it until we're able to test against Positron.

Related to posit-dev/positron#9791.
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.

1 participant