extension_migration_2_3.rst 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. .. _extension_migration_2_3:
  2. JupyterLab 2.x to 3.x Extension Migration Guide
  3. ===============================================
  4. This is a migration guide for updating extensions that support JupyterLab 2.x to work in JupyterLab 3.x.
  5. Upgrading library versions manually
  6. -----------------------------------
  7. To update the extensions so it is compatible with the 3.0 release, update the compatibility
  8. range of the ``@jupyterlab`` dependencies in the ``package.json``. The diff should be similar to:
  9. .. code:: diff
  10. index 6f1562f..3fcdf37 100644
  11. --- a/package.json
  12. +++ b/package.json
  13. "dependencies": {
  14. - "@jupyterlab/application": "^2.0.0",
  15. + "@jupyterlab/application": "^3.0.0",
  16. Upgrading library versions using the upgrade script
  17. ---------------------------------------------------
  18. JupyterLab 3.0 provides a script to upgrade an existing extension to use the new extension system and packaging.
  19. First, make sure to update to JupyterLab 3.0 and install ``jupyter-packaging`` and ``cookiecutter``. With ``pip``:
  20. .. code:: bash
  21. pip install jupyterlab -U
  22. pip install jupyter-packaging cookiecutter
  23. Or with ``conda``:
  24. .. code:: bash
  25. conda install -c conda-forge jupyterlab=3 jupyter-packaging cookiecutter
  26. Then at the root folder of the extension, run:
  27. .. code:: bash
  28. python -m jupyterlab.upgrade_extension .
  29. The upgrade script creates the necessary files for packaging the JupyterLab extension as a Python package, such as
  30. ``setup.py`` and ``pyproject.toml``.
  31. The upgrade script also updates the dependencies in ``package.json`` to the ``^3.0.0`` packages. Here is an example diff:
  32. .. code:: diff
  33. index 6f1562f..3fcdf37 100644
  34. --- a/package.json
  35. +++ b/package.json
  36. @@ -29,9 +29,13 @@
  37. "scripts": {
  38. - "build": "tsc",
  39. - "build:labextension": "npm run clean:labextension && mkdirp myextension/labextension && cd myextension/labextension && npm pack ../..",
  40. - "clean": "rimraf lib tsconfig.tsbuildinfo",
  41. + "build": "jlpm run build:lib && jlpm run build:labextension:dev",
  42. + "build:prod": "jlpm run build:lib && jlpm run build:labextension",
  43. + "build:lib": "tsc",
  44. + "build:labextension": "jupyter labextension build .",
  45. + "build:labextension:dev": "jupyter labextension build --development True .",
  46. + "clean": "rimraf lib tsconfig.tsbuildinfo myextension/labextension",
  47. + "clean:all": "jlpm run clean:lib && jlpm run clean:labextension",
  48. "clean:labextension": "rimraf myextension/labextension",
  49. "eslint": "eslint . --ext .ts,.tsx --fix",
  50. "eslint:check": "eslint . --ext .ts,.tsx",
  51. @@ -59,12 +63,12 @@
  52. ]
  53. },
  54. "dependencies": {
  55. - "@jupyterlab/application": "^2.0.0",
  56. - "@jupyterlab/apputils": "^2.0.0",
  57. - "@jupyterlab/observables": "^3.0.0",
  58. + "@jupyterlab/builder": "^3.0.0",
  59. + "@jupyterlab/application": "^3.0.0",
  60. + "@jupyterlab/apputils": "^3.0.0",
  61. + "@jupyterlab/observables": "^3.0.0",
  62. "@lumino/algorithm": "^1.2.3",
  63. "@lumino/commands": "^1.10.1",
  64. "@lumino/disposable": "^1.3.5",
  65. @@ -99,6 +103,13 @@
  66. - "typescript": "~3.8.3"
  67. + "typescript": "~4.0.1"
  68. },
  69. "jupyterlab": {
  70. - "extension": "lib/plugin"
  71. + "extension": "lib/plugin",
  72. + "outputDir": "myextension/labextension/"
  73. }
  74. }
  75. On the diff above, we see that additional development scripts are also added, as they are used by the new extension system workflow.
  76. The diff also shows the new ``@jupyterlab/builder`` as a ``devDependency``.
  77. ``@jupyterlab/builder`` is a package required to build the extension as a federated extension.
  78. It hides away internal dependencies such as ``webpack``, and produces the assets that can then be distributed as part of a Python package.
  79. Extension developers do not need to interact with ``@jupyterlab/builder`` directly, but instead can use the
  80. ``jupyter labextension build`` command. This command is run automatically as part of the ``build`` script
  81. (``jlpm run build``).
  82. For more details about the new file structure and packaging of the extension, check out the extension tutorial: :ref:`extension_tutorial`
  83. Publishing the extension to PyPI and conda-forge
  84. ------------------------------------------------
  85. Starting from JupyterLab 3.0, extensions can be distributed as a Python package.
  86. The extension tutorial provides explanations to package the extension so it can be
  87. published on PyPI and conda forge: :ref:`extension_tutorial_publish`.
  88. .. note::
  89. While publishing to PyPI is the new recommended way for distributing extensions to users,
  90. it is still useful to continue publishing extensions to ``npm`` as well,
  91. so other developers can extend them in their own extensions.