contributing.rst 38 KB

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