question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Jupyter extension for Jupytext

See original GitHub issue

An extension for Jupyter would make the configuration of paired notebooks easier. Rather than asking to edit the jupytext_formats metadata, we should offer the user an interface where the user can select the desired notebook extensions (among ipynb, py, jl, R, md, Rmd; the order matters), and the format for each extension (default, light, percent, sphinx…).

The documentation on how to distribute a notebook extension is here. Extensions have to be written in Javascript, which I have almost never practiced before - help is welcome!

Useful references are:

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:2
  • Comments:27 (26 by maintainers)

github_iconTop GitHub Comments

1reaction
fwoutscommented, Feb 9, 2019

@mwouts Sorry for the delay! It looks like JSONValue is a custom type defined by @phosphor/coreutils here: https://github.com/phosphorjs/phosphor/blob/cdb412e9dfb9a987b99143e4be79d477e5136832/packages/coreutils/src/json.ts#L21

What this is saying is basically: “this could be anything” (it’s effectively untyped). In this specific case, I think the jupytext field is likely to be an object with a specific structure (including the formats field you expect).

You could do the following:

// Using an unsafe cast (tell TypeScript you know what type this is).
const jupytextConfig = notebook_tracker.currentWidget.context.model.metadata.get("jupytext") as JupytextConfig;

interface JupytextConfig {
  formats: string[];
}

Or if you want to catch any unexpected values, a more verbose approach:

const jupytextConfig = notebook_tracker.currentWidget.context.model.metadata.get("jupytext");
if (jupytextConfig === null || typeof jupytextConfig !== "object") {
  throw new Error("Invalid Jupytext config");
}
if (!("formats" in jupytextConfig)) {
  throw new Error("Invalid Jupytext config (no formats field)");
}
const formats = jupytextConfig["formats"]
if (!(formats instanceof Array)) {
  throw new Error("Invalid Jupytext config (formats is not an array)");
}
// At this point TypeScript knows that `formats` is a JsonArray. You may still want to check that
// every value is a string.
for (const format of formats) {
  if (typeof format !== "string") {
    throw new Error("Format isn't a string");
  }
  // Now TypeScript knows that `format` is a string.
}
1reaction
mwoutscommented, Feb 8, 2019

Hi everyone, I’m happy to let you know that

Both require the latest rc (now 1.0.0-rc3):

pip install jupytext --pre --upgrade

Feedback is welcome.

Also, before I let the 1.0.0 version go I’ll try to bind the extensions with the python package, as nbdime or plotly seem to do.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Installation - Jupytext documentation - Read the Docs
Jupytext includes an extensions for Jupyter Notebook that adds a Jupytext section in the File menu. If the extension was not automatically installed,...
Read more >
A JupyterLab extension for Jupytext - GitHub
This extension adds a few Jupytext commands to the command palette. Use these to select the desired ipynb/text pairing for your notebook. Jupytext...
Read more >
Jupytext: The hack-free way to use Jupyter notebooks with git
Luckily the Python community has come to the rescue with a brilliant Jupyter notebook extension called Jupytext. Jupytext solves all of these issues...
Read more >
jupyterlab-jupytext - npm
This extension adds a few Jupytext commands to the command palette. Use these to select the desired ipynb/text pairing for your notebook.
Read more >
Jupytext for Notebooks - Visual Studio Marketplace
A Visual Studio Code extension that provides ability to open and execute script files as Jupyter Notebooks.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found