developing.rst 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362
  1. .. _developing:
  2. Development
  3. ===========
  4. Setting up a local copy of `the Wagtail git repository <https://github.com/wagtail/wagtail>`_ is slightly more involved than running a release package of Wagtail, as it requires `Node.js <https://nodejs.org/>`_ and NPM for building JavaScript and CSS assets. (This is not required when running a release version, as the compiled assets are included in the release package.)
  5. If you're happy to develop on a virtual machine, the `vagrant-wagtail-develop <https://github.com/wagtail/vagrant-wagtail-develop>`_ and `docker-wagtail-develop <https://github.com/wagtail/docker-wagtail-develop>`_ setup scripts are the fastest way to get up and running. They will provide you with a running instance of the `Wagtail Bakery demo site <https://github.com/wagtail/bakerydemo/>`_, with the Wagtail and bakerydemo codebases available as shared folders for editing on your host machine.
  6. (Build scripts for other platforms would be very much welcomed - if you create one, please let us know via the `Slack workspace <https://github.com/wagtail/wagtail/wiki/Slack>`_!)
  7. If you'd prefer to set up all the components manually, read on. These instructions assume that you're familiar with using pip and virtualenv to manage Python packages.
  8. Setting up the Wagtail codebase
  9. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  10. Install `Node.js <https://nodejs.org/>`_, version 16.
  11. You can also use Node version manager (nvm) since Wagtail supplies a ``.nvmrc`` file in the root of the project with the minimum required Node version - see nvm's `installation instructions <https://github.com/creationix/nvm>`_.
  12. You will also need to install the **libjpeg** and **zlib** libraries, if you haven't done so already - see Pillow's `platform-specific installation instructions <https://pillow.readthedocs.org/en/latest/installation.html#external-libraries>`_.
  13. Clone a copy of `the Wagtail codebase <https://github.com/wagtail/wagtail>`_:
  14. .. code-block:: console
  15. $ git clone https://github.com/wagtail/wagtail.git
  16. $ cd wagtail
  17. With your preferred virtualenv activated, install the Wagtail package in development mode with the included testing and documentation dependencies:
  18. .. code-block:: console
  19. $ pip install -e .[testing,docs] -U
  20. $ # or if using zsh as your shell:
  21. $ # pip install -e '.[testing,docs]' -U
  22. Install Node through nvm (optional):
  23. .. code-block:: console
  24. $ nvm install
  25. Install the tool chain for building static assets:
  26. .. code-block:: console
  27. $ npm install --no-save
  28. Compile the assets:
  29. .. code-block:: console
  30. $ npm run build
  31. Any Wagtail sites you start up in this virtualenv will now run against this development instance of Wagtail. We recommend using the `Wagtail Bakery demo site <https://github.com/wagtail/bakerydemo/>`_ as a basis for developing Wagtail. Keep in mind that the setup steps for a Wagtail site may include installing a release version of Wagtail, which will override the development version you've just set up. In this case, you should install the site before running the ``pip install -e`` step, or re-run that step after the site is installed.
  32. .. _testing:
  33. Testing
  34. ~~~~~~~
  35. From the root of the Wagtail codebase, run the following command to run all the Python tests:
  36. .. code-block:: console
  37. $ python runtests.py
  38. Running only some of the tests
  39. ------------------------------
  40. At the time of writing, Wagtail has well over 2500 tests, which takes a while to
  41. run. You can run tests for only one part of Wagtail by passing in the path as
  42. an argument to ``runtests.py`` or ``tox``:
  43. .. code-block:: console
  44. $ # Running in the current environment
  45. $ python runtests.py wagtail.core
  46. $ # Running in a specified Tox environment
  47. $ tox -e py39-dj32-sqlite-noelasticsearch wagtail.core
  48. $ # See a list of available Tox environments
  49. $ tox -l
  50. You can also run tests for individual TestCases by passing in the path as
  51. an argument to ``runtests.py``
  52. .. code-block:: console
  53. $ # Running in the current environment
  54. $ python runtests.py wagtail.core.tests.test_blocks.TestIntegerBlock
  55. $ # Running in a specified Tox environment
  56. $ tox -e py39-dj32-sqlite-noelasticsearch wagtail.core.tests.test_blocks.TestIntegerBlock
  57. Running migrations for the test app models
  58. ------------------------------------------
  59. You can create migrations for the test app by running the following from the Wagtail root.
  60. .. code-block:: console
  61. $ django-admin makemigrations --settings=wagtail.tests.settings
  62. Testing against PostgreSQL
  63. --------------------------
  64. .. note::
  65. In order to run these tests, you must install the required modules for PostgreSQL as described in Django's `Databases documentation`_.
  66. By default, Wagtail tests against SQLite. You can switch to using PostgreSQL by
  67. using the ``--postgres`` argument:
  68. .. code-block:: console
  69. $ python runtests.py --postgres
  70. If you need to use a different user, password, host or port, use the ``PGUSER``, ``PGPASSWORD``, ``PGHOST`` and ``PGPORT`` environment variables respectively.
  71. Testing against a different database
  72. ------------------------------------
  73. .. note::
  74. In order to run these tests, you must install the required client libraries and modules for the given database as described in Django's `Databases`_ documentation or 3rd-party database backend's documentation.
  75. If you need to test against a different database, set the ``DATABASE_ENGINE``
  76. environment variable to the name of the Django database backend to test against:
  77. .. code-block:: console
  78. $ DATABASE_ENGINE=django.db.backends.mysql python runtests.py
  79. This will create a new database called ``test_wagtail`` in MySQL and run
  80. the tests against it.
  81. If you need to use different connection settings, use the following environment variables which correspond to the respective keys within Django's `DATABASES`_ settings dictionary:
  82. * ``DATABASE_ENGINE``
  83. * ``DATABASE_NAME``
  84. * ``DATABASE_PASSWORD``
  85. * ``DATABASE_HOST``
  86. * Note that for MySQL, this must be ``127.0.0.1`` rather than ``localhost`` if you need to connect using a TCP socket
  87. * ``DATABASE_PORT``
  88. It is also possible to set ``DATABASE_DRIVER``, which corresponds to the `driver` value within `OPTIONS` if an SQL Server engine is used.
  89. Testing Elasticsearch
  90. ---------------------
  91. You can test Wagtail against Elasticsearch by passing the ``--elasticsearch``
  92. argument to ``runtests.py``:
  93. .. code-block:: console
  94. $ python runtests.py --elasticsearch
  95. Wagtail will attempt to connect to a local instance of Elasticsearch
  96. (``http://localhost:9200``) and use the index ``test_wagtail``.
  97. If your Elasticsearch instance is located somewhere else, you can set the
  98. ``ELASTICSEARCH_URL`` environment variable to point to its location:
  99. .. code-block:: console
  100. $ ELASTICSEARCH_URL=http://my-elasticsearch-instance:9200 python runtests.py --elasticsearch
  101. Unit tests for JavaScript
  102. -------------------------
  103. We use `Jest <https://jestjs.io/>`_ for unit tests of client-side business logic or UI components. From the root of the Wagtail codebase, run the following command to run all the front-end unit tests:
  104. .. code-block:: console
  105. $ npm run test:unit
  106. Integration tests
  107. -----------------
  108. Our end-to-end browser testing suite also uses `Jest <https://jestjs.io/>`_, combined with `Puppeteer <https://pptr.dev/>`_. We set this up to be installed separately so as not to increase the installation size of the existing Node tooling. To run the tests, you will need to install the dependencies and run the test suite’s Django development server:
  109. .. code-block:: console
  110. $ export DJANGO_SETTINGS_MODULE=wagtail.tests.settings_ui
  111. $ # Assumes the current environment contains a valid installation of Wagtail for local development.
  112. $ ./wagtail/tests/manage.py migrate
  113. $ ./wagtail/tests/manage.py createcachetable
  114. $ DJANGO_SUPERUSER_EMAIL=admin@example.com DJANGO_SUPERUSER_USERNAME=admin DJANGO_SUPERUSER_PASSWORD=changeme ./wagtail/tests/manage.py createsuperuser --noinput
  115. $ ./wagtail/tests/manage.py runserver 0:8000
  116. $ npm --prefix client/tests/integration install
  117. $ npm run test:integration
  118. Integration tests target ``http://localhost:8000`` by default. Use the ``TEST_ORIGIN`` environment variable to use a different port, or test a remote Wagtail instance: ``TEST_ORIGIN=http://localhost:9000 npm run test:integration``.
  119. Browser and device support
  120. --------------------------
  121. Wagtail is meant to be used on a wide variety of devices and browsers. Supported browser / device versions include:
  122. ============= ============= =============
  123. Browser Device/OS Version(s)
  124. ============= ============= =============
  125. Mobile Safari iOS Phone Last 2
  126. Mobile Safari iOS Tablet Last 2
  127. Chrome Android Last 2
  128. Chrome Desktop Last 2
  129. MS Edge Windows Last 2
  130. Firefox Desktop Latest
  131. Firefox ESR Desktop Latest
  132. Safari macOS Last 3
  133. ============= ============= =============
  134. We aim for Wagtail to work in those environments. Our development standards ensure that the site is usable on other browsers **and will work on future browsers**.
  135. IE 11 support has been officially dropped in 2.15 as it is gradually falling out of use. Features already known not to work include:
  136. * Rich text copy-paste in the rich text editor.
  137. * Sticky toolbar in the rich text editor.
  138. * Focus outline styles in the main menu & explorer menu.
  139. * Keyboard access to the actions in page listing tables.
  140. **Unsupported browsers / devices include:**
  141. ============= ============= =============
  142. Browser Device/OS Version(s)
  143. ============= ============= =============
  144. Stock browser Android All
  145. IE Desktop All
  146. Safari Windows All
  147. ============= ============= =============
  148. Accessibility targets
  149. ---------------------
  150. We want to make Wagtail accessible for users of a wide variety of assistive technologies. The specific standard we aim for is `WCAG2.1 <https://www.w3.org/TR/WCAG21/>`_, AA level. Here are specific assistive technologies we aim to test for, and ultimately support:
  151. * `NVDA <https://www.nvaccess.org/download/>`_ on Windows with Firefox ESR
  152. * `VoiceOver <https://support.apple.com/en-gb/guide/voiceover-guide/welcome/web>`_ on macOS with Safari
  153. * `Windows Magnifier <https://support.microsoft.com/en-gb/help/11542/windows-use-magnifier>`_ and macOS Zoom
  154. * Windows Speech Recognition and macOS Dictation
  155. * Mobile `VoiceOver <https://support.apple.com/en-gb/guide/voiceover-guide/welcome/web>`_ on iOS, or `TalkBack <https://support.google.com/accessibility/android/answer/6283677?hl=en-GB>`_ on Android
  156. * Windows `High-contrast mode <https://support.microsoft.com/en-us/windows/use-high-contrast-mode-in-windows-10-fedc744c-90ac-69df-aed5-c8a90125e696>`_
  157. We aim for Wagtail to work in those environments. Our development standards ensure that the site is usable with other assistive technologies. In practice, testing with assistive technology can be a daunting task that requires specialised training – here are tools we rely on to help identify accessibility issues, to use during development and code reviews:
  158. * `react-axe <https://github.com/dequelabs/react-axe>`_ integrated directly in our build tools, to identify actionable issues. Logs its results in the browser console.
  159. * `@wordpress/jest-puppeteer-axe <https://github.com/WordPress/gutenberg/tree/trunk/packages/jest-puppeteer-axe>`_ running Axe checks as part of integration tests.
  160. * `Axe <https://chrome.google.com/webstore/detail/axe/lhdoppojpmngadmnindnejefpokejbdd>`_ Chrome extension for more comprehensive automated tests of a given page.
  161. * `Accessibility Insights for Web <https://accessibilityinsights.io/docs/en/web/overview>`_ Chrome extension for semi-automated tests, and manual audits.
  162. Known accessibility issues
  163. --------------------------
  164. Wagtail’s administration interface isn’t fully accessible at the moment. We actively work on fixing issues both as part of ongoing maintenance and bigger overhauls. To learn about known issues, check out:
  165. * The `WCAG2.1 AA for CMS admin <https://github.com/wagtail/wagtail/projects/5>`_ issues backlog.
  166. * Our `2021 accessibility audit <https://docs.google.com/spreadsheets/d/1l7tnpEyJiC5BWE_JX0XCkknyrjxYA5T2aee5JgPnmi4/edit>`_.
  167. The audit also states which parts of Wagtail have and haven’t been tested, how issues affect WCAG 2.1 compliance, and the likely impact on users.
  168. Compiling static assets
  169. ~~~~~~~~~~~~~~~~~~~~~~~
  170. All static assets such as JavaScript, CSS, images, and fonts for the Wagtail admin are compiled from their respective sources by ``webpack``. The compiled assets are not committed to the repository, and are compiled before packaging each new release. Compiled assets should not be submitted as part of a pull request.
  171. To compile the assets, run:
  172. .. code-block:: console
  173. $ npm run build
  174. This must be done after every change to the source files. To watch the source files for changes and then automatically recompile the assets, run:
  175. .. code-block:: console
  176. $ npm start
  177. Using the pattern library
  178. ~~~~~~~~~~~~~~~~~~~~~~~~~
  179. Wagtail’s UI component library is built with `Storybook <https://storybook.js.org/>`_ and `django-pattern-library <https://github.com/torchbox/django-pattern-library>`_. To run it locally,
  180. .. code-block:: console
  181. $ export DJANGO_SETTINGS_MODULE=wagtail.tests.settings_ui
  182. $ # Assumes the current environment contains a valid installation of Wagtail for local development.
  183. $ ./wagtail/tests/manage.py migrate
  184. $ ./wagtail/tests/manage.py createcachetable
  185. $ ./wagtail/tests/manage.py runserver 0:8000
  186. $ # In a separate terminal:
  187. $ npm run storybook
  188. The last command will start Storybook at ``http://localhost:6006/``. It will proxy specific requests to Django at ``http://localhost:8000`` by default. Use the ``TEST_ORIGIN`` environment variable to use a different port for Django: ``TEST_ORIGIN=http://localhost:9000 npm run storybook``.
  189. Compiling the documentation
  190. ~~~~~~~~~~~~~~~~~~~~~~~~~~~
  191. The Wagtail documentation is built by Sphinx. To install Sphinx and compile the documentation, run:
  192. .. code-block:: console
  193. $ cd /path/to/wagtail
  194. $ # Install the documentation dependencies
  195. $ pip install -e .[docs]
  196. $ # or if using zsh as your shell:
  197. $ # pip install -e '.[docs]' -U
  198. $ # Compile the docs
  199. $ cd docs/
  200. $ make html
  201. The compiled documentation will now be in ``docs/_build/html``.
  202. Open this directory in a web browser to see it.
  203. Python comes with a module that makes it very easy to preview static files in a web browser.
  204. To start this simple server, run the following commands:
  205. .. code-block:: console
  206. $ cd docs/_build/html/
  207. $ python -mhttp.server 8080
  208. Now you can open <http://localhost:8080/> in your web browser to see the compiled documentation.
  209. Sphinx caches the built documentation to speed up subsequent compilations.
  210. Unfortunately, this cache also hides any warnings thrown by unmodified documentation source files.
  211. To clear the built HTML and start fresh, so you can see all warnings thrown when building the documentation, run:
  212. .. code-block:: console
  213. $ cd docs/
  214. $ make clean
  215. $ make html
  216. Wagtail also provides a way for documentation to be compiled automatically on each change.
  217. To do this, you can run the following command to see the changes automatically at ``localhost:4000``:
  218. .. code-block:: console
  219. $ cd docs/
  220. $ make livehtml
  221. .. _Databases documentation: https://docs.djangoproject.com/en/stable/ref/databases/
  222. .. _DATABASES: https://docs.djangoproject.com/en/stable/ref/settings/#databases
  223. Automatically lint and code format on commits
  224. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  225. `pre-commit <https://pre-commit.com/>`_ is configured to automatically run code linting and formatting checks with every commit. To install pre-commit into your git hooks run:
  226. .. code-block:: console
  227. $ pre-commit install
  228. pre-commit should now run on every commit you make.