diff --git a/packages/labextension/CHANGELOG.md b/packages/labextension/CHANGELOG.md new file mode 100644 index 000000000..34ef4d466 --- /dev/null +++ b/packages/labextension/CHANGELOG.md @@ -0,0 +1,16 @@ +# 1.0.1 (2019-07-18) + +- A click on a selected format toggle the pairing (#289) +- Use `JupyterFrontEnd` and `JupyterFrontEndPlugin` from `@jupyterlab/application` rather than `JupyterLab` and `JupyterLabPlugin` for compatibility with JupyterLab 1.0. + +# 1.0.0 (2019-07-06) + +- First extension compatible with JupyterLab 1.0 + +# 0.19.0 (2019-07-06) + +- Last extension compatible with JupyterLab 0.35 + +# 0.1.0 (2018-10-02) + +- Initial release of the extension diff --git a/packages/labextension/README.md b/packages/labextension/README.md index ffe072be2..7c7b0916e 100644 --- a/packages/labextension/README.md +++ b/packages/labextension/README.md @@ -20,39 +20,51 @@ jupyter labextension install jupyterlab-jupytext@0.19 # How to develop this extension -We developed the extension following the [xkcd extension tutorial](https://jupyterlab.readthedocs.io/en/stable/developer/xkcd_extension_tutorial.html). Follow the instructions there to create a conda environment in which you will be able to develop the extension. In that environment, install JupyterLab's plugin manager, and the extension with +We assume that you have activated the conda environment described in [CONTRIBUTING.md](https://github.com/mwouts/jupytext/blob/master/CONTRIBUTING.md). In addition to that environment, you will need `npm`. Install it with + +```bash +conda install nodejs +``` + +In that environment, install JupyterLab's plugin manager, and the extension with ```bash +# Go to the extension folder +cd packages/labextension + +# Cleanup +rm lib node_modules yarn.lock + +# Install JupyterLab's plugin manager jlpm install + +# Package the extension +npm pack +``` + +Then you can rebuild the Jupytext python package (with `python setup.py sdist bdist_wheel`) and reinstall it (`pip install dist\jupytext-XXX.tar.gz`). + +Alternatively, if you prefer to develop iteratively, you could install a development version of the extension with + +```bash jupyter labextension install . --no-build ``` -Then, in another shell on the same environment, start JupyterLab: +Then start JupyterLab in watch mode in another shell on the same environment: ```bash jupyter lab --watch ``` -Finally, make changes to the extension and rebuild it (in the first shell) with: +And finally, make changes to the extension and rebuild it (in the first shell) with: ```bash jlpm run build ``` -Refresh the JupyterLab interface and see your changes in action. - # How to publish a new version of the extension -Bump the version in `package.json`. - -Build the new version of `jupyterlab-jupytext-xxx.tgz` with - -```bash -npm pack -``` +Bump the version in `package.json`, rebuild the extension with `npm pack`. Include the new extension in Git and `setup.py`, and delete the previous version. -and remove any previous version. That package will be included in the Jupytext Python package. - -If you wish, you may also update the package on npm with +If you wish, you can also publish the package on [npm](https://www.npmjs.com) with ```bash npm publish --access=public ``` - diff --git a/packages/labextension/jupyterlab-jupytext-1.0.0.tgz b/packages/labextension/jupyterlab-jupytext-1.0.0.tgz deleted file mode 100644 index 7ed1b3bb2..000000000 Binary files a/packages/labextension/jupyterlab-jupytext-1.0.0.tgz and /dev/null differ diff --git a/packages/labextension/jupyterlab-jupytext-1.0.1.tgz b/packages/labextension/jupyterlab-jupytext-1.0.1.tgz new file mode 100644 index 000000000..819c138b3 Binary files /dev/null and b/packages/labextension/jupyterlab-jupytext-1.0.1.tgz differ diff --git a/packages/labextension/package.json b/packages/labextension/package.json index 99202404a..9ef0c73c9 100644 --- a/packages/labextension/package.json +++ b/packages/labextension/package.json @@ -1,6 +1,6 @@ { "name": "jupyterlab-jupytext", - "version": "1.0.0", + "version": "1.0.1", "description": "A JupyterLab extension for Jupytext", "keywords": [ "jupyter", diff --git a/packages/labextension/src/index.ts b/packages/labextension/src/index.ts index bb5521338..8c344db9b 100644 --- a/packages/labextension/src/index.ts +++ b/packages/labextension/src/index.ts @@ -1,4 +1,4 @@ -import { JupyterLab, JupyterLabPlugin } from "@jupyterlab/application"; +import { JupyterFrontEnd, JupyterFrontEndPlugin } from "@jupyterlab/application"; import { ICommandPalette } from "@jupyterlab/apputils"; @@ -43,15 +43,41 @@ const JUPYTEXT_FORMATS = [ } ]; +function get_selected_format(notebook_tracker: INotebookTracker): string { + if (!notebook_tracker.currentWidget) return null; + + if ( + !notebook_tracker.currentWidget.context.model.metadata.has( + "jupytext" + ) + ) + return "none"; + + const jupytext: JupytextSection = (notebook_tracker.currentWidget.context.model.metadata.get( + "jupytext" + ) as unknown) as JupytextSection; + if (!jupytext.formats) return "none"; + + const lang = notebook_tracker.currentWidget.context.model.metadata.get( + "language_info" + ) as nbformat.ILanguageInfoMetadata; + return lang + ? jupytext.formats.replace( + "," + lang.file_extension.substring(1) + ":", + ",auto:" + ) + : jupytext.formats; +}; + /** * Initialization data for the jupyterlab-jupytext extension. */ -const extension: JupyterLabPlugin = { +const extension: JupyterFrontEndPlugin = { id: "jupyterlab-jupytext", autoStart: true, requires: [ICommandPalette, INotebookTracker], activate: ( - app: JupyterLab, + app: JupyterFrontEnd, palette: ICommandPalette, notebook_tracker: INotebookTracker ) => { @@ -65,33 +91,13 @@ const extension: JupyterLabPlugin = { label: args["label"], isToggled: () => { if (!notebook_tracker.currentWidget) return false; - - if ( - !notebook_tracker.currentWidget.context.model.metadata.has( - "jupytext" - ) - ) - return formats == "none"; - - const jupytext: JupytextSection = (notebook_tracker.currentWidget.context.model.metadata.get( - "jupytext" - ) as unknown) as JupytextSection; - if (!jupytext.formats) return formats == "none"; - - const lang = notebook_tracker.currentWidget.context.model.metadata.get( - "language_info" - ) as nbformat.ILanguageInfoMetadata; - const jupytext_formats = lang - ? jupytext.formats.replace( - "," + lang.file_extension.substring(1) + ":", - ",auto:" - ) - : jupytext.formats; + const jupytext_formats = get_selected_format(notebook_tracker) if (formats == "custom") return ( jupytext_formats && [ + "none", "ipynb,auto:light", "ipynb,auto:percent", "ipynb,auto:hydrogen", @@ -117,6 +123,11 @@ const extension: JupyterLabPlugin = { return formats != "ipynb,md" && formats != "ipynb,Rmd"; }, execute: () => { + const jupytext: JupytextSection = (notebook_tracker.currentWidget.context.model.metadata.get( + "jupytext" + ) as unknown) as JupytextSection; + const jupytext_formats = get_selected_format(notebook_tracker); + const target_format = jupytext_formats === formats ? "none": formats; console.log("Jupytext: executing command=" + command); if (formats == "custom") { alert( @@ -125,11 +136,7 @@ const extension: JupyterLabPlugin = { return; } - const jupytext: JupytextSection = (notebook_tracker.currentWidget.context.model.metadata.get( - "jupytext" - ) as unknown) as JupytextSection; - - if (formats == "none") { + if (target_format == "none") { if ( !notebook_tracker.currentWidget.context.model.metadata.has( "jupytext" @@ -148,12 +155,12 @@ const extension: JupyterLabPlugin = { return; } - // set desired format - if (jupytext) jupytext.formats = formats; + // set the desired format + if (jupytext) jupytext.formats = target_format; else notebook_tracker.currentWidget.context.model.metadata.set( "jupytext", - { formats } + { target_format } ); } }); diff --git a/setup.py b/setup.py index d6f853f90..e2cc05426 100644 --- a/setup.py +++ b/setup.py @@ -32,7 +32,7 @@ 'jupytext/nbextension/jupytext_menu.png', 'jupytext/nbextension/jupytext_menu_zoom.png', 'jupytext/nbextension/jupytext.yml']), - ('share/jupyter/lab/extensions', ['packages/labextension/jupyterlab-jupytext-1.0.0.tgz'])], + ('share/jupyter/lab/extensions', ['packages/labextension/jupyterlab-jupytext-1.0.1.tgz'])], entry_points={'console_scripts': ['jupytext = jupytext.cli:jupytext_cli']}, tests_require=['pytest'], install_requires=['nbformat>=4.0.0', 'pyyaml', 'mock;python_version<"3"'],