Developers guide#
This guide describes how to install and configure the development environment for contributing to the nbsite repository.
If you have any problems with the steps here, please reach out in the dev channel on Discord or on Discourse.
Quick Overview#
Open an issue on Github if needed
Fork and clone nbsite’s Github repository
Install
pixiRun
pixi run setup-devto create your development environmentMake some changes and run:
pixi run test-unitif you updated the source code to run the unit testspixi run test-exampleif you updated the notebooks to run thempixi run docs-buildif you need to build the website locally
Open a Pull Request
Preliminaries#
Basic understanding of how to contribute to Open Source#
If this is your first open-source contribution, please study one or more of the below resources.
Git#
The nbsite source code is stored in a Git source control repository. The first step to working on nbsite is to install Git onto your system. There are different ways to do this, depending on whether you use Windows, Mac, or Linux.
To install Git on any platform, refer to the Installing Git section of the Pro Git Book.
To contribute to nbsite, you will also need Github account and knowledge of the fork and pull request workflow.
Pixi#
Developing all aspects of nbsite requires a wide range of packages in different environments, but for new contributors the default environment will be more than enough.
To make this more manageable, Pixi manages the developer experience. To install Pixi, follow this guide.
Glossary#
Tasks: A task is what can be run with
pixi run <task-name>. Tasks can be anything from installing packages to running tests.Environments: An environment is a set of packages installed in a virtual environment. Each environment has a name; you can run tasks in a specific environment with the
-eflag. For example,pixi run -e test-core test-unitwill run thetest-unittask in thetest-coreenvironment.Lock-file: A lock-file is a file that contains all the information about the environments.
For more information, see the Pixi documentation.
:::{admonition} Note :class: info
The first time you run pixi, it will create a .pixi directory in the source directory. This directory will contain all the files needed for the virtual environments. The .pixi directory can be large, so it is advised not to put the source directory into a cloud-synced directory.
:::
Installing the Project#
Cloning the Project#
The source code for the nbsite project is hosted on GitHub. The first thing you need to do is clone the repository.
Run in your terminal:
git clone https://github.com/<Your Username Here>/nbsite
The instructions for cloning above created a nbsite directory at your file system location.
This nbsite directory is the source checkout for the remainder of this document, and your current working directory is this directory.
Start developing#
To start developing, run the following command:
pixi run setup-dev
This will create an environment called default (in .pixi/envs), install nbsite in editable mode, and install pre-commit:
:::{admonition} Note :class: info
The first time you run it, it will create a pixi.lock file with information for all available environments.
This command will take a minute or so to run.
:::
All available tasks can be found by running pixi task list, the following sections will give a brief introduction to the most common tasks.
Developer Environment#
The default environment is meant to provide all the tools needed to develop nbsite.
This environment is created by running pixi run setup-dev. Run pixi shell to activate it; this is equivalent to source venv/bin/activate in a Python virtual environment or conda activate in a conda environment.
If you need to run a command directly instead of via pixi, activate the environment and run the command (e.g. pixi shell and pytest nbsite/tests/<somefile.py>).
VS Code#
This environment can also be selected in your IDE. In VS Code, this can be done by running the command Python: Select Interpreter and choosing {'default': Pixi}.
To confirm you are using this dev environment, check the bottom right corner:

Jupyter Lab#
You can launch Jupyter lab with the default environment with pixi run lab. This can be advantageous when you need to edit the documentation or debug an example notebook.
Linting#
nbsite uses pre-commit to lint and format the source code. pre-commit is installed automatically when running pixi run setup-dev; it can also be installed with pixi run lint-install.
pre-commit runs all the linters when a commit is made locally. Linting can be forced to run for all the files with:
pixi run lint
:::{admonition} Note :class: info
Alternatively, if you have pre-commit installed elsewhere you can run:
pre-commit install # To install
pre-commit run --all-files # To run on all files
:::
Testing#
To help keep nbsite maintainable, all Pull Requests (PR) with code changes should typically be accompanied by relevant tests. While exceptions may be made for specific circumstances, the default assumption should be that a Pull Request without tests will not be merged.
There are three types of tasks and five environments related to tests.
Unit tests#
Unit tests are usually small tests executed with pytest. They can be found in nbsite/tests/.
Unit tests can be run with the test-unit task:
pixi run test-unit
:::{admonition} Advanced usage :class: tip
The task is available in the following environments: test-39, test-310, test-311, test-312, and test-313. Where they all have the same environments except for different Python versions.
You can run the task in a specific environment with the -e flag. For example, to run the test-unit task in the test-39 environment, you can run:
pixi run -e test-39 test-unit
:::
:::{admonition} Advanced usage :class: tip
Currently, an editable install needs to be run in each environment. So, if you want to install in the test-312 environment for example, you can add --environment / -e to the command:
pixi run -e test-312 install
:::
Example tests#
nbsite’s documentation consists mainly of Jupyter Notebooks. The example tests execute all the notebooks and fail if an error is raised. Example tests are possible thanks to nbval and can be found in the site/doc/ folder.
Example tests can be run with the following command:
pixi run test-example
Documentation#
The documentation can be built with the command:
pixi run docs-build
After building the docs, you can clean up the build artifacts by running:
pixi run docs-clean
A development version of nbsite can be found here. You can ask a maintainer if they want to make a dev release for your PR, but there is no guarantee they will say yes.
Build#
nbsite has two build tasks to build a Python (for pypi.org) and a Conda package (for anaconda.org).
pixi run build-pip
pixi run build-conda
Continuous Integration#
Every push to the main branch or any PR branch on GitHub automatically triggers a test build with GitHub Actions.
You can see the list of all current and previous builds at this URL
Etiquette#
GitHub Actions provides free build workers for open-source projects. A few considerations will help you be considerate of others needing these limited resources:
Run the tests locally before opening or pushing to an opened PR.
Group commits to meaningful chunks of work before pushing to GitHub (i.e., don’t push on every commit).