contributing.rst 38 KB

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