extension_migration.rst 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. .. _extension_migration:
  2. JupyterLab 1.x to 2.x Extension Migration Guide
  3. ------------------------------------------------
  4. This is a migration guide for updating extensions that support JupyterLab 1.x
  5. to work in JupyterLab 2.x. We will look at two examples of extensions that
  6. cover most of the APIs that extension authors might be using:
  7. - ``@jupyterlab/debugger`` migration pull request:
  8. https://github.com/jupyterlab/debugger/pull/337/files
  9. - ``@jupyterlab/shortcutui`` migration pull request:
  10. https://github.com/jupyterlab/jupyterlab-shortcutui/pull/53/files
  11. Upgrading library versions
  12. ~~~~~~~~~~~~~~~~~~~~~~~~~~
  13. The ``@phosphor/*`` libraries that JupyterLab 1.x uses have been renamed to
  14. ``@lumino/*``. Updating your ``package.json`` is straightforward. The easiest
  15. way to do this is to look in the
  16. `JupyterLab core packages code base <https://github.com/jupyterlab/jupyterlab/tree/master/packages>`__
  17. and to simply adopt the versions of the relevant libraries that are used
  18. there.
  19. .. figure:: extension_migration_dependencies_debugger.png
  20. :align: center
  21. :class: jp-screenshot
  22. :alt: Updating the debugger extension's libraries in package.json
  23. Updating the debugger extension's libraries in ``package.json``
  24. .. figure:: extension_migration_dependencies_shortcuts.png
  25. :align: center
  26. :class: jp-screenshot
  27. :alt: Updating the shortcuts UI extension's libraries in package.json
  28. Updating the shortcuts UI extension's libraries in ``package.json``
  29. .. tip::
  30. In these examples, note that we are using the ``2.0.0-beta.x`` version of
  31. many libraries. This was to test the extensions against the JupyterLab 2.0
  32. beta release before the final version. For the final release, your
  33. ``package.json`` should depend on version ``^2.0.0`` of these packages.
  34. Migrating from ``@phosphor`` to ``@lumino``
  35. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  36. The foundational packages used by JupyterLab are now all prefixed with the NPM
  37. namespace ``@lumino`` instead of ``@phosphor``. The APIs for these packages
  38. have not changed. The ``@phosphor`` namespaced imports need to be updated to
  39. the new ``@lumino`` namespaced packages:
  40. .. list-table:: Update from ``@phosphor/...`` to ``@lumino/...``
  41. * - ``@phosphor/application``
  42. - ``@lumino/application``
  43. * - ``@phosphor/collections``
  44. - ``@lumino/collections``
  45. * - ``@phosphor/commands``
  46. - ``@lumino/commands``
  47. * - ``@phosphor/coreutils``
  48. - ``@lumino/coreutils``
  49. * - ``@phosphor/datagrid``
  50. - ``@lumino/datagrid``
  51. * - ``@phosphor/datastore``
  52. - ``@lumino/datastore``
  53. * - ``@phosphor/default-theme``
  54. - ``@lumino/default-theme``
  55. * - ``@phosphor/disposable``
  56. - ``@lumino/disposable``
  57. * - ``@phosphor/domutils``
  58. - ``@lumino/domutils``
  59. * - ``@phosphor/dragdrop``
  60. - ``@lumino/dragdrop``
  61. * - ``@phosphor/keyboard``
  62. - ``@lumino/keyboard``
  63. * - ``@phosphor/messaging``
  64. - ``@lumino/messaging``
  65. * - ``@phosphor/properties``
  66. - ``@lumino/properties``
  67. * - ``@phosphor/signaling``
  68. - ``@lumino/signaling``
  69. * - ``@phosphor/virtualdom``
  70. - ``@lumino/virtualdom``
  71. * - ``@phosphor/widgets``
  72. - ``@lumino/widgets``
  73. .. warning::
  74. ``p-`` prefixed CSS classes, ``data-p-`` attributes and ``p-`` DOM events
  75. are deprecated. They will continue to work until the next major release of
  76. Lumino.
  77. - ``.p-`` CSS classes such as ``.p-Widget`` should be updated to ``.lm-``,
  78. e.g. ``.lm-Widget``
  79. - ``data-p-`` attributes such as ``data-p-dragscroll`` should be updated to
  80. ``data-lm-``, e.g. ``data-lm-dragscroll``
  81. - ``p-`` DOM events such as ``p-dragenter`` should be updated to ``lm-``,
  82. e.g. ``lm-dragenter``
  83. Updating former ``@jupyterlab/coreutils`` imports
  84. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  85. JupyterLab 2.0 introduces several new packages with classes and tokens that
  86. have been moved out of ``@jupyterlab/coreutils`` into their own packages. These
  87. exports have been moved.
  88. .. tip::
  89. It might be helpful to delete ``node_modules`` and ``yarn.lock`` when
  90. updating these libraries.
  91. ============================ =================================
  92. Export Package
  93. ============================ =================================
  94. ``DataConnector`` ``@jupyterlab/statedb``
  95. ``Debouncer`` ``@lumino/polling``
  96. ``DefaultSchemaValidator`` ``@jupyterlab/settingregistry``
  97. ``IDataConnector`` ``@jupyterlab/statedb``
  98. ``IObjectPool`` ``@jupyterlab/statedb``
  99. ``IPoll`` ``@lumino/polling``
  100. ``IRateLimiter`` ``@lumino/polling``
  101. ``IRestorable`` ``@jupyterlab/statedb``
  102. ``IRestorer`` ``@jupyterlab/statedb``
  103. ``ISchemaValidator`` ``@jupyterlab/settingregistry``
  104. ``ISettingRegistry`` ``@jupyterlab/settingregistry``
  105. ``IStateDB`` ``@jupyterlab/statedb``
  106. ``nbformat`` ``@jupyterlab/nbformat``
  107. ``Poll`` ``@lumino/polling``
  108. ``RateLimiter`` ``@lumino/polling``
  109. ``RestorablePool`` ``@jupyterlab/statedb``
  110. ``SettingRegistry`` ``@jupyterlab/settingregistry``
  111. ``Settings`` ``@jupyterlab/settingregistry``
  112. ``StateDB`` ``@jupyterlab/statedb``
  113. ``Throttler`` ``@lumino/polling``
  114. ============================ =================================
  115. Using ``Session`` and ``SessionContext`` to manage kernel sessions
  116. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  117. .. note::
  118. For full API documentation and examples of how to use
  119. ``@jupyterlab/services``,
  120. `consult the repository <https://github.com/jupyterlab/jupyterlab/tree/master/packages/services#readme>`__.
  121. ``ConsolePanel`` and ``NotebookPanel`` now expose a
  122. ``sessionContext: ISessionContext`` attribute that allows for a uniform way to
  123. interact with kernel sessions.
  124. Any widget that matches the ``interface IDocumentWidget`` has a
  125. ``context: DocumentRegistry.IContext`` attribute with a
  126. ``sessionContext: ISessionContext`` attribute.
  127. For example, consider how the ``@jupyterlab/debugger`` extension's
  128. ``DebuggerService`` updated its ``isAvailable()`` method.
  129. .. figure:: extension_migration_session.png
  130. :align: center
  131. :class: jp-screenshot
  132. :alt: Updating the isAvailable method of the debugger service
  133. From the `PR migrating the debugger extension to JupyterLab 2.0 <https://github.com/jupyterlab/debugger/pull/337/files#diff-22ccf3ebb0cb6b300ee90a38b88edff8>`__
  134. .. note::
  135. ``await kernel.ready`` is no longer necessary before the kernel connection
  136. ``kernel`` can be used. Kernel messages will be buffered as needed while a
  137. kernel connection is coming online, so you should be able to use a kernel
  138. connection immediately. If you want to retrieve the kernel info (or if for
  139. some other reason you want to wait until at least one message has returned
  140. from a new kernel connection), you can do ``await kernel.info``.
  141. Using the new icon system and ``LabIcon``
  142. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  143. .. note::
  144. For full API documentation and examples of how to use
  145. the new icon support based on ``LabIcon`` from ``@jupyterlab/ui-components``,
  146. `consult the repository <https://github.com/jupyterlab/jupyterlab/tree/master/packages/ui-components#readme>`__.