contributing.rst 34 KB

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