developing.rst 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  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, version 10. Instructions for installing Node.js can be found on the `Node.js download page <https://nodejs.org/download/>`_.
  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. Install Node through nvm (optional):
  21. .. code-block:: console
  22. $ nvm install
  23. Install the tool chain for building static assets:
  24. .. code-block:: console
  25. $ npm install --no-save
  26. Compile the assets:
  27. .. code-block:: console
  28. $ npm run build
  29. 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.
  30. .. _testing:
  31. Testing
  32. ~~~~~~~
  33. From the root of the Wagtail codebase, run the following command to run all the tests:
  34. .. code-block:: console
  35. $ python runtests.py
  36. Running only some of the tests
  37. ------------------------------
  38. At the time of writing, Wagtail has well over 2500 tests, which takes a while to
  39. run. You can run tests for only one part of Wagtail by passing in the path as
  40. an argument to ``runtests.py`` or ``tox``:
  41. .. code-block:: console
  42. $ # Running in the current environment
  43. $ python runtests.py wagtail.core
  44. $ # Running in a specified Tox environment
  45. $ tox -e py36-dj22-sqlite-noelasticsearch wagtail.core
  46. $ # See a list of available Tox environments
  47. $ tox -l
  48. You can also run tests for individual TestCases by passing in the path as
  49. an argument to ``runtests.py``
  50. .. code-block:: console
  51. $ # Running in the current environment
  52. $ python runtests.py wagtail.core.tests.test_blocks.TestIntegerBlock
  53. $ # Running in a specified Tox environment
  54. $ tox -e py36-dj22-sqlite-noelasticsearch wagtail.core.tests.test_blocks.TestIntegerBlock
  55. Running migrations for the test app models
  56. ------------------------------------------
  57. You can create migrations for the test app by running the following from the Wagtail root.
  58. .. code-block:: console
  59. $ django-admin makemigrations --settings=wagtail.tests.settings
  60. Testing against PostgreSQL
  61. --------------------------
  62. .. note::
  63. In order to run these tests, you must install the required modules for PostgreSQL as described in Django's `Databases documentation`_.
  64. By default, Wagtail tests against SQLite. You can switch to using PostgreSQL by
  65. using the ``--postgres`` argument:
  66. .. code-block:: console
  67. $ python runtests.py --postgres
  68. If you need to use a different user, password, host or port, use the ``PGUSER``, ``PGPASSWORD``, ``PGHOST`` and ``PGPORT`` environment variables respectively.
  69. Testing against a different database
  70. ------------------------------------
  71. .. note::
  72. 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.
  73. If you need to test against a different database, set the ``DATABASE_ENGINE``
  74. environment variable to the name of the Django database backend to test against:
  75. .. code-block:: console
  76. $ DATABASE_ENGINE=django.db.backends.mysql python runtests.py
  77. This will create a new database called ``test_wagtail`` in MySQL and run
  78. the tests against it.
  79. 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:
  80. * ``DATABASE_ENGINE``
  81. * ``DATABASE_NAME``
  82. * ``DATABASE_PASSWORD``
  83. * ``DATABASE_HOST``
  84. * Note that for MySQL, this must be `127.0.0.1` rather than `localhost` if you need to connect using a TCP socket
  85. * ``DATABASE_PORT``
  86. Testing Elasticsearch
  87. ---------------------
  88. You can test Wagtail against Elasticsearch by passing the ``--elasticsearch``
  89. argument to ``runtests.py``:
  90. .. code-block:: console
  91. $ python runtests.py --elasticsearch
  92. Wagtail will attempt to connect to a local instance of Elasticsearch
  93. (``http://localhost:9200``) and use the index ``test_wagtail``.
  94. If your Elasticsearch instance is located somewhere else, you can set the
  95. ``ELASTICSEARCH_URL`` environment variable to point to its location:
  96. .. code-block:: console
  97. $ ELASTICSEARCH_URL=http://my-elasticsearch-instance:9200 python runtests.py --elasticsearch
  98. Browser and device support
  99. --------------------------
  100. Wagtail is meant to be used on a wide variety of devices and browsers. Supported browser / device versions include:
  101. ============= ============= =============
  102. Browser Device/OS Version(s)
  103. ============= ============= =============
  104. Mobile Safari iOS Phone Last 2
  105. Mobile Safari iOS Tablet Last 2
  106. Chrome Android Last 2
  107. IE Desktop 11
  108. Chrome Desktop Last 2
  109. MS Edge Desktop Last 2
  110. Firefox Desktop Latest
  111. Firefox ESR Desktop Latest
  112. Safari macOS Last 2
  113. ============= ============= =============
  114. 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**. To test on IE, install virtual machines `made available by Microsoft <https://developer.microsoft.com/en-us/microsoft-edge/tools/vms/>`_.
  115. IE 11 is gradually falling out of use, and specific features are unsupported in this browser:
  116. * Rich text copy-paste in the rich text editor.
  117. * Sticky toolbar in the rich text editor.
  118. * Focus outline styles in the main menu & explorer menu.
  119. * Keyboard access to the actions in page listing tables.
  120. **Unsupported browsers / devices include:**
  121. ============= ============= =============
  122. Browser Device/OS Version(s)
  123. ============= ============= =============
  124. Stock browser Android All
  125. IE Desktop 10 and below
  126. Safari Windows All
  127. ============= ============= =============
  128. Accessibility targets
  129. ---------------------
  130. 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. Wagtail’s administration user interface isn’t accessible at the moment (see `issue #4199 <https://github.com/wagtail/wagtail/issues/4199>`_), but here are specific assistive technologies we aim to test for, and ultimately support:
  131. ============= ====================
  132. Type Assistive technology
  133. ============= ====================
  134. Screen reader `NVDA <https://www.nvaccess.org/download/>`_ on Windows with Firefox ESR
  135. Screen reader `VoiceOver <https://support.apple.com/en-gb/guide/voiceover-guide/welcome/web>`_ on macOS with Safari
  136. Magnification `Windows Magnifier <https://support.microsoft.com/en-gb/help/11542/windows-use-magnifier>`_
  137. Magnification macOS Zoom
  138. Voice control Windows Speech Recognition
  139. Voice control macOS Dictation
  140. Screen reader 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
  141. ============= ====================
  142. 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:
  143. * `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.
  144. * `Axe <https://chrome.google.com/webstore/detail/axe/lhdoppojpmngadmnindnejefpokejbdd>`_ Chrome extension for more comprehensive automated tests of a given page.
  145. * `Accessibility Insights for Web <https://accessibilityinsights.io/docs/en/web/overview>`_ Chrome extension for semi-automated tests, and manual audits.
  146. Compiling static assets
  147. ~~~~~~~~~~~~~~~~~~~~~~~
  148. All static assets such as JavaScript, CSS, images, and fonts for the Wagtail admin are compiled from their respective sources by ``gulp``. 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.
  149. To compile the assets, run:
  150. .. code-block:: console
  151. $ npm run build
  152. 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:
  153. .. code-block:: console
  154. $ npm start
  155. Compiling the documentation
  156. ~~~~~~~~~~~~~~~~~~~~~~~~~~~
  157. The Wagtail documentation is built by Sphinx. To install Sphinx and compile the documentation, run:
  158. .. code-block:: console
  159. $ cd /path/to/wagtail
  160. $ # Install the documentation dependencies
  161. $ pip install -e .[docs]
  162. $ # Compile the docs
  163. $ cd docs/
  164. $ make html
  165. The compiled documentation will now be in ``docs/_build/html``.
  166. Open this directory in a web browser to see it.
  167. Python comes with a module that makes it very easy to preview static files in a web browser.
  168. To start this simple server, run the following commands:
  169. .. code-block:: console
  170. $ cd docs/_build/html/
  171. $ python -mhttp.server 8080
  172. Now you can open <http://localhost:8080/> in your web browser to see the compiled documentation.
  173. Sphinx caches the built documentation to speed up subsequent compilations.
  174. Unfortunately, this cache also hides any warnings thrown by unmodified documentation source files.
  175. To clear the built HTML and start fresh, so you can see all warnings thrown when building the documentation, run:
  176. .. code-block:: console
  177. $ cd docs/
  178. $ make clean
  179. $ make html
  180. Wagtail also provides a way for documentation to be compiled automatically on each change.
  181. To do this, you can run the following command to see the changes automatically at ``localhost:4000``:
  182. .. code-block:: console
  183. $ cd docs/
  184. $ make livehtml
  185. .. _Databases documentation: https://docs.djangoproject.com/en/stable/ref/databases/
  186. .. _DATABASES: https://docs.djangoproject.com/en/stable/ref/settings/#databases