2022-01-18 16:43:12 +01:00
# Contributing to Jupyter Notebook
2020-12-16 20:12:40 +01:00
2022-01-18 16:43:12 +01:00
Thanks for contributing to Jupyter Notebook!
2020-12-16 20:12:40 +01:00
Make sure to follow [Project Jupyter's Code of Conduct ](https://github.com/jupyter/governance/blob/master/conduct/code_of_conduct.md )
for a friendly and welcoming collaborative environment.
## Setting up a development environment
Note: You will need NodeJS to build the extension package.
The `jlpm` command is JupyterLab's pinned version of [yarn ](https://yarnpkg.com/ ) that is installed with JupyterLab. You may use
`yarn` or `npm` in lieu of `jlpm` below.
2023-02-19 23:28:59 -08:00
**Note**: we recommend using `mamba` to speed the creating of the environment.
2020-12-16 20:12:40 +01:00
```bash
# create a new environment
2022-01-18 16:43:12 +01:00
mamba create -n notebook -c conda-forge python nodejs -y
2020-12-16 20:12:40 +01:00
# activate the environment
2022-02-25 10:19:03 +01:00
mamba activate notebook
2020-12-16 20:12:40 +01:00
# Install package in development mode
2022-06-13 10:19:48 -05:00
pip install -e ".[dev,test]"
2021-07-14 15:11:46 +02:00
2022-01-18 16:43:12 +01:00
# Link the notebook extension and @jupyter-notebook schemas
2021-11-01 16:04:15 +01:00
jlpm develop
2021-07-14 15:11:46 +02:00
# Enable the server extension
2022-01-18 16:43:12 +01:00
jupyter server extension enable notebook
2020-12-16 20:12:40 +01:00
```
2022-01-18 16:43:12 +01:00
`notebook` follows a monorepo structure. To build all the packages at once:
2020-12-16 20:12:40 +01:00
```bash
2021-04-20 12:11:00 +02:00
jlpm build
```
There is also a `watch` script to watch for changes and rebuild the app automatically:
```bash
jlpm watch
2020-12-16 20:12:40 +01:00
```
2022-01-18 16:43:12 +01:00
To make sure the `notebook` server extension is installed:
2020-12-16 20:12:40 +01:00
```bash
$ jupyter server extension list
Config dir: /home/username/.jupyter
2022-01-18 16:43:12 +01:00
Config dir: /home/username/miniforge3/envs/notebook/etc/jupyter
2020-12-16 20:12:40 +01:00
jupyterlab enabled
- Validating jupyterlab...
2020-12-24 10:30:34 +01:00
jupyterlab 3.0.0 OK
2022-01-18 16:43:12 +01:00
notebook enabled
- Validating notebook...
notebook 7.0.0a0 OK
2020-12-16 20:12:40 +01:00
Config dir: /usr/local/etc/jupyter
```
2022-01-18 16:43:12 +01:00
Then start Jupyter Notebook with:
2020-12-16 20:12:40 +01:00
```bash
2022-01-18 16:43:12 +01:00
jupyter notebook
2020-12-16 20:12:40 +01:00
```
2021-01-29 17:15:02 +01:00
## Running Tests
To run the tests:
```bash
jlpm run build:test
jlpm run test
```
2022-03-09 07:00:26 -06:00
There are also end to end tests to cover higher level user interactions, located in the `ui-tests` folder. To run these tests:
2021-01-29 17:15:02 +01:00
```bash
2021-11-11 10:36:44 +01:00
cd ui-tests
2021-01-29 17:15:02 +01:00
# start a new Jupyter server in a terminal
2021-11-11 10:36:44 +01:00
jlpm start
2021-01-29 17:15:02 +01:00
2021-11-11 10:36:44 +01:00
# in a new terminal, run the tests
jlpm test
```
2021-01-29 17:15:02 +01:00
2021-11-11 10:36:44 +01:00
The `test` script calls the Playwright test runner. You can pass additional arguments to `playwright` by appending parameters to the command. For example to run the test in headed mode, `jlpm test --headed` .
2021-01-29 17:15:02 +01:00
2021-11-11 10:36:44 +01:00
Checkout the [Playwright Command Line Reference ](https://playwright.dev/docs/test-cli/ ) for more information about the available command line options.
2021-01-29 17:15:02 +01:00
Running the end to end tests in headful mode will trigger something like the following:
2021-11-11 10:36:44 +01:00

2022-04-01 08:48:40 -05:00
2023-02-15 14:16:59 +01:00
### Updating reference snapshots
Often a PR might make changes to the user interface, which can cause the visual regression tests to fail.
If you want to update the reference snapshots while working on a PR you can post the following sentence as a GitHub comment:
```
bot please update playwright snapshots
```
This will trigger a GitHub Action that will run the UI tests automatically and push new commits to the branch if the reference snapshots have changed.
2022-04-01 08:48:40 -05:00
## Code Styling
All non-python source code is formatted using [prettier ](https://prettier.io ) and python source code is formatted using [black ](https://github.com/psf/black )s
When code is modified and committed, all staged files will be
automatically formatted using pre-commit git hooks (with help from
[pre-commit ](https://github.com/pre-commit/pre-commit ). The benefit of
using a code formatters like `prettier` and `black` is that it removes the topic of
code style from the conversation when reviewing pull requests, thereby
speeding up the review process.
As long as your code is valid,
the pre-commit hook should take care of how it should look.
`pre-commit` and its associated hooks will automatically be installed when
2022-06-13 10:19:48 -05:00
you run `pip install -e ".[dev,test]"`
2022-04-01 08:48:40 -05:00
To install `pre-commit` manually, run the following:
```shell
pip install pre-commit
pre-commit install
```
You can invoke the pre-commit hook by hand at any time with:
```shell
pre-commit run
```
which should run any autoformatting on your code
and tell you about any errors it couldn't fix automatically.
You may also install [black integration ](https://github.com/psf/black#editor-integration )
into your text editor to format code automatically.
If you have already committed files before setting up the pre-commit
hook with `pre-commit install` , you can fix everything up using
`pre-commit run --all-files` . You need to make the fixing commit
yourself after that.
You may also use the prettier npm script (e.g. `npm run prettier` or
`yarn prettier` or `jlpm prettier` ) to format the entire code base.
We recommend installing a prettier extension for your code editor and
configuring it to format your code with a keyboard shortcut or
automatically on save.
2022-04-09 05:46:04 -05:00
Some of the hooks only run on CI by default, but you can invoke them by
running with the `--hook-stage manual` argument.