contributing.rst 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997
  1. Contributing to JupyterLab
  2. ==========================
  3. If you're reading this section, you're probably interested in
  4. contributing to JupyterLab. Welcome and thanks for your interest in
  5. contributing!
  6. Please take a look at the Contributor documentation, familiarize
  7. yourself with using JupyterLab, and introduce yourself to the community
  8. (on the mailing list or discourse) and share what area of the project
  9. you are interested in working on. Please also see the Jupyter `Community
  10. Guides <https://jupyter.readthedocs.io/en/latest/community/content-community.html>`__.
  11. We have labeled some issues as `good first
  12. issue <https://github.com/jupyterlab/jupyterlab/issues?q=is%3Aopen+is%3Aissue+label%3A%22good+first+issue%22>`__
  13. or `help
  14. wanted <https://github.com/jupyterlab/jupyterlab/issues?q=is%3Aissue+is%3Aopen+label%3A%22help+wanted%22>`__
  15. that we believe are good examples of small, self-contained changes. We
  16. encourage those that are new to the code base to implement and/or ask
  17. questions about these issues.
  18. If you believe you’ve found a security vulnerability in JupyterLab or
  19. any Jupyter project, please report it to security@ipython.org. If you
  20. prefer to encrypt your security reports, you can use `this PGP public
  21. key <https://raw.githubusercontent.com/jupyter/notebook/master/docs/source/ipython_security.asc>`__.
  22. .. contents:: Table of contents
  23. :local:
  24. :depth: 1
  25. General Guidelines for Contributing
  26. ------------------------------------
  27. For general documentation about contributing to Jupyter projects, see
  28. the `Project Jupyter Contributor
  29. Documentation <https://jupyter.readthedocs.io/en/latest/contributing/content-contributor.html>`__
  30. and `Code of
  31. Conduct <https://github.com/jupyter/governance/blob/master/conduct/code_of_conduct.md>`__.
  32. All source code is written in
  33. `TypeScript <http://www.typescriptlang.org/Handbook>`__. See the `Style
  34. Guide <https://github.com/jupyterlab/jupyterlab/wiki/TypeScript-Style-Guide>`__.
  35. All source code is formatted using `prettier <https://prettier.io>`__.
  36. When code is modified and committed, all staged files will be
  37. automatically formatted using pre-commit git hooks (with help from the
  38. `lint-staged <https://github.com/okonet/lint-staged>`__ and
  39. `husky <https://github.com/typicode/husky>`__ libraries). The benefit of
  40. using a code formatter like prettier is that it removes the topic of
  41. code style from the conversation when reviewing pull requests, thereby
  42. speeding up the review process.
  43. You may also use the prettier npm script (e.g. ``npm run prettier`` or
  44. ``yarn prettier`` or ``jlpm prettier``) to format the entire code base.
  45. We recommend installing a prettier extension for your code editor and
  46. configuring it to format your code with a keyboard shortcut or
  47. automatically on save.
  48. Submitting a Pull Request Contribution
  49. --------------------------------------
  50. Generally, an issue should be opened describing a piece of proposed work
  51. and the issues it solves before a pull request is opened.
  52. Issue Management
  53. ^^^^^^^^^^^^^^^^
  54. Opening an issue lets community members participate in the design
  55. discussion, makes others aware of work being done, and sets the stage
  56. for a fruitful community interaction. A pull request should reference
  57. the issue it is addressing. Once the pull request is merged, the issue
  58. related to it will also be closed. If there is additional discussion
  59. around implemementation the issue may be re-opened. Once 30 days have
  60. passed with no additional discussion, the `lock
  61. bot <https://github.com/apps/lock>`__ will lock the issue. If additional
  62. discussion is desired, or if the pull request doesn't fully address the
  63. locked issue, please open a new issue referencing the locked issue.
  64. Tag Issues with Labels
  65. ^^^^^^^^^^^^^^^^^^^^^^
  66. Users without the commit rights to the JupyterLab repository can tag
  67. issues with labels using the ``@meeseeksdev`` bot. For example: To apply
  68. the label ``foo`` and ``bar baz`` to an issue, comment
  69. ``@meeseeksdev tag foo "bar baz"`` on the issue.
  70. Contributing from within the browser
  71. ------------------------------------
  72. Using the https://github.com web interface - documented
  73. `here <https://docs.github.com/en/free-pro-team@latest/github>`__ - you
  74. can create and propose a change purely within your browser.
  75. Using `Binder <https://mybinder.org>`__, you can test the current master branch and your
  76. changes within the browser as well. We recommend you have at least 8 GB of RAM for this.
  77. To build and launch an instance of the latest JupyterLab master, open
  78. `this link <https://mybinder.org/v2/gh/jupyterlab/jupyterlab/master?urlpath=lab-dev/>`__
  79. in a new tab. The build takes about 7 minutes to complete.
  80. To test your own branch hosted on GitHub, enter it on https://mybinder.org.
  81. If everything goes right, filling out the form takes about 2 minutes, and the build should take
  82. about 7 minutes again.
  83. Setting up a local development environment
  84. ------------------------------------------
  85. This section explains how to set up a local development environment. We assume you use GNU/Linux,
  86. Mac OS X, or Windows Subsystem for Linux.
  87. Installing Node.js and jlpm
  88. ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  89. Building JupyterLab from its GitHub source code requires Node.js. The
  90. development version requires Node.js version 12+, as defined in the
  91. ``engines`` specification in
  92. `dev_mode/package.json <https://github.com/jupyterlab/jupyterlab/blob/master/dev_mode/package.json>`__.
  93. If you use ``conda``, you can get it with:
  94. .. code:: bash
  95. conda install -c conda-forge 'nodejs'
  96. If you use `Homebrew <http://brew.sh>`__ on Mac OS X:
  97. .. code:: bash
  98. brew install node
  99. You can also use the installer from the `Node.js <https://nodejs.org>`__
  100. website.
  101. To check which version of Node.js is installed:
  102. .. code:: bash
  103. node -v
  104. Installing JupyterLab
  105. ---------------------
  106. If you use ``conda``, you may also want to install ``nb_conda_kernels`` to have a kernel
  107. option for different `conda
  108. environments <https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html>`__
  109. .. code:: bash
  110. conda install -c conda-forge nb_conda_kernels
  111. Fork the JupyterLab
  112. `repository <https://github.com/jupyterlab/jupyterlab>`__.
  113. Then use the following steps:
  114. .. code:: bash
  115. git clone https://github.com/<your-github-username>/jupyterlab.git
  116. cd jupyterlab
  117. pip install -e .
  118. jlpm install
  119. jlpm run build # Build the dev mode assets (optional)
  120. jlpm run build:core # Build the core mode assets (optional)
  121. jupyter lab build # Build the app dir assets (optional)
  122. Notes:
  123. - A few of the scripts will run "python". If your target python is
  124. called something else (such as "python3") then parts of the build
  125. will fail. You may wish to build in a conda environment, or make an
  126. alias.
  127. - Some of the packages used in the development environment require
  128. Python 3.0 or higher. If you encounter an ImportError during the
  129. installation, make sure Python 3.0+ is installed. Also, try using the
  130. Python 3.0+ version of ``pip`` or ``pip3 install -e .`` command to
  131. install JupyterLab from the forked repository.
  132. - The ``jlpm`` command is a JupyterLab-provided, locked version of the
  133. `yarn <https://yarnpkg.com/en>`__ package manager. If you have
  134. ``yarn`` installed already, you can use the ``yarn`` command when
  135. developing, and it will use the local version of ``yarn`` in
  136. ``jupyterlab/yarn.js`` when run in the repository or a built
  137. application directory.
  138. - If you decide to use the ``jlpm`` command and encounter the
  139. ``jlpm: command not found`` error, try adding the user-level bin
  140. directory to your ``PATH`` environment variable. You already
  141. installed ``jlpm`` along with JupyterLab in the previous command, but
  142. ``jlpm`` might not be accessible due to ``PATH`` environment variable
  143. related issues. If you are using a Unix derivative (FreeBSD, GNU /
  144. Linux, OS X), you can achieve this by using
  145. ``export PATH="$HOME/.local/bin:$PATH"`` command.
  146. - At times, it may be necessary to clean your local repo with the
  147. command ``npm run clean:slate``. This will clean the repository, and
  148. re-install and rebuild.
  149. - If ``pip`` gives a ``VersionConflict`` error, it usually means that
  150. the installed version of ``jupyterlab_server`` is out of date. Run
  151. ``pip install --upgrade jupyterlab_server`` to get the latest
  152. version.
  153. - To install JupyterLab in isolation for a single conda/virtual
  154. environment, you can add the ``--sys-prefix`` flag to the extension
  155. activation above; this will tie the installation to the
  156. ``sys.prefix`` location of your environment, without writing anything
  157. in your user-wide settings area (which are visible to all your envs):
  158. - You can run ``jlpm run build:dev:prod`` to build more accurate
  159. sourcemaps that show the original Typescript code when debugging.
  160. However, it takes a bit longer to build the sources, so is used only
  161. to build for production by default.
  162. If you are using a version of Jupyter Notebook earlier than 5.3, then
  163. you must also run the following command to enable the JupyterLab server
  164. extension:
  165. .. code:: bash
  166. jupyter serverextension enable --py --sys-prefix jupyterlab
  167. For installation instructions to write documentation, please see
  168. `Writing Documentation <#writing-documentation>`__
  169. Run JupyterLab
  170. ^^^^^^^^^^^^^^
  171. Start JupyterLab in development mode:
  172. .. code:: bash
  173. jupyter lab --dev-mode
  174. Development mode ensures that you are running the JavaScript assets that
  175. are built in the dev-installed Python package. Note that when running in
  176. dev mode, extensions will not be activated by default.
  177. When running in dev mode, a red stripe will appear at the top of the
  178. page; this is to indicate running an unreleased version.
  179. If you want to change the TypeScript code and rebuild on the fly
  180. (needs page refresh after each rebuild):
  181. .. code:: bash
  182. jupyter lab --dev-mode --watch
  183. Build and Run the Tests
  184. ^^^^^^^^^^^^^^^^^^^^^^^
  185. .. code:: bash
  186. jlpm run build:testutils
  187. jlpm test
  188. You can run tests for an individual package by changing to the
  189. appropriate package folder:
  190. .. code:: bash
  191. cd packages/notebook
  192. jlpm run build:test
  193. jlpm test
  194. We use ``jest`` for all tests, so standard ``jest`` workflows apply.
  195. Tests can be debugged in either VSCode or Chrome. It can help to add an
  196. ``it.only`` to a specific test when debugging. All of the ``test*``
  197. scripts in each package accept ``jest`` `cli
  198. options <https://jestjs.io/docs/en/cli.html>`__.
  199. VSCode Debugging
  200. """"""""""""""""
  201. To debug in VSCode, open a package folder in VSCode. We provide a launch
  202. configuration in each package folder. In a terminal, run
  203. ``jlpm test:debug:watch``. In VSCode, select "Attach to Jest" from the
  204. "Run" sidebar to begin debugging. See `VSCode docs on
  205. debugging <https://code.visualstudio.com/docs/editor/debugging>`__ for
  206. more details.
  207. Chrome Debugging
  208. """"""""""""""""
  209. To debug in Chrome, run ``jlpm test:debug:watch`` in the terminal. Open
  210. Chrome and go to ``chrome://inspect/``. Select the remote device and
  211. begin debugging.
  212. Testing Utilities
  213. """""""""""""""""
  214. There are some helper functions in ``testutils`` (which is a public npm
  215. package called ``@jupyterlab/testutils``) that are used by many of the
  216. tests.
  217. For tests that rely on ``@jupyterlab/services`` (starting kernels,
  218. interacting with files, etc.), there are two options. If a simple
  219. interaction is needed, the ``Mock`` namespace exposed by ``testutils``
  220. has a number of mock implmentations (see ``testutils/src/mock.ts``). If
  221. a full server interaction is required, use the ``JupyterServer`` class.
  222. We have a helper function called ``testEmission`` to help with writing
  223. tests that use ``Lumino`` signals, as well as a ``framePromise``
  224. function to get a ``Promise`` for a ``requestAnimationFrame``. We
  225. sometimes have to set a sentinel value inside a ``Promise`` and then
  226. check that the sentinel was set if we need a promise to run without
  227. blocking.
  228. Performance Testing
  229. -------------------
  230. If you are making a change that might affect how long it takes to load
  231. JupyterLab in the browser, we recommend doing some performance testing
  232. using `Lighthouse <https://github.com/GoogleChrome/lighthouse>`__. It
  233. let's you easily compute a number of metrics, like page load time, for
  234. the site.
  235. To use it, first build JupyterLab in dev mode:
  236. .. code:: bash
  237. jlpm run build:dev
  238. Then, start JupyterLab using the dev build:
  239. .. code:: bash
  240. jupyter lab --dev --NotebookApp.token='' --no-browser
  241. Now run Lighthouse against this local server and show the results:
  242. .. code:: bash
  243. jlpm run lighthouse --view
  244. .. image:: /images/lighthouse.png
  245. Using throttling
  246. ^^^^^^^^^^^^^^^^
  247. Lighthouse recommends using the system level
  248. `comcast <https://github.com/tylertreat/comcast>`__ tool to throttle
  249. your network connection and emulate different scenarios. To use it,
  250. first install that tool using ``go``:
  251. .. code:: bash
  252. go get github.com/tylertreat/comcast
  253. Then, before you run Lighthouse, enable the throttling (this requires
  254. sudo):
  255. .. code:: bash
  256. run lighthouse:throttling:start
  257. This enables the "WIFI (good)" preset of comcast, which should emulate
  258. loading JupyterLab over a local network.
  259. Then run the lighthouse tests:
  260. .. code:: bash
  261. jlpm run lighthouse [...]
  262. Then disable the throttling after you are done:
  263. .. code:: bash
  264. jlpm run lighthouse:throttling:stop
  265. Comparing results
  266. ^^^^^^^^^^^^^^^^^
  267. Performance results are usually only useful in comparison to other
  268. results. For that reason, we have included a comparison script that can
  269. take two lighthouse results and show the changes between them.
  270. Let's say we want to compare the results of the production build of
  271. JupyterLab with the normal build. The production build minifies all the
  272. JavaScript, so should load a bit faster.
  273. First, we build JupyterLab normally, start it up, profile it and save
  274. the results:
  275. .. code:: bash
  276. jlpm build:dev
  277. jupyter lab --dev --NotebookApp.token='' --no-browser
  278. # in new window
  279. jlpm run lighthouse --output json --output-path normal.json
  280. Then rebuild with the production build and retest:
  281. .. code:: bash
  282. jlpm run build:dev:prod
  283. jupyter lab --dev --NotebookApp.token='' --no-browser
  284. # in new window
  285. jlpm run lighthouse --output json --output-path prod.json
  286. Now we can use compare the two outputs:
  287. .. code:: bash
  288. jlpm run lighthouse:compare normal.json prod.json
  289. This gives us a report of the relative differences between the audits in
  290. the two reports:
  291. .. admonition:: Resulting Output
  292. ``normal.json`` -> ``prod.json``
  293. | **First Contentful Paint**
  294. | - -62% Δ
  295. | - 1.9 s -> 0.7 s
  296. | - First Contentful Paint marks the time at which the first text or
  297. image is painted. `Learn
  298. more <https://developers.google.com/web/tools/lighthouse/audits/first-contentful-paint>`__.
  299. | **First Meaningful Paint**
  300. | - -50% Δ
  301. | - 2.5 s -> 1.3 s
  302. | - First Meaningful Paint measures when the primary content of a
  303. page is visible. `Learn
  304. more <https://developers.google.com/web/tools/lighthouse/audits/first-meaningful-paint>`__.
  305. | **Speed Index**
  306. | - -48% Δ
  307. | - 2.6 s -> 1.3 s
  308. | - Speed Index shows how quickly the contents of a page are visibly
  309. populated. `Learn
  310. more <https://developers.google.com/web/tools/lighthouse/audits/speed-index>`__.
  311. | **Estimated Input Latency**
  312. | - 0% Δ
  313. | - 20 ms -> 20 ms
  314. | - Estimated Input Latency is an estimate of how long your app takes
  315. to respond to user input, in milliseconds, during the busiest 5s
  316. window of page load. If your latency is higher than 50 ms, users
  317. may perceive your app as laggy. `Learn
  318. more <https://developers.google.com/web/tools/lighthouse/audits/estimated-input-latency>`__.
  319. | **Max Potential First Input Delay**
  320. | - 9% Δ
  321. | - 200 ms -> 210 ms
  322. | - The maximum potential First Input Delay that your users could
  323. experience is the duration, in milliseconds, of the longest task.
  324. `Learn
  325. more <https://developers.google.com/web/updates/2018/05/first-input-delay>`__.
  326. | **First CPU Idle**
  327. | - -50% Δ
  328. | - 2.5 s -> 1.3 s
  329. | - First CPU Idle marks the first time at which the page's main
  330. thread is quiet enough to handle input. `Learn
  331. more <https://developers.google.com/web/tools/lighthouse/audits/first-interactive>`__.
  332. | **Time to Interactive**
  333. | - -52% Δ
  334. | - 2.5 s -> 1.2 s
  335. | - Time to interactive is the amount of time it takes for the page
  336. to become fully interactive. `Learn
  337. more <https://developers.google.com/web/tools/lighthouse/audits/consistently-interactive>`__.
  338. | **Avoid multiple page redirects**
  339. | - -2% Δ
  340. | - Potential savings of 10 ms -> Potential savings of 10 ms
  341. | - Redirects introduce additional delays before the page can be
  342. loaded. `Learn
  343. more <https://developers.google.com/web/tools/lighthouse/audits/redirects>`__.
  344. | **Minimize main-thread work**
  345. | - -54% Δ
  346. | - 2.1 s -> 1.0 s
  347. | - Consider reducing the time spent parsing, compiling and executing
  348. JS. You may find delivering smaller JS payloads helps with this.
  349. | **JavaScript execution time**
  350. | - -49% Δ
  351. | - 1.1 s -> 0.6 s
  352. | - Consider reducing the time spent parsing, compiling, and
  353. executing JS. You may find delivering smaller JS payloads helps
  354. with this. `Learn
  355. more <https://developers.google.com/web/tools/lighthouse/audits/bootup>`__.
  356. | **Preload key requests**
  357. | - -100% Δ
  358. | - Potential savings of 240 ms ->
  359. | - Consider using <link rel=preload> to prioritize fetching
  360. resources that are currently requested later in page load. `Learn
  361. more <https://developers.google.com/web/tools/lighthouse/audits/preload>`__.
  362. | **Uses efficient cache policy on static assets**
  363. | - 0% Δ
  364. | - 1 resource found -> 1 resource found
  365. | - A long cache lifetime can speed up repeat visits to your page.
  366. `Learn
  367. more <https://developers.google.com/web/tools/lighthouse/audits/cache-policy>`__.
  368. | **Avoid enormous network payloads**
  369. | - -86% Δ
  370. | - Total size was 30,131 KB -> Total size was 4,294 KB
  371. | - Large network payloads cost users real money and are highly
  372. correlated with long load times. `Learn
  373. more <https://developers.google.com/web/tools/lighthouse/audits/network-payloads>`__.
  374. | **Minify JavaScript**
  375. | - -100% Δ
  376. | - Potential savings of 23,041 KB ->
  377. | - Minifying JavaScript files can reduce payload sizes and script
  378. parse time. `Learn
  379. more <https://developers.google.com/speed/docs/insights/MinifyResources>`__.
  380. | **Enable text compression**
  381. | - -86% Δ
  382. | - Potential savings of 23,088 KB -> Potential savings of 3,112 KB
  383. | - Text-based resources should be served with compression (gzip,
  384. deflate or brotli) to minimize total network bytes. `Learn
  385. more <https://developers.google.com/web/tools/lighthouse/audits/text-compression>`__.
  386. | **Avoid an excessive DOM size**
  387. | - 0% Δ
  388. | - 1,268 elements -> 1,268 elements
  389. | - Browser engineers recommend pages contain fewer than ~1,500 DOM
  390. elements. The sweet spot is a tree depth < 32 elements and fewer
  391. than 60 children/parent element. A large DOM can increase memory
  392. usage, cause longer `style
  393. calculations <https://developers.google.com/web/fundamentals/performance/rendering/reduce-the-scope-and-complexity-of-style-calculations>`__,
  394. and produce costly `layout
  395. reflows <https://developers.google.com/speed/articles/reflow>`__.
  396. `Learn
  397. more <https://developers.google.com/web/tools/lighthouse/audits/dom-size>`__.
  398. Contributing to the debugger front-end
  399. --------------------------------------
  400. To make changes to the debugger extension, a kernel with support for debugging is required.
  401. Check out the user documentation to learn how to install such kernel: :ref:`debugger`.
  402. Then refresh the page and the debugger sidebar should appear in the right area.
  403. The Debugger Adapter Protocol
  404. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  405. The following diagram illustrates the types of messages sent between the JupyterLab extension and the kernel.
  406. .. image:: ./debugger_protocol_diagram.png
  407. Inspecting Debug Messages in VS Code
  408. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  409. Inspecting the debug messages in VS Code can be useful to understand when debug requests are made (for example triggered by a UI action), and to compare the behavior of the JupyterLab debugger with the Python debugger in VS Code.
  410. The first step is to create a test file and a debug configuration (``launch.json``):
  411. .. image:: ./debugger_launch_configuration.png
  412. .. code:: json
  413. {
  414. "version": "0.2.0",
  415. "configurations": [
  416. {
  417. "name": "Python: Current File",
  418. "type": "python",
  419. "request": "launch",
  420. "program": "${file}",
  421. "console": "integratedTerminal",
  422. "env": { "DEBUGPY_LOG_DIR": "/path/to/logs/folder" }
  423. }
  424. ]
  425. }
  426. Then start the debugger:
  427. .. image:: ./debugger_vscode_start.png
  428. The content of the log file looks like this:
  429. .. code:: bash
  430. ...
  431. D00000.032: IDE --> {
  432. "command": "initialize",
  433. "arguments": {
  434. "clientID": "vscode",
  435. "clientName": "Visual Studio Code",
  436. "adapterID": "python",
  437. "pathFormat": "path",
  438. "linesStartAt1": true,
  439. "columnsStartAt1": true,
  440. "supportsVariableType": true,
  441. "supportsVariablePaging": true,
  442. "supportsRunInTerminalRequest": true,
  443. "locale": "en-us"
  444. },
  445. "type": "request",
  446. "seq": 1
  447. }
  448. ...
  449. With:
  450. - ``IDE`` = VS Code
  451. - ``PYD`` = pydev debugger
  452. - Messages follow the `DAP <https://microsoft.github.io/debug-adapter-protocol/specification>`_
  453. References
  454. ^^^^^^^^^^
  455. - Dump cell and state restoration: https://github.com/jupyterlab/debugger/issues/52
  456. - Protocol Overview: https://microsoft.github.io/debug-adapter-protocol/overview
  457. - Specification: https://microsoft.github.io/debug-adapter-protocol/specification
  458. Build and run the stand-alone examples
  459. --------------------------------------
  460. To install and build the examples in the ``examples`` directory:
  461. .. code:: bash
  462. jlpm run build:examples
  463. To run a specific example, change to the examples directory (i.e.
  464. ``examples/filebrowser``) and enter:
  465. .. code:: bash
  466. python main.py
  467. Debugging in the Browser
  468. ------------------------
  469. All methods of building JupyterLab produce source maps. The source maps
  470. should be available in the source files view of your browser's
  471. development tools under the ``webpack://`` header.
  472. When running JupyterLab normally, expand the ``~`` header to see the
  473. source maps for individual packages.
  474. When running in ``--dev-mode``, the core packages are available under
  475. ``packages/``, while the third party libraries are available under
  476. ``~``. Note: it is recommended to use ``jupyter lab --watch --dev-mode``
  477. while debugging.
  478. When running a test, the packages will be available at the top level
  479. (e.g. ``application/src``), and the current set of test files available
  480. under ``/src``. Note: it is recommended to use ``jlpm run watch`` in the
  481. test folder while debugging test options. See
  482. `above <#build-and-run-the-tests>`__ for more info.
  483. --------------
  484. High level Architecture
  485. -----------------------
  486. The JupyterLab application is made up of two major parts:
  487. - an npm package
  488. - a Jupyter server extension (Python package)
  489. Each part is named ``jupyterlab``. The :ref:`developer tutorial
  490. documentation <developer-guide>`
  491. provides additional architecture information.
  492. The NPM Packages
  493. ----------------
  494. The repository consists of many npm packages that are managed using the
  495. lerna build tool. The npm package source files are in the ``packages/``
  496. subdirectory.
  497. Build the NPM Packages from Source
  498. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  499. .. code:: bash
  500. git clone https://github.com/jupyterlab/jupyterlab.git
  501. cd jupyterlab
  502. pip install -e .
  503. jlpm
  504. jlpm run build:packages
  505. **Rebuild**
  506. .. code:: bash
  507. jlpm run clean
  508. jlpm run build:packages
  509. Writing Documentation
  510. ---------------------
  511. Documentation is written in Markdown and reStructuredText. In
  512. particular, the documentation on our Read the Docs page is written in
  513. reStructuredText. To ensure that the Read the Docs page builds, you'll
  514. need to install the documentation dependencies with ``pip``:
  515. .. code:: bash
  516. pip install -r docs/requirements.txt
  517. To test the docs run:
  518. .. code:: bash
  519. py.test --check-links -k .md . || py.test --check-links -k .md --lf .
  520. The Read the Docs pages can be built using ``make``:
  521. .. code:: bash
  522. cd docs
  523. make html
  524. Or with ``jlpm``:
  525. .. code:: bash
  526. jlpm run docs
  527. Writing Style
  528. ^^^^^^^^^^^^^
  529. - The documentation should be written in the second person, referring
  530. to the reader as "you" and not using the first person plural "we."
  531. The author of the documentation is not sitting next to the user, so
  532. using "we" can lead to frustration when things don't work as
  533. expected.
  534. - Avoid words that trivialize using JupyterLab such as "simply" or
  535. "just." Tasks that developers find simple or easy may not be for
  536. users.
  537. - Write in the active tense, so "drag the notebook cells..." rather
  538. than "notebook cells can be dragged..."
  539. - The beginning of each section should begin with a short (1-2
  540. sentence) high-level description of the topic, feature or component.
  541. - Use "enable" rather than "allow" to indicate what JupyterLab makes
  542. possible for users. Using "allow" connotes that we are giving them
  543. permission, whereas "enable" connotes empowerment.
  544. User Interface Naming Conventions
  545. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  546. Documents, Files, and Activities
  547. """"""""""""""""""""""""""""""""
  548. Files are referrred to as either files or documents, depending on the
  549. context.
  550. Documents are more human centered. If human viewing, interpretation,
  551. interaction is an important part of the experience, it is a document in
  552. that context. For example, notebooks and markdown files will often be
  553. referring to as documents unless referring to the file-ness aspect of it
  554. (e.g., the notebook filename).
  555. Files are used in a less human-focused context. For example, we refer to
  556. files in relation to a file system or file name.
  557. Activities can be either a document or another UI panel that is not file
  558. backed, such as terminals, consoles or the inspector. An open document
  559. or file is an activity in that it is represented by a panel that you can
  560. interact with.
  561. Element Names
  562. """""""""""""
  563. - The generic content area of a tabbed UI is a panel, but prefer to
  564. refer to the more specific name, such as “File browser.” Tab bars
  565. have tabs which toggle panels.
  566. - The menu bar contains menu items, which have their own submenus.
  567. - The main work area can be referred to as the work area when the name
  568. is unambiguous.
  569. - When describing elements in the UI, colloquial names are preferred
  570. (e.g., “File browser” instead of “Files panel”).
  571. The majority of names are written in lower case. These names include:
  572. - tab
  573. - panel
  574. - menu bar
  575. - sidebar
  576. - file
  577. - document
  578. - activity
  579. - tab bar
  580. - main work area
  581. - file browser
  582. - command palette
  583. - cell inspector
  584. - code console
  585. The following sections of the user interface should be in title case,
  586. directly quoting a word in the UI:
  587. - File menu
  588. - Files tab
  589. - Running panel
  590. - Tabs panel
  591. - Simple Interface mode
  592. The capitalized words match the label of the UI element the user is
  593. clicking on because there does not exist a good colloquial name for the
  594. tool, such as “file browser” or “command palette”.
  595. See :ref:`interface` for descriptions of elements in the UI.
  596. The Jupyter Server Extension
  597. ----------------------------
  598. The Jupyter server extension source files are in the jupyterlab/
  599. subdirectory. To use this extension, make sure the Jupyter Notebook
  600. server version 4.3 or later is installed.
  601. Build the JupyterLab server extension
  602. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  603. When you make a change to JupyterLab npm package source files, run:
  604. .. code:: bash
  605. jlpm run build
  606. to build the changes, and then refresh your browser to see the changes.
  607. To have the system build after each source file change, run:
  608. .. code:: bash
  609. jupyter lab --dev-mode --watch
  610. Build Utilities
  611. ---------------
  612. There is a range of build utilities for maintaining the repository. To
  613. get a suggested version for a library use
  614. ``jlpm run get:dependency foo``. To update the version of a library
  615. across the repo use ``jlpm run update:dependency foo ^latest``. To
  616. remove an unwanted dependency use ``jlpm run remove:dependency foo``.
  617. The key utility is ``jlpm run integrity``, which ensures the integrity
  618. of the packages in the repo. It will:
  619. - Ensure the core package version dependencies match everywhere.
  620. - Ensure imported packages match dependencies.
  621. - Ensure a consistent version of all packages.
  622. - Manage the meta package.
  623. The ``packages/metapackage`` package is used to build all of the
  624. TypeScript in the repository at once, instead of 50+ individual builds.
  625. The integrity script also allows you to automatically add a dependency
  626. for a package by importing from it in the TypeScript file, and then
  627. running: ``jlpm run integrity`` from the repo root.
  628. We also have scripts for creating and removing packages in
  629. ``packages/``, ``jlpm run create:package`` and
  630. ``jlpm run remove:package``. When creating a package, if it is meant to
  631. be included in the core bundle, add the
  632. ``jupyterlab: { coreDependency: true }`` metadata to the
  633. ``package.json``. Packages with ``extension`` or ``mimeExtension``
  634. metadata are considered to be a core dependency unless they are
  635. explicitly marked otherwise.
  636. Testing Changes to External Packages
  637. ------------------------------------
  638. Linking/Unlinking Packages to JupyterLab
  639. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  640. If you want to make changes to one of JupyterLab's external packages
  641. (for example, `Lumino <https://github.com/jupyterlab/lumino>`__ and test
  642. them out against your copy of JupyterLab, you can easily do so using the
  643. ``link`` command:
  644. 1. Make your changes and then build the external package
  645. 2. Register a link to the modified external package
  646. - navigate to the external package dir and run ``jlpm link``
  647. 3. Link JupyterLab to modded package
  648. - navigate to top level of your JupyterLab repo, then run
  649. ``jlpm link "<package-of-interest>"``
  650. You can then (re)build JupyterLab (eg ``jlpm run build``) and your
  651. changes should be picked up by the build.
  652. To restore JupyterLab to its original state, you use the ``unlink``
  653. command:
  654. 1. Unlink JupyterLab and modded package
  655. - navigate to top level of your JupyterLab repo, then run
  656. ``jlpm unlink "<package-of-interest>"``
  657. 2. Reinstall original version of the external package in JupyterLab
  658. - run ``jlpm install --check-files``
  659. You can then (re)build JupyterLab and everything should be back to
  660. default.
  661. Possible Linking Pitfalls
  662. ^^^^^^^^^^^^^^^^^^^^^^^^^
  663. If you're working on an external project with more than one package,
  664. you'll probably have to link in your copies of every package in the
  665. project, including those you made no changes to. Failing to do so may
  666. cause issues relating to duplication of shared state.
  667. Specifically, when working with Lumino, you'll probably have to link
  668. your copy of the ``"@lumino/messaging"`` package (in addition to
  669. whatever packages you actually made changes to). This is due to
  670. potential duplication of objects contained in the ``MessageLoop``
  671. namespace provided by the ``messaging`` package.
  672. Keyboard Shortcuts
  673. ------------------
  674. Typeset keyboard shortcuts as follows:
  675. - Monospace typeface, with spaces between individual keys:
  676. ``Shift Enter``.
  677. - For modifiers, use the platform independent word describing key:
  678. ``Shift``.
  679. - For the ``Accel`` key use the phrase: ``Command/Ctrl``.
  680. - Don’t use platform specific icons for modifier keys, as they are
  681. difficult to display in a platform specific way on Sphinx/RTD.
  682. Screenshots and Animations
  683. --------------------------
  684. Our documentation should contain screenshots and animations that
  685. illustrate and demonstrate the software. Here are some guidelines for
  686. preparing them:
  687. - Make sure the screenshot does not contain copyrighted material
  688. (preferable), or the license is allowed in our documentation and
  689. clearly stated.
  690. - If taking a png screenshot, use the Firefox or Chrome developer tools
  691. to do the following:
  692. - set the browser viewport to 1280x720 pixels
  693. - set the device pixel ratio to 1:1 (i.e., non-hidpi, non-retina)
  694. - screenshot the entire *viewport* using the browser developer
  695. tools. Screenshots should not include any browser elements such as
  696. the browser address bar, browser title bar, etc., and should not
  697. contain any desktop background.
  698. - If creating a movie, adjust the settings as above (1280x720 viewport
  699. resolution, non-hidpi) and use a screen capture utility of your
  700. choice to capture just the browser viewport.
  701. - For PNGs, reduce their size using ``pngquant --speed 1 <filename>``.
  702. The resulting filename will have ``-fs8`` appended, so make sure to
  703. rename it and use the resulting file. Commit the optimized png file
  704. to the main repository. Each png file should be no more than a few
  705. hundred kilobytes.
  706. - For movies, upload them to the IPython/Jupyter YouTube channel and
  707. add them to the
  708. `jupyterlab-media <https://github.com/jupyterlab/jupyterlab-media>`__
  709. repository. To embed a movie in the documentation, use the
  710. ``www.youtube-nocookie.com`` website, which can be found by clicking
  711. on the 'privacy-enhanced' embedding option in the Share dialog on
  712. YouTube. Add the following parameters the end of the URL
  713. ``?rel=0&amp;showinfo=0``. This disables the video title and related
  714. video suggestions.
  715. - Screenshots or animations should be preceded by a sentence describing
  716. the content, such as "To open a file, double-click on its name in the
  717. File Browser:".
  718. - We have custom CSS that will add box shadows, and proper sizing of
  719. screenshots and embedded YouTube videos. See examples in the
  720. documentation for how to embed these assets.
  721. To help us organize screenshots and animations, please name the files
  722. with a prefix that matches the names of the source file in which they
  723. are used:
  724. ::
  725. sourcefile.rst
  726. sourcefile_filebrowser.png
  727. sourcefile_editmenu.png
  728. This will help us to keep track of the images as documentation content
  729. evolves.
  730. Notes
  731. -----
  732. - By default, the application will load from the JupyterLab staging
  733. directory (default is ``<sys-prefix>/share/jupyter/lab/build``. If
  734. you wish to run the core application in
  735. ``<git root>/jupyterlab/build``, run ``jupyter lab --core-mode``.
  736. This is the core application that will be shipped.
  737. - If working with extensions, see the :ref:`extension documentation <developer_extensions>`.
  738. - The npm modules are fully compatible with Node/Babel/ES6/ES5. Simply
  739. omit the type declarations when using a language other than
  740. TypeScript.