.. _contributing:
Contributing
============
Datasette is an open source project. We welcome contributions!
This document describes how to contribute to Datasette core. You can also contribute to the wider Datasette ecosystem by creating new :ref:`plugins`.
General guidelines
------------------
* **main should always be releasable**. Incomplete features should live in branches. This ensures that any small bug fixes can be quickly released.
* **The ideal commit** should bundle together the implementation, unit tests and associated documentation updates. The commit message should link to an associated issue.
* **New plugin hooks** should only be shipped if accompanied by a separate release of a non-demo plugin that uses them.
* **New user-facing views and documentation** should be added or updated alongside their implementation. The `/docs` folder includes pages for plugin hooks and built-in views—please ensure any new hooks or views are reflected there so the documentation tests continue to pass.
.. _devenvironment:
Setting up a development environment
------------------------------------
If you have Python 3.10 or higher installed on your computer (on OS X the quickest way to do this `is using homebrew `__) you can install an editable copy of Datasette using the following steps.
If you want to use GitHub to publish your changes, first `create a fork of datasette `__ under your own GitHub account.
Now clone that repository somewhere on your computer::
git clone git@github.com:YOURNAME/datasette
If you want to get started without creating your own fork, you can do this instead::
git clone git@github.com:simonw/datasette
The quickest way to set up a development environment is to use `uv `__. From the repository root you can run the tests directly::
cd datasette
uv run pytest
This will create a local ``.venv/`` and install Datasette plus its development dependencies.
If you prefer to manage your own virtual environment with pip, create and activate one and then install the development dependency group::
python3 -m venv ./venv
source venv/bin/activate
python3 -m pip install -e . --group dev
.. _contributing_running_tests:
Running the tests
-----------------
Once you have done this, you can run the Datasette unit tests from inside your ``datasette/`` directory using `pytest `__ like so::
uv run pytest
You can run the tests faster using multiple CPU cores with `pytest-xdist `__ like this::
uv run pytest -n auto -m "not serial"
``-n auto`` detects the number of available cores automatically. The ``-m "not serial"`` skips tests that don't work well in a parallel test environment. You can run those tests separately like so::
uv run pytest -m "serial"
.. _contributing_playwright:
Running Playwright tests
~~~~~~~~~~~~~~~~~~~~~~~~
Datasette includes a small number of browser automation tests using Playwright_.
These tests are skipped by default, so you can run the main test suite with
``uv run pytest`` without installing Playwright or any browser binaries.
.. _Playwright: https://playwright.dev/python/
The Playwright tests use a separate dependency group. The easiest way to run
them is using ``just``. First install the browser engine you want to test
against. Chromium is used by default:
.. code-block:: bash
just playwright-install
Then run the Playwright test module:
.. code-block:: bash
just playwright
You can also run the same tests against Firefox or WebKit by installing that
browser engine and passing it to ``just playwright``:
.. code-block:: bash
just playwright-install firefox
just playwright firefox
just playwright-install webkit
just playwright webkit
To install every supported browser engine and run the tests against all of
them, use:
.. code-block:: bash
just playwright-install-all
just playwright-all
You can pass extra ``pytest`` options after the browser name:
.. code-block:: bash
just playwright chromium -k permissions
just playwright-all -x
You can add the ``--headed`` option to have Playwright open a browser window that you can see while it runs the tests. This only works if you specify a browser, for example:
.. code-block:: bash
just playwright firefox --headed
Combine this with ``-k`` to watch a specific test:
.. code-block:: bash
just playwright chromium --headed -k test_insert_row
If you are not using ``just``, the equivalent ``uv run`` commands are:
.. code-block:: bash
uv run --group playwright playwright install chromium
uv run --group playwright pytest tests/test_playwright.py --playwright --browser chromium
.. _contributing_modals:
Modal dialogs
-------------
Core dialogs use the same ```` component available to plugins. See :ref:`javascript_plugins_modals` for examples, lifecycle methods, dismissal guards and shared styles.
The implementation lives in ``datasette/static/modal.js`` and ``datasette/static/modal.css``. The wrapper keeps each native ``