contributing.rst 38 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027
  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 implementation 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 implementations (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. Visual Regression and UI Tests
  399. ------------------------------
  400. As part of JupyterLab CI workflows, UI tests are run with visual regression checks. `Galata <https://github.com/jupyterlab/galata>`__ is used for UI testing. Galata provides a high level API to control and inspect JupyterLab UI programmatically, testing tools and CLI to manage tests and other tasks.
  401. UI tests are run for each commit into JupyterLab project in PRs or direct commits. Code changes can sometimes cause UI tests to fail for various reasons. After each test run, Galata generates a user friendly test result report which can be used to inspect failing UI tests. Result report shows the failure reason, call-stack up to the failure and detailed information on visual regression issues. For visual regression errors, reference image and test capture image, along with diff image generated during comparison are provided in the report. You can use these information to debug failing tests. Galata test report can be downloaded from GitHub Actions page for a UI test run. Test artifact is named ``ui-test-output`` and once you extract it, you can access the report by opening ``test/report/index.html`` in a browser window.
  402. Main reasons for UI test failures are:
  403. 1. **A visual regression caused by code changes**:
  404. Sometimes unintentional UI changes are introduced by modifications to project source code. Goal of visual regression testing is to detect this kind of UI changes. If your PR / commit is causing visual regression, then debug and fix the regression caused. You can locally run and debug the UI tests to fix the visual regression. Follow the instructions in steps 5-7 of ``Adding a new UI test suite guide`` in `UI Testing documentation <https://github.com/jupyterlab/jupyterlab/blob/master/ui-tests/README.md#adding-a-new-ui-test-suite>`__ to locally debug and fix UI tests. Once you have a fix, you can push the change to your GitHub branch and test with GitHub actions.
  405. 2. **An intended update to user interface**:
  406. If your code change is introducing an update to UI which causes existing UI Tests to fail, then you will need to update reference image(s) for the failing tests. In order to do that, simply go to GitHub Actions page for the failed test and download test artifacts. It will contain test captures in directory ``test/screenshots``. You can copy the capture for the failed test and paste into reference screenshots directory in JupyterLab source code, replacing the failing test's reference capture. Reference captures are located in ``ui-tests/reference-output/screenshots`` in JupyterLab source code.
  407. For more information on UI Testing, please read the `UI Testing developer documentation <.https://github.com/jupyterlab/jupyterlab/blob/master/ui-tests/README.md>`__ and `Galata documentation <https://github.com/jupyterlab/galata/blob/main/README.md>`__.
  408. Good Practices for Integration tests
  409. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  410. Here are some good practices to follow when writing integration tests:
  411. - Don't compare multiple screenshots in the same test; if the first comparison breaks, it will require running multiple times the CI workflow to fix all tests.
  412. Contributing to the debugger front-end
  413. --------------------------------------
  414. To make changes to the debugger extension, a kernel with support for debugging is required.
  415. Check out the user documentation to learn how to install such kernel: :ref:`debugger`.
  416. Then refresh the page and the debugger sidebar should appear in the right area.
  417. The Debugger Adapter Protocol
  418. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  419. The following diagram illustrates the types of messages sent between the JupyterLab extension and the kernel.
  420. .. image:: ./debugger_protocol_diagram.png
  421. Inspecting Debug Messages in VS Code
  422. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  423. 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.
  424. The first step is to create a test file and a debug configuration (``launch.json``):
  425. .. image:: ./debugger_launch_configuration.png
  426. .. code:: json
  427. {
  428. "version": "0.2.0",
  429. "configurations": [
  430. {
  431. "name": "Python: Current File",
  432. "type": "python",
  433. "request": "launch",
  434. "program": "${file}",
  435. "console": "integratedTerminal",
  436. "env": { "DEBUGPY_LOG_DIR": "/path/to/logs/folder" }
  437. }
  438. ]
  439. }
  440. Then start the debugger:
  441. .. image:: ./debugger_vscode_start.png
  442. The content of the log file looks like this:
  443. .. code:: bash
  444. ...
  445. D00000.032: IDE --> {
  446. "command": "initialize",
  447. "arguments": {
  448. "clientID": "vscode",
  449. "clientName": "Visual Studio Code",
  450. "adapterID": "python",
  451. "pathFormat": "path",
  452. "linesStartAt1": true,
  453. "columnsStartAt1": true,
  454. "supportsVariableType": true,
  455. "supportsVariablePaging": true,
  456. "supportsRunInTerminalRequest": true,
  457. "locale": "en-us"
  458. },
  459. "type": "request",
  460. "seq": 1
  461. }
  462. ...
  463. With:
  464. - ``IDE`` = VS Code
  465. - ``PYD`` = pydev debugger
  466. - Messages follow the `DAP <https://microsoft.github.io/debug-adapter-protocol/specification>`_
  467. References
  468. ^^^^^^^^^^
  469. - Dump cell and state restoration: https://github.com/jupyterlab/debugger/issues/52
  470. - Protocol Overview: https://microsoft.github.io/debug-adapter-protocol/overview
  471. - Specification: https://microsoft.github.io/debug-adapter-protocol/specification
  472. Build and run the stand-alone examples
  473. --------------------------------------
  474. To install and build the examples in the ``examples`` directory:
  475. .. code:: bash
  476. jlpm run build:examples
  477. To run a specific example, change to the examples directory (i.e.
  478. ``examples/filebrowser``) and enter:
  479. .. code:: bash
  480. python main.py
  481. Debugging in the Browser
  482. ------------------------
  483. All methods of building JupyterLab produce source maps. The source maps
  484. should be available in the source files view of your browser's
  485. development tools under the ``webpack://`` header.
  486. When running JupyterLab normally, expand the ``~`` header to see the
  487. source maps for individual packages.
  488. When running in ``--dev-mode``, the core packages are available under
  489. ``packages/``, while the third party libraries are available under
  490. ``~``. Note: it is recommended to use ``jupyter lab --watch --dev-mode``
  491. while debugging.
  492. When running a test, the packages will be available at the top level
  493. (e.g. ``application/src``), and the current set of test files available
  494. under ``/src``. Note: it is recommended to use ``jlpm run watch`` in the
  495. test folder while debugging test options. See
  496. `above <#build-and-run-the-tests>`__ for more info.
  497. --------------
  498. High level Architecture
  499. -----------------------
  500. The JupyterLab application is made up of two major parts:
  501. - an npm package
  502. - a Jupyter server extension (Python package)
  503. Each part is named ``jupyterlab``. The :ref:`developer tutorial
  504. documentation <developer-guide>`
  505. provides additional architecture information.
  506. The NPM Packages
  507. ----------------
  508. The repository consists of many npm packages that are managed using the
  509. lerna build tool. The npm package source files are in the ``packages/``
  510. subdirectory.
  511. Build the NPM Packages from Source
  512. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  513. .. code:: bash
  514. git clone https://github.com/jupyterlab/jupyterlab.git
  515. cd jupyterlab
  516. pip install -e .
  517. jlpm
  518. jlpm run build:packages
  519. **Rebuild**
  520. .. code:: bash
  521. jlpm run clean
  522. jlpm run build:packages
  523. Writing Documentation
  524. ---------------------
  525. Documentation is written in Markdown and reStructuredText. In
  526. particular, the documentation on our Read the Docs page is written in
  527. reStructuredText. To ensure that the Read the Docs page builds, you'll
  528. need to install the documentation dependencies with ``conda``:
  529. .. code:: bash
  530. conda env create -f docs/environment.yml
  531. .. code:: bash
  532. conda activate jupyterlab_documentation
  533. To test the docs run:
  534. .. code:: bash
  535. py.test --check-links -k .md . || py.test --check-links -k .md --lf .
  536. The Read the Docs pages can be built using ``make``:
  537. .. code:: bash
  538. cd docs
  539. make html
  540. Or with ``jlpm``:
  541. .. code:: bash
  542. jlpm run docs
  543. Writing Style
  544. ^^^^^^^^^^^^^
  545. - The documentation should be written in the second person, referring
  546. to the reader as "you" and not using the first person plural "we."
  547. The author of the documentation is not sitting next to the user, so
  548. using "we" can lead to frustration when things don't work as
  549. expected.
  550. - Avoid words that trivialize using JupyterLab such as "simply" or
  551. "just." Tasks that developers find simple or easy may not be for
  552. users.
  553. - Write in the active tense, so "drag the notebook cells..." rather
  554. than "notebook cells can be dragged..."
  555. - The beginning of each section should begin with a short (1-2
  556. sentence) high-level description of the topic, feature or component.
  557. - Use "enable" rather than "allow" to indicate what JupyterLab makes
  558. possible for users. Using "allow" connotes that we are giving them
  559. permission, whereas "enable" connotes empowerment.
  560. User Interface Naming Conventions
  561. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  562. Documents, Files, and Activities
  563. """"""""""""""""""""""""""""""""
  564. Files are referred to as either files or documents, depending on the
  565. context.
  566. Documents are more human centered. If human viewing, interpretation,
  567. interaction is an important part of the experience, it is a document in
  568. that context. For example, notebooks and markdown files will often be
  569. referring to as documents unless referring to the file-ness aspect of it
  570. (e.g., the notebook filename).
  571. Files are used in a less human-focused context. For example, we refer to
  572. files in relation to a file system or file name.
  573. Activities can be either a document or another UI panel that is not file
  574. backed, such as terminals, consoles or the inspector. An open document
  575. or file is an activity in that it is represented by a panel that you can
  576. interact with.
  577. Element Names
  578. """""""""""""
  579. - The generic content area of a tabbed UI is a panel, but prefer to
  580. refer to the more specific name, such as “File browser.” Tab bars
  581. have tabs which toggle panels.
  582. - The menu bar contains menu items, which have their own submenus.
  583. - The main work area can be referred to as the work area when the name
  584. is unambiguous.
  585. - When describing elements in the UI, colloquial names are preferred
  586. (e.g., “File browser” instead of “Files panel”).
  587. The majority of names are written in lower case. These names include:
  588. - tab
  589. - panel
  590. - menu bar
  591. - sidebar
  592. - file
  593. - document
  594. - activity
  595. - tab bar
  596. - main work area
  597. - file browser
  598. - command palette
  599. - cell inspector
  600. - code console
  601. The following sections of the user interface should be in title case,
  602. directly quoting a word in the UI:
  603. - File menu
  604. - Files tab
  605. - Running panel
  606. - Tabs panel
  607. - Simple Interface mode
  608. The capitalized words match the label of the UI element the user is
  609. clicking on because there does not exist a good colloquial name for the
  610. tool, such as “file browser” or “command palette”.
  611. See :ref:`interface` for descriptions of elements in the UI.
  612. The Jupyter Server Extension
  613. ----------------------------
  614. The Jupyter server extension source files are in the jupyterlab/
  615. subdirectory. To use this extension, make sure the Jupyter Notebook
  616. server version 4.3 or later is installed.
  617. Build the JupyterLab server extension
  618. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  619. When you make a change to JupyterLab npm package source files, run:
  620. .. code:: bash
  621. jlpm run build
  622. to build the changes, and then refresh your browser to see the changes.
  623. To have the system build after each source file change, run:
  624. .. code:: bash
  625. jupyter lab --dev-mode --watch
  626. Build Utilities
  627. ---------------
  628. There is a range of build utilities for maintaining the repository. To
  629. get a suggested version for a library use
  630. ``jlpm run get:dependency foo``. To update the version of a library
  631. across the repo use ``jlpm run update:dependency foo ^latest``. To
  632. remove an unwanted dependency use ``jlpm run remove:dependency foo``.
  633. The key utility is ``jlpm run integrity``, which ensures the integrity
  634. of the packages in the repo. It will:
  635. - Ensure the core package version dependencies match everywhere.
  636. - Ensure imported packages match dependencies.
  637. - Ensure a consistent version of all packages.
  638. - Manage the meta package.
  639. The ``packages/metapackage`` package is used to build all of the
  640. TypeScript in the repository at once, instead of 50+ individual builds.
  641. The integrity script also allows you to automatically add a dependency
  642. for a package by importing from it in the TypeScript file, and then
  643. running: ``jlpm run integrity`` from the repo root.
  644. We also have scripts for creating and removing packages in
  645. ``packages/``, ``jlpm run create:package`` and
  646. ``jlpm run remove:package``. When creating a package, if it is meant to
  647. be included in the core bundle, add the
  648. ``jupyterlab: { coreDependency: true }`` metadata to the
  649. ``package.json``. Packages with ``extension`` or ``mimeExtension``
  650. metadata are considered to be a core dependency unless they are
  651. explicitly marked otherwise.
  652. Testing Changes to External Packages
  653. ------------------------------------
  654. Linking/Unlinking Packages to JupyterLab
  655. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  656. If you want to make changes to one of JupyterLab's external packages
  657. (for example, `Lumino <https://github.com/jupyterlab/lumino>`__ and test
  658. them out against your copy of JupyterLab, you can easily do so using the
  659. ``link`` command:
  660. 1. Make your changes and then build the external package
  661. 2. Register a link to the modified external package
  662. - navigate to the external package dir and run ``jlpm link``
  663. 3. Link JupyterLab to modded package
  664. - navigate to top level of your JupyterLab repo, then run
  665. ``jlpm link "<package-of-interest>"``
  666. You can then (re)build JupyterLab (eg ``jlpm run build``) and your
  667. changes should be picked up by the build.
  668. To restore JupyterLab to its original state, you use the ``unlink``
  669. command:
  670. 1. Unlink JupyterLab and modded package
  671. - navigate to top level of your JupyterLab repo, then run
  672. ``jlpm unlink "<package-of-interest>"``
  673. 2. Reinstall original version of the external package in JupyterLab
  674. - run ``jlpm install --check-files``
  675. You can then (re)build JupyterLab and everything should be back to
  676. default.
  677. Possible Linking Pitfalls
  678. ^^^^^^^^^^^^^^^^^^^^^^^^^
  679. If you're working on an external project with more than one package,
  680. you'll probably have to link in your copies of every package in the
  681. project, including those you made no changes to. Failing to do so may
  682. cause issues relating to duplication of shared state.
  683. Specifically, when working with Lumino, you'll probably have to link
  684. your copy of the ``"@lumino/messaging"`` package (in addition to
  685. whatever packages you actually made changes to). This is due to
  686. potential duplication of objects contained in the ``MessageLoop``
  687. namespace provided by the ``messaging`` package.
  688. Keyboard Shortcuts
  689. ------------------
  690. Typeset keyboard shortcuts as follows:
  691. - Monospace typeface, with spaces between individual keys:
  692. ``Shift Enter``.
  693. - For modifiers, use the platform independent word describing key:
  694. ``Shift``.
  695. - For the ``Accel`` key use the phrase: ``Command/Ctrl``.
  696. - Don’t use platform specific icons for modifier keys, as they are
  697. difficult to display in a platform specific way on Sphinx/RTD.
  698. Screenshots and Animations
  699. --------------------------
  700. Our documentation should contain screenshots and animations that
  701. illustrate and demonstrate the software. Here are some guidelines for
  702. preparing them:
  703. - Make sure the screenshot does not contain copyrighted material
  704. (preferable), or the license is allowed in our documentation and
  705. clearly stated.
  706. - If taking a png screenshot, use the Firefox or Chrome developer tools
  707. to do the following:
  708. - set the browser viewport to 1280x720 pixels
  709. - set the device pixel ratio to 1:1 (i.e., non-hidpi, non-retina)
  710. - screenshot the entire *viewport* using the browser developer
  711. tools. Screenshots should not include any browser elements such as
  712. the browser address bar, browser title bar, etc., and should not
  713. contain any desktop background.
  714. - If creating a movie, adjust the settings as above (1280x720 viewport
  715. resolution, non-hidpi) and use a screen capture utility of your
  716. choice to capture just the browser viewport.
  717. - For PNGs, reduce their size using ``pngquant --speed 1 <filename>``.
  718. The resulting filename will have ``-fs8`` appended, so make sure to
  719. rename it and use the resulting file. Commit the optimized png file
  720. to the main repository. Each png file should be no more than a few
  721. hundred kilobytes.
  722. - For movies, upload them to the IPython/Jupyter YouTube channel and
  723. add them to the
  724. `jupyterlab-media <https://github.com/jupyterlab/jupyterlab-media>`__
  725. repository. To embed a movie in the documentation, use the
  726. ``www.youtube-nocookie.com`` website, which can be found by clicking
  727. on the 'privacy-enhanced' embedding option in the Share dialog on
  728. YouTube. Add the following parameters the end of the URL
  729. ``?rel=0&amp;showinfo=0``. This disables the video title and related
  730. video suggestions.
  731. - Screenshots or animations should be preceded by a sentence describing
  732. the content, such as "To open a file, double-click on its name in the
  733. File Browser:".
  734. - We have custom CSS that will add box shadows, and proper sizing of
  735. screenshots and embedded YouTube videos. See examples in the
  736. documentation for how to embed these assets.
  737. To help us organize screenshots and animations, please name the files
  738. with a prefix that matches the names of the source file in which they
  739. are used:
  740. ::
  741. sourcefile.rst
  742. sourcefile_filebrowser.png
  743. sourcefile_editmenu.png
  744. This will help us to keep track of the images as documentation content
  745. evolves.
  746. Notes
  747. -----
  748. - By default, the application will load from the JupyterLab staging
  749. directory (default is ``<sys-prefix>/share/jupyter/lab/build``. If
  750. you wish to run the core application in
  751. ``<git root>/jupyterlab/build``, run ``jupyter lab --core-mode``.
  752. This is the core application that will be shipped.
  753. - If working with extensions, see the :ref:`extension documentation <developer_extensions>`.
  754. - The npm modules are fully compatible with Node/Babel/ES6/ES5. Simply
  755. omit the type declarations when using a language other than
  756. TypeScript.