contributing.rst 34 KB

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