2017-07-31 19:42:31 +03:00
|
|
|
============
|
|
|
|
Contributing
|
|
|
|
============
|
|
|
|
|
2021-07-16 14:57:22 +03:00
|
|
|
Source code
|
|
|
|
===========
|
|
|
|
|
2024-02-26 15:34:02 +03:00
|
|
|
Pontoon source code is available on `GitHub <https://github.com/mozilla/pontoon>`_.
|
2021-07-16 14:57:22 +03:00
|
|
|
|
|
|
|
|
2021-09-13 22:05:29 +03:00
|
|
|
Issues
|
|
|
|
======
|
2017-07-31 19:42:31 +03:00
|
|
|
|
2021-09-13 22:05:29 +03:00
|
|
|
Our work is tracked in `GitHub <https://github.com/mozilla/pontoon/issues>`_.
|
2017-07-31 19:42:31 +03:00
|
|
|
|
2024-02-26 15:34:02 +03:00
|
|
|
`Report a new issue <https://github.com/mozilla/pontoon/issues/new>`_.
|
2017-07-31 19:42:31 +03:00
|
|
|
|
|
|
|
|
|
|
|
Docker
|
|
|
|
======
|
|
|
|
|
2022-02-21 21:28:25 +03:00
|
|
|
While the front-end (JavaScript) build and tests use the host environment for development,
|
|
|
|
the back-end systems (Python/Django, databases, etc.) run in Docker containers.
|
|
|
|
For production use, also the front-end is built in a container.
|
|
|
|
Thus Pontoon requires fewer things to get started
|
|
|
|
and you're guaranteed to have the same server setup as everyone else.
|
2017-07-31 19:42:31 +03:00
|
|
|
|
|
|
|
If you're not familiar with `Docker <https://docs.docker.com/>`_ and
|
|
|
|
`docker-compose <https://docs.docker.com/compose/overview/>`_, it's worth
|
|
|
|
reading up on.
|
|
|
|
|
|
|
|
|
2022-02-21 21:28:25 +03:00
|
|
|
JavaScript setup
|
|
|
|
================
|
|
|
|
|
|
|
|
For working on the front-end, you need at least Node.js 14 and npm 7
|
|
|
|
(`installation instructions <https://docs.npmjs.com/downloading-and-installing-node-js-and-npm>`_).
|
|
|
|
Parts of the front-end use `npm workspaces <https://docs.npmjs.com/cli/v7/using-npm/workspaces>`_,
|
|
|
|
which are not supported by earlier npm versions.
|
|
|
|
|
|
|
|
|
2018-07-09 18:44:53 +03:00
|
|
|
Database
|
|
|
|
========
|
|
|
|
|
|
|
|
By default, you will have default data loaded for only the Pontoon Intro project.
|
2021-01-09 00:11:17 +03:00
|
|
|
If you have a database dump, you can load it into your PostgreSQL database.
|
|
|
|
|
|
|
|
Make sure you backup your existing database first:
|
|
|
|
|
|
|
|
.. code-block:: shell
|
|
|
|
|
|
|
|
$ make dumpdb
|
|
|
|
|
|
|
|
And then load the dump:
|
2018-07-09 18:44:53 +03:00
|
|
|
|
2019-02-22 20:04:47 +03:00
|
|
|
.. code-block:: shell
|
|
|
|
|
|
|
|
$ make loaddb DB_DUMP_FILE=path/to/my/dump
|
2018-07-09 18:44:53 +03:00
|
|
|
|
|
|
|
Note that your database container needs to be running while you do that. You
|
2019-02-22 20:04:47 +03:00
|
|
|
can start just the postgresql container by running:
|
|
|
|
|
|
|
|
.. code-block:: shell
|
|
|
|
|
|
|
|
$ docker-compose run postgresql -d
|
|
|
|
|
2018-07-09 18:44:53 +03:00
|
|
|
|
2019-02-22 20:04:47 +03:00
|
|
|
Interactive shell
|
|
|
|
=================
|
|
|
|
|
|
|
|
If you need to run specific commands, that are not covered by our `Makefile`,
|
|
|
|
you can start an interactive shell inside a Pontoon container:
|
|
|
|
|
|
|
|
.. code-block:: shell
|
|
|
|
|
|
|
|
$ make shell
|
2018-07-09 18:44:53 +03:00
|
|
|
|
|
|
|
|
2019-05-13 20:45:11 +03:00
|
|
|
Browser Support
|
|
|
|
===============
|
2020-01-30 11:01:35 +03:00
|
|
|
|
2021-09-03 19:04:34 +03:00
|
|
|
The list of browsers supported by Pontoon is defined in the `"browserslist"` entry of the root package.json, and contains by default:
|
2019-05-13 20:45:11 +03:00
|
|
|
|
|
|
|
.. code-block:: bash
|
|
|
|
|
2021-09-03 19:04:34 +03:00
|
|
|
Firefox >= 78
|
|
|
|
Chrome >= 80
|
|
|
|
Edge >= 91
|
|
|
|
Safari >= 13.1
|
2019-05-13 20:45:11 +03:00
|
|
|
|
|
|
|
|
2021-02-09 02:19:06 +03:00
|
|
|
Code style
|
|
|
|
==========
|
|
|
|
|
|
|
|
We use code formatters so that we do not have to fight over code style.
|
|
|
|
You are free to write code however you like, because in the end the formatter is the one
|
|
|
|
that will format it. We thus don't need to pay attention to style during
|
|
|
|
code reviews, and are free from those never-ending code style discussions.
|
|
|
|
|
|
|
|
To format the Python and the JavaScript code at once you can use:
|
|
|
|
|
|
|
|
.. code-block:: shell
|
|
|
|
|
|
|
|
$ make format
|
|
|
|
|
|
|
|
Code formatting is explained in more detail in the following sections.
|
|
|
|
|
2021-10-03 02:36:06 +03:00
|
|
|
To run the required linters on the Python and the Javascript code at once you can use:
|
|
|
|
|
|
|
|
.. code-block:: shell
|
|
|
|
|
|
|
|
$ make lint
|
|
|
|
|
2021-02-09 02:19:06 +03:00
|
|
|
|
2017-07-31 19:42:31 +03:00
|
|
|
Python code conventions
|
|
|
|
=======================
|
|
|
|
|
2024-06-03 20:08:47 +03:00
|
|
|
Our Python code is automatically formatted using `ruff <https://docs.astral.sh/ruff/>`_.
|
2020-12-22 15:16:25 +03:00
|
|
|
We enforce that in our Continuous Integration, so you will need to run
|
2024-06-03 20:08:47 +03:00
|
|
|
ruff on your code before sending it for review.
|
2017-07-31 19:42:31 +03:00
|
|
|
|
2024-06-03 20:08:47 +03:00
|
|
|
You can run ruff locally either as an
|
|
|
|
`add-on in your code editor <https://docs.astral.sh/ruff/integrations/#vs-code-official>`_,
|
|
|
|
or as a `git pre-hook commit <https://docs.astral.sh/ruff/integrations/#pre-commit>`_.
|
2020-02-06 17:31:08 +03:00
|
|
|
Alternatively, you can format your code using:
|
2017-07-31 19:42:31 +03:00
|
|
|
|
2020-02-06 17:31:08 +03:00
|
|
|
.. code-block:: shell
|
|
|
|
|
2024-06-03 20:08:47 +03:00
|
|
|
$ make ruff
|
2020-02-06 17:31:08 +03:00
|
|
|
|
2024-06-03 20:08:47 +03:00
|
|
|
In the rare case when you cannot fix an error, use ``# noqa`` to make the linter
|
|
|
|
ignore that error (see `documentation <https://docs.astral.sh/ruff/linter/#error-suppression>`_).
|
|
|
|
Note that in most cases, it is better to fix the issues than ignoring them.
|
2017-07-31 19:42:31 +03:00
|
|
|
|
|
|
|
|
|
|
|
Javascript code conventions
|
|
|
|
===========================
|
|
|
|
|
2021-10-03 02:36:06 +03:00
|
|
|
Our Javascript code is automatically formatted using `Prettier <https://prettier.io/docs/en/index.html>`_.
|
2020-12-22 15:16:25 +03:00
|
|
|
We enforce that in our Continuous Integration, so you will need to run
|
2019-02-22 20:04:47 +03:00
|
|
|
prettier on your code before sending it for review.
|
2020-09-28 00:03:32 +03:00
|
|
|
|
2019-02-22 20:04:47 +03:00
|
|
|
You can run prettier locally either as an
|
2020-01-30 11:01:35 +03:00
|
|
|
`add-on in your code editor <https://prettier.io/docs/en/editors.html>`_,
|
2019-02-22 20:04:47 +03:00
|
|
|
or as a `git pre-hook commit <https://prettier.io/docs/en/precommit.html>`_.
|
|
|
|
Alternatively, you can format your code using:
|
2020-09-28 00:03:32 +03:00
|
|
|
|
2019-02-22 20:04:47 +03:00
|
|
|
.. code-block:: shell
|
2020-09-28 00:03:32 +03:00
|
|
|
|
2021-10-03 02:36:06 +03:00
|
|
|
$ make prettier
|
2020-09-28 00:03:32 +03:00
|
|
|
|
2021-02-09 10:27:58 +03:00
|
|
|
Additionally, there are linting rules that are defined in our
|
2021-02-09 02:19:06 +03:00
|
|
|
``.eslintrc.js`` file. To run the linter, do:
|
2019-02-22 20:04:47 +03:00
|
|
|
|
|
|
|
.. code-block:: shell
|
|
|
|
|
2021-03-17 20:18:09 +03:00
|
|
|
$ make eslint
|
2019-02-22 20:04:47 +03:00
|
|
|
|
2021-02-09 02:19:06 +03:00
|
|
|
In the rare case when you cannot fix an eslint error, use ``// eslint-disable`` to make the linter
|
|
|
|
ignore that error. Note that in most cases, it is better to fix the issues than ignore them.
|
2017-07-31 19:42:31 +03:00
|
|
|
|
2022-03-10 19:23:22 +03:00
|
|
|
For more specifics about the ``translate`` folder, look at the README.md file there.
|
2020-09-28 00:03:32 +03:00
|
|
|
|
|
|
|
|
2017-07-31 19:42:31 +03:00
|
|
|
Git conventions
|
|
|
|
===============
|
|
|
|
|
2017-12-21 18:29:12 +03:00
|
|
|
The first line is a summary of the commit. It should start with one of the following::
|
2017-07-31 19:42:31 +03:00
|
|
|
|
2021-09-13 22:05:29 +03:00
|
|
|
Fix #1234
|
2017-07-31 19:42:31 +03:00
|
|
|
|
|
|
|
or::
|
|
|
|
|
2021-09-13 22:05:29 +03:00
|
|
|
#1234
|
2017-07-31 19:42:31 +03:00
|
|
|
|
|
|
|
|
2021-09-13 22:05:29 +03:00
|
|
|
The first, when it lands, will cause the issue to be closed. The second one just adds
|
|
|
|
a cross-reference.
|
2017-07-31 19:42:31 +03:00
|
|
|
|
|
|
|
After that, the commit should explain *why* the changes are being made and any
|
|
|
|
notes that future readers should know for context or be aware of.
|
|
|
|
|
|
|
|
We follow `The seven rules of a great Git commit message <https://chris.beams.io/posts/git-commit/#seven-rules>`_:
|
|
|
|
|
|
|
|
1. Separate subject from body with a blank line
|
|
|
|
2. Limit the subject line to 50 characters
|
|
|
|
3. Capitalize the subject line
|
|
|
|
4. Do not end the subject line with a period
|
|
|
|
5. Use the imperative mood in the subject line
|
|
|
|
6. Wrap the body at 72 characters
|
|
|
|
7. Use the body to explain what and why vs. how
|
|
|
|
|
|
|
|
|
|
|
|
Pull requests
|
|
|
|
=============
|
|
|
|
|
2021-09-13 22:05:29 +03:00
|
|
|
Pull request summary should indicate the issue the pull request addresses.
|
2017-07-31 19:42:31 +03:00
|
|
|
|
|
|
|
Pull request descriptions should cover at least some of the following:
|
|
|
|
|
|
|
|
1. what is the issue the pull request is addressing?
|
|
|
|
2. why does this pull request fix the issue?
|
|
|
|
3. how should a reviewer review the pull request?
|
|
|
|
4. what did you do to test the changes?
|
|
|
|
5. any steps-to-reproduce for the reviewer to use to test the changes
|
|
|
|
|
|
|
|
|
|
|
|
Code reviews
|
|
|
|
============
|
|
|
|
|
|
|
|
Pull requests should be reviewed before merging.
|
|
|
|
|
|
|
|
Style nits should be covered by linting as much as possible.
|
|
|
|
|
|
|
|
Code reviews should review the changes in the context of the rest of the system.
|
|
|
|
|
|
|
|
|
2022-02-21 21:28:25 +03:00
|
|
|
Python Dependencies
|
|
|
|
===================
|
2017-07-31 19:42:31 +03:00
|
|
|
|
2021-10-03 02:36:06 +03:00
|
|
|
Direct dependencies for Pontoon are distributed across four files:
|
2017-07-31 19:42:31 +03:00
|
|
|
|
2020-12-09 18:16:54 +03:00
|
|
|
1. ``requirements/default.in``: Running Pontoon in production
|
|
|
|
2. ``requirements/dev.in``: Development
|
2021-08-01 20:29:45 +03:00
|
|
|
3. ``requirements/test.in``: Testing
|
|
|
|
4. ``requirements/lint.in``: Linting
|
2019-02-22 20:04:47 +03:00
|
|
|
|
2020-12-09 18:16:54 +03:00
|
|
|
In order to pin and hash the direct and indirect dependencies, we use `pip-compile <https://pypi.org/project/pip-tools/>`_,
|
|
|
|
which yields corresponding ``*.txt`` files. These ``*.txt`` files contain all direct and indirect dependencies,
|
|
|
|
and can be used for installation with ``pip``. After any change to the ``*.in`` files,
|
2021-01-09 00:02:29 +03:00
|
|
|
you should run the following command to update all ``requirements/*.txt`` files.
|
2017-07-31 19:42:31 +03:00
|
|
|
|
2020-12-09 18:16:54 +03:00
|
|
|
.. code-block:: shell
|
2019-02-22 20:04:47 +03:00
|
|
|
|
2021-01-09 00:02:29 +03:00
|
|
|
$ make requirements
|
2017-10-12 18:01:35 +03:00
|
|
|
|
2020-12-09 18:16:54 +03:00
|
|
|
When adding a new requirement, add it to the appropriate ``requirements/*.in`` file.
|
|
|
|
For example, to add the development dependency ``foobar`` version 5, add ``foobar==5`` to ``requirements/dev.in``,
|
2021-01-09 00:02:29 +03:00
|
|
|
and then run the command from above.
|
2017-10-12 18:01:35 +03:00
|
|
|
|
2020-12-09 18:16:54 +03:00
|
|
|
Once you are done adding, removing or updating requirements, rebuild your docker environment:
|
2019-02-22 20:04:47 +03:00
|
|
|
|
|
|
|
.. code-block:: shell
|
2017-07-31 19:42:31 +03:00
|
|
|
|
2021-11-26 18:12:03 +03:00
|
|
|
$ make build-server
|
2017-07-31 19:42:31 +03:00
|
|
|
|
|
|
|
If there are problems, it'll tell you.
|
|
|
|
|
2021-02-11 00:02:10 +03:00
|
|
|
To upgrade existing dependencies within the given constraints of the input
|
|
|
|
files, you can pass options through to the ``pip-compile`` invocations, i.e.
|
|
|
|
|
|
|
|
.. code-block:: shell
|
|
|
|
|
|
|
|
$ make requirements opts=--upgrade
|
2017-07-31 19:42:31 +03:00
|
|
|
|
|
|
|
Documentation
|
|
|
|
=============
|
|
|
|
|
|
|
|
Documentation for Pontoon is built with `Sphinx
|
|
|
|
<http://www.sphinx-doc.org/en/stable/>`_ and is available on ReadTheDocs.
|
|
|
|
|
2018-01-03 19:06:48 +03:00
|
|
|
Building docs is not covered with docker yet, so you will have to do it on your host. To make
|
2017-07-31 19:42:31 +03:00
|
|
|
a virtualenv to build docs, do this:
|
|
|
|
|
2017-08-14 16:28:33 +03:00
|
|
|
.. code-block:: shell
|
2017-07-31 19:42:31 +03:00
|
|
|
|
|
|
|
$ cd docs/
|
|
|
|
$ virtualenv venv
|
|
|
|
$ source venv/bin/activate
|
2020-12-09 18:16:54 +03:00
|
|
|
$ pip install --require-hashes -r requirements.txt
|
2017-07-31 19:42:31 +03:00
|
|
|
|
|
|
|
Then, to build the docs, run this:
|
|
|
|
|
|
|
|
.. code-block:: shell
|
|
|
|
|
|
|
|
$ make html
|
|
|
|
|
|
|
|
The HTML documentation will be in `docs/_build/html/`. Try to open `docs/_build/html/index.html`
|
|
|
|
for example.
|
|
|
|
|
2017-08-14 16:28:33 +03:00
|
|
|
.. note:: Pontoon uses `GraphViz`_ as part of the documentation generation, so
|
|
|
|
you'll need to install it to generate graphs that use it. Most package
|
|
|
|
managers, including `Homebrew`_, have a package available for install.
|
|
|
|
|
|
|
|
.. _GraphViz: http://www.graphviz.org/
|
|
|
|
.. _Homebrew: http://brew.sh/
|
|
|
|
|
2017-07-31 19:42:31 +03:00
|
|
|
|
|
|
|
Running tests
|
|
|
|
=============
|
|
|
|
|
2020-01-30 11:01:35 +03:00
|
|
|
To run the entire test suite, do:
|
2019-02-22 20:04:47 +03:00
|
|
|
|
|
|
|
.. code-block:: shell
|
|
|
|
|
|
|
|
$ make test
|
|
|
|
|
|
|
|
|
2022-03-02 18:10:42 +03:00
|
|
|
To run only the ``translate`` tests:
|
2019-02-22 20:04:47 +03:00
|
|
|
|
|
|
|
.. code-block:: shell
|
2017-07-31 19:42:31 +03:00
|
|
|
|
2020-01-30 11:01:35 +03:00
|
|
|
$ make jest
|
|
|
|
|
|
|
|
|
|
|
|
To run only the Python tests:
|
|
|
|
|
|
|
|
.. code-block:: shell
|
|
|
|
|
|
|
|
$ make pytest
|
2017-07-31 19:42:31 +03:00
|
|
|
|
|
|
|
|
|
|
|
To run specific tests or specify arguments, you'll want to start a shell in the
|
2019-02-22 20:04:47 +03:00
|
|
|
test container:
|
2017-07-31 19:42:31 +03:00
|
|
|
|
2019-02-22 20:04:47 +03:00
|
|
|
.. code-block:: shell
|
|
|
|
|
|
|
|
$ make shell
|
2017-07-31 19:42:31 +03:00
|
|
|
|
|
|
|
|
|
|
|
Then you can run tests as you like.
|
|
|
|
|
2019-02-22 20:04:47 +03:00
|
|
|
Running all the unittests (make sure you run ``./manage.py collectstatic`` first):
|
2017-07-31 19:42:31 +03:00
|
|
|
|
2019-02-22 20:04:47 +03:00
|
|
|
.. code-block:: shell
|
2017-07-31 19:42:31 +03:00
|
|
|
|
2019-02-22 20:04:47 +03:00
|
|
|
app@...:/app$ pytest
|
2017-07-31 19:42:31 +03:00
|
|
|
|
|
|
|
|
2019-02-22 20:04:47 +03:00
|
|
|
Running a directory of tests:
|
2017-07-31 19:42:31 +03:00
|
|
|
|
2019-02-22 20:04:47 +03:00
|
|
|
.. code-block:: shell
|
2017-07-31 19:42:31 +03:00
|
|
|
|
2019-02-22 20:04:47 +03:00
|
|
|
app@...:/app$ pytest pontoon/base/
|
2017-07-31 19:42:31 +03:00
|
|
|
|
|
|
|
|
2019-02-22 20:04:47 +03:00
|
|
|
Running a file of tests:
|
2017-07-31 19:42:31 +03:00
|
|
|
|
2019-02-22 20:04:47 +03:00
|
|
|
.. code-block:: shell
|
2018-04-23 12:39:54 +03:00
|
|
|
|
2019-02-22 20:04:47 +03:00
|
|
|
app@...:/app$ pytest pontoon/base/tests/test_views.py
|
2018-04-23 12:39:54 +03:00
|
|
|
|
|
|
|
|
2017-07-31 19:42:31 +03:00
|
|
|
Writing tests
|
|
|
|
=============
|
|
|
|
|
|
|
|
Put your tests in the ``tests/`` directory of the appropriate app in
|
|
|
|
``pontoon/``.
|
|
|
|
|
|
|
|
|
|
|
|
Mock usage
|
|
|
|
----------
|
|
|
|
|
|
|
|
`Mock <http://www.voidspace.org.uk/python/mock/>`_ is a python library for mocks
|
2017-12-21 18:29:12 +03:00
|
|
|
objects. This allows us to write isolated tests by simulating services besides
|
|
|
|
using the real ones. Best examples are existing tests which admittedly do mocking
|
2017-07-31 19:42:31 +03:00
|
|
|
different depending on the context.
|
|
|
|
|
|
|
|
Tip! Try to mock in limited context so that individual tests don't affect other
|
|
|
|
tests. Use context managers instead of monkey patching imported modules.
|
2017-08-14 16:28:33 +03:00
|
|
|
|
|
|
|
|
|
|
|
Updating Your Local Instance
|
|
|
|
============================
|
2018-07-09 18:44:53 +03:00
|
|
|
|
2017-12-21 18:29:12 +03:00
|
|
|
When changes are merged into the main Pontoon repository, you'll want to update
|
2017-08-14 16:28:33 +03:00
|
|
|
your local development instance to reflect the latest version of the site. You
|
|
|
|
can use Git as normal to pull the latest changes, but if the changes add any new
|
|
|
|
dependencies or alter the database, you'll want to install any new libraries and
|
|
|
|
run any new migrations.
|
|
|
|
|
|
|
|
If you're unsure what needs to be run, it's safe to just perform all of these
|
|
|
|
steps, as they don't affect your setup if nothing has changed:
|
|
|
|
|
|
|
|
.. code-block:: shell
|
|
|
|
|
2023-09-19 14:39:03 +03:00
|
|
|
# Pull the latest code (assuming you've already checked out main).
|
|
|
|
git pull origin main
|
2017-08-14 16:28:33 +03:00
|
|
|
|
|
|
|
# Install new dependencies or update existing ones.
|
2020-12-09 18:16:54 +03:00
|
|
|
pip install -U --force --require-hashes -r requirements/default.txt
|
2017-08-14 16:28:33 +03:00
|
|
|
|
|
|
|
# Run database migrations.
|
|
|
|
python manage.py migrate
|