contributing.rst 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909
  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 10+, 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. Build and run the stand-alone examples
  392. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  393. To install and build the examples in the ``examples`` directory:
  394. .. code:: bash
  395. jlpm run build:examples
  396. To run a specific example, change to the examples directory (i.e.
  397. ``examples/filebrowser``) and enter:
  398. .. code:: bash
  399. python main.py
  400. Debugging in the Browser
  401. ~~~~~~~~~~~~~~~~~~~~~~~~
  402. All methods of building JupyterLab produce source maps. The source maps
  403. should be available in the source files view of your browser's
  404. development tools under the ``webpack://`` header.
  405. When running JupyterLab normally, expand the ``~`` header to see the
  406. source maps for individual packages.
  407. When running in ``--dev-mode``, the core packages are available under
  408. ``packages/``, while the third party libraries are available under
  409. ``~``. Note: it is recommended to use ``jupyter lab --watch --dev-mode``
  410. while debugging.
  411. When running a test, the packages will be available at the top level
  412. (e.g. ``application/src``), and the current set of test files available
  413. under ``/src``. Note: it is recommended to use ``jlpm run watch`` in the
  414. test folder while debugging test options. See
  415. `above <#build-and-run-the-tests>`__ for more info.
  416. --------------
  417. High level Architecture
  418. ~~~~~~~~~~~~~~~~~~~~~~~
  419. The JupyterLab application is made up of two major parts:
  420. - an npm package
  421. - a Jupyter server extension (Python package)
  422. Each part is named ``jupyterlab``. The :ref:`developer tutorial
  423. documentation <developer-guide>`
  424. provides additional architecture information.
  425. The NPM Packages
  426. ~~~~~~~~~~~~~~~~
  427. The repository consists of many npm packages that are managed using the
  428. lerna build tool. The npm package source files are in the ``packages/``
  429. subdirectory.
  430. Build the NPM Packages from Source
  431. ''''''''''''''''''''''''''''''''''
  432. .. code:: bash
  433. git clone https://github.com/jupyterlab/jupyterlab.git
  434. cd jupyterlab
  435. pip install -e .
  436. jlpm
  437. jlpm run build:packages
  438. **Rebuild**
  439. .. code:: bash
  440. jlpm run clean
  441. jlpm run build:packages
  442. Writing Documentation
  443. ~~~~~~~~~~~~~~~~~~~~~
  444. Documentation is written in Markdown and reStructuredText. In
  445. particular, the documentation on our Read the Docs page is written in
  446. reStructuredText. To ensure that the Read the Docs page builds, you'll
  447. need to install the documentation dependencies with ``pip``:
  448. .. code:: bash
  449. pip install -r docs/requirements.txt
  450. To test the docs run:
  451. .. code:: bash
  452. py.test --check-links -k .md . || py.test --check-links -k .md --lf .
  453. The Read the Docs pages can be built using ``make``:
  454. .. code:: bash
  455. cd docs
  456. make html
  457. Or with ``jlpm``:
  458. .. code:: bash
  459. jlpm run docs
  460. Writing Style
  461. '''''''''''''
  462. - The documentation should be written in the second person, referring
  463. to the reader as "you" and not using the first person plural "we."
  464. The author of the documentation is not sitting next to the user, so
  465. using "we" can lead to frustration when things don't work as
  466. expected.
  467. - Avoid words that trivialize using JupyterLab such as "simply" or
  468. "just." Tasks that developers find simple or easy may not be for
  469. users.
  470. - Write in the active tense, so "drag the notebook cells..." rather
  471. than "notebook cells can be dragged..."
  472. - The beginning of each section should begin with a short (1-2
  473. sentence) high-level description of the topic, feature or component.
  474. - Use "enable" rather than "allow" to indicate what JupyterLab makes
  475. possible for users. Using "allow" connotes that we are giving them
  476. permission, whereas "enable" connotes empowerment.
  477. User Interface Naming Conventions
  478. '''''''''''''''''''''''''''''''''
  479. Documents, Files, and Activities
  480. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  481. Files are referrred to as either files or documents, depending on the
  482. context.
  483. Documents are more human centered. If human viewing, interpretation,
  484. interaction is an important part of the experience, it is a document in
  485. that context. For example, notebooks and markdown files will often be
  486. referring to as documents unless referring to the file-ness aspect of it
  487. (e.g., the notebook filename).
  488. Files are used in a less human-focused context. For example, we refer to
  489. files in relation to a file system or file name.
  490. Activities can be either a document or another UI panel that is not file
  491. backed, such as terminals, consoles or the inspector. An open document
  492. or file is an activity in that it is represented by a panel that you can
  493. interact with.
  494. Element Names
  495. ^^^^^^^^^^^^^
  496. - The generic content area of a tabbed UI is a panel, but prefer to
  497. refer to the more specific name, such as “File browser.” Tab bars
  498. have tabs which toggle panels.
  499. - The menu bar contains menu items, which have their own submenus.
  500. - The main work area can be referred to as the work area when the name
  501. is unambiguous.
  502. - When describing elements in the UI, colloquial names are preferred
  503. (e.g., “File browser” instead of “Files panel”).
  504. The majority of names are written in lower case. These names include:
  505. - tab
  506. - panel
  507. - menu bar
  508. - sidebar
  509. - file
  510. - document
  511. - activity
  512. - tab bar
  513. - main work area
  514. - file browser
  515. - command palette
  516. - cell inspector
  517. - code console
  518. The following sections of the user interface should be in title case,
  519. directly quoting a word in the UI:
  520. - File menu
  521. - Files tab
  522. - Running panel
  523. - Tabs panel
  524. - Single-Document Mode
  525. The capitalized words match the label of the UI element the user is
  526. clicking on because there does not exist a good colloquial name for the
  527. tool, such as “file browser” or “command palette”.
  528. See :ref:`interface` for descriptions of elements in the UI.
  529. The Jupyter Server Extension
  530. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  531. The Jupyter server extension source files are in the jupyterlab/
  532. subdirectory. To use this extension, make sure the Jupyter Notebook
  533. server version 4.3 or later is installed.
  534. Build the JupyterLab server extension
  535. '''''''''''''''''''''''''''''''''''''
  536. When you make a change to JupyterLab npm package source files, run:
  537. .. code:: bash
  538. jlpm run build
  539. to build the changes, and then refresh your browser to see the changes.
  540. To have the system build after each source file change, run:
  541. .. code:: bash
  542. jupyter lab --dev-mode --watch
  543. Build Utilities
  544. ~~~~~~~~~~~~~~~
  545. There is a range of build utilities for maintaining the repository. To
  546. get a suggested version for a library use
  547. ``jlpm run get:dependency foo``. To update the version of a library
  548. across the repo use ``jlpm run update:dependency foo ^latest``. To
  549. remove an unwanted dependency use ``jlpm run remove:dependency foo``.
  550. The key utility is ``jlpm run integrity``, which ensures the integrity
  551. of the packages in the repo. It will:
  552. - Ensure the core package version dependencies match everywhere.
  553. - Ensure imported packages match dependencies.
  554. - Ensure a consistent version of all packages.
  555. - Manage the meta package.
  556. The ``packages/metapackage`` package is used to build all of the
  557. TypeScript in the repository at once, instead of 50+ individual builds.
  558. The integrity script also allows you to automatically add a dependency
  559. for a package by importing from it in the TypeScript file, and then
  560. running: ``jlpm run integrity`` from the repo root.
  561. We also have scripts for creating and removing packages in
  562. ``packages/``, ``jlpm run create:package`` and
  563. ``jlpm run remove:package``. When creating a package, if it is meant to
  564. be included in the core bundle, add the
  565. ``jupyterlab: { coreDependency: true }`` metadata to the
  566. ``package.json``. Packages with ``extension`` or ``mimeExtension``
  567. metadata are considered to be a core dependency unless they are
  568. explicitly marked otherwise.
  569. Testing Changes to External Packages
  570. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  571. Linking/Unlinking Packages to JupyterLab
  572. ''''''''''''''''''''''''''''''''''''''''
  573. If you want to make changes to one of JupyterLab's external packages
  574. (for example, `Lumino <https://github.com/jupyterlab/lumino>`__ and test
  575. them out against your copy of JupyterLab, you can easily do so using the
  576. ``link`` command:
  577. 1. Make your changes and then build the external package
  578. 2. Register a link to the modified external package
  579. - navigate to the external package dir and run ``jlpm link``
  580. 3. Link JupyterLab to modded package
  581. - navigate to top level of your JupyterLab repo, then run
  582. ``jlpm link "<package-of-interest>"``
  583. You can then (re)build JupyterLab (eg ``jlpm run build``) and your
  584. changes should be picked up by the build.
  585. To restore JupyterLab to its original state, you use the ``unlink``
  586. command:
  587. 1. Unlink JupyterLab and modded package
  588. - navigate to top level of your JupyterLab repo, then run
  589. ``jlpm unlink "<package-of-interest>"``
  590. 2. Reinstall original version of the external package in JupyterLab
  591. - run ``jlpm install --check-files``
  592. You can then (re)build JupyterLab and everything should be back to
  593. default.
  594. Possible Linking Pitfalls
  595. '''''''''''''''''''''''''
  596. If you're working on an external project with more than one package,
  597. you'll probably have to link in your copies of every package in the
  598. project, including those you made no changes to. Failing to do so may
  599. cause issues relating to duplication of shared state.
  600. Specifically, when working with Lumino, you'll probably have to link
  601. your copy of the ``"@lumino/messaging"`` package (in addition to
  602. whatever packages you actually made changes to). This is due to
  603. potential duplication of objects contained in the ``MessageLoop``
  604. namespace provided by the ``messaging`` package.
  605. Keyboard Shortcuts
  606. ~~~~~~~~~~~~~~~~~~
  607. Typeset keyboard shortcuts as follows:
  608. - Monospace typeface, with spaces between individual keys:
  609. ``Shift Enter``.
  610. - For modifiers, use the platform independent word describing key:
  611. ``Shift``.
  612. - For the ``Accel`` key use the phrase: ``Command/Ctrl``.
  613. - Don’t use platform specific icons for modifier keys, as they are
  614. difficult to display in a platform specific way on Sphinx/RTD.
  615. Screenshots and Animations
  616. ~~~~~~~~~~~~~~~~~~~~~~~~~~
  617. Our documentation should contain screenshots and animations that
  618. illustrate and demonstrate the software. Here are some guidelines for
  619. preparing them:
  620. - Make sure the screenshot does not contain copyrighted material
  621. (preferable), or the license is allowed in our documentation and
  622. clearly stated.
  623. - If taking a png screenshot, use the Firefox or Chrome developer tools
  624. to do the following:
  625. - set the browser viewport to 1280x720 pixels
  626. - set the device pixel ratio to 1:1 (i.e., non-hidpi, non-retina)
  627. - screenshot the entire *viewport* using the browser developer
  628. tools. Screenshots should not include any browser elements such as
  629. the browser address bar, browser title bar, etc., and should not
  630. contain any desktop background.
  631. - If creating a movie, adjust the settings as above (1280x720 viewport
  632. resolution, non-hidpi) and use a screen capture utility of your
  633. choice to capture just the browser viewport.
  634. - For PNGs, reduce their size using ``pngquant --speed 1 <filename>``.
  635. The resulting filename will have ``-fs8`` appended, so make sure to
  636. rename it and use the resulting file. Commit the optimized png file
  637. to the main repository. Each png file should be no more than a few
  638. hundred kilobytes.
  639. - For movies, upload them to the IPython/Jupyter YouTube channel and
  640. add them to the
  641. `jupyterlab-media <https://github.com/jupyterlab/jupyterlab-media>`__
  642. repository. To embed a movie in the documentation, use the
  643. ``www.youtube-nocookie.com`` website, which can be found by clicking
  644. on the 'privacy-enhanced' embedding option in the Share dialog on
  645. YouTube. Add the following parameters the end of the URL
  646. ``?rel=0&amp;showinfo=0``. This disables the video title and related
  647. video suggestions.
  648. - Screenshots or animations should be preceded by a sentence describing
  649. the content, such as "To open a file, double-click on its name in the
  650. File Browser:".
  651. - We have custom CSS that will add box shadows, and proper sizing of
  652. screenshots and embedded YouTube videos. See examples in the
  653. documentation for how to embed these assets.
  654. To help us organize screenshots and animations, please name the files
  655. with a prefix that matches the names of the source file in which they
  656. are used:
  657. ::
  658. sourcefile.rst
  659. sourcefile_filebrowser.png
  660. sourcefile_editmenu.png
  661. This will help us to keep track of the images as documentation content
  662. evolves.
  663. Notes
  664. ~~~~~
  665. - By default, the application will load from the JupyterLab staging
  666. directory (default is ``<sys-prefix>/share/jupyter/lab/build``. If
  667. you wish to run the core application in
  668. ``<git root>/jupyterlab/build``, run ``jupyter lab --core-mode``.
  669. This is the core application that will be shipped.
  670. - If working with extensions, see the :ref:`extension documentation <developer_extensions>`.
  671. - The npm modules are fully compatible with Node/Babel/ES6/ES5. Simply
  672. omit the type declarations when using a language other than
  673. TypeScript.