2016-10-27 07:17:19 +02:00
.. _developing:
2015-05-14 15:21:36 +02:00
Development
-----------
2014-02-18 18:45:31 +01:00
2015-09-30 16:54:08 +02:00
Setting up a local copy of `the Wagtail git repository <https://github.com/torchbox/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.)
2014-02-18 18:45:31 +01:00
2015-09-30 17:24:42 +02:00
If you're happy to develop on a virtual machine, the `vagrant-wagtail-develop <https://github.com/torchbox/vagrant-wagtail-develop> `_ setup script is the fastest way to get up and running. This will provide you with a running instance of the `Wagtail demo site <https://github.com/torchbox/wagtaildemo/> `_ , with the Wagtail and wagtaildemo codebases available as shared folders for editing on your host machine.
2014-02-18 18:45:31 +01:00
2015-09-30 16:54:08 +02:00
(Build scripts for other platforms would be very much welcomed - if you create one, please let us know via the `Wagtail Developers group <https://groups.google.com/forum/#!forum/wagtail-developers> `_ !)
2015-05-14 15:03:11 +02:00
2015-09-30 16:54:08 +02:00
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.
2015-05-14 15:03:11 +02:00
2015-09-30 16:54:08 +02:00
Setting up the Wagtail codebase
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2015-05-14 15:03:11 +02:00
2016-02-29 16:55:02 +01:00
Install Node.js, v5.3.0 or higher. Instructions for installing Node.js can be found on the `Node.js download page <https://nodejs.org/download/> `_ . 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 <http://pillow.readthedocs.org/en/latest/installation.html#external-libraries> `_ .
2015-05-14 15:03:11 +02:00
2015-09-30 16:54:08 +02:00
Clone a copy of `the Wagtail codebase <https://github.com/torchbox/wagtail> `_ :
2015-05-14 15:03:11 +02:00
2016-11-28 02:30:44 +01:00
.. code-block :: console
2015-05-14 15:03:11 +02:00
2016-11-28 02:30:44 +01:00
$ git clone https://github.com/torchbox/wagtail.git
$ cd wagtail
2015-05-14 15:03:11 +02:00
2016-02-03 02:56:48 +01:00
With your preferred virtualenv activated, install the Wagtail package in development mode with the included testing and documentation dependencies:
2015-05-14 15:03:11 +02:00
2016-11-28 02:30:44 +01:00
.. code-block :: console
2014-02-18 18:45:31 +01:00
2016-11-28 02:30:44 +01:00
$ pip install -e .[testing,docs] -U
2014-02-18 18:45:31 +01:00
2015-09-30 16:54:08 +02:00
Install the tool chain for building static assets:
2015-03-18 20:44:30 +01:00
2016-11-28 02:30:44 +01:00
.. code-block :: console
2015-03-18 20:44:30 +01:00
2016-11-28 02:30:44 +01:00
$ npm install
2015-05-14 15:21:36 +02:00
2015-09-30 16:54:08 +02:00
Compile the assets:
2015-05-14 15:21:36 +02:00
2016-11-28 02:30:44 +01:00
.. code-block :: console
2015-05-14 15:21:36 +02:00
2016-11-28 02:30:44 +01:00
$ npm run build
2015-05-15 10:33:45 +02:00
2015-09-30 16:54:08 +02:00
Any Wagtail sites you start up in this virtualenv will now run against this development instance of Wagtail. We recommend using the `Wagtail demo site <https://github.com/torchbox/wagtaildemo/> `_ as a basis for developing Wagtail.
2015-05-14 15:21:36 +02:00
2015-09-30 16:54:08 +02:00
.. _testing:
2015-03-18 20:44:30 +01:00
2015-09-30 16:54:08 +02:00
Testing
~~~~~~~
2015-03-18 20:44:30 +01:00
2016-11-28 02:30:44 +01:00
From the root of the Wagtail codebase, run the following command to run all the tests:
2015-03-18 20:44:30 +01:00
2016-11-28 02:30:44 +01:00
.. code-block :: console
$ python runtests.py
2015-03-18 20:44:30 +01:00
**Running only some of the tests**
2015-09-30 16:54:08 +02:00
At the time of writing, Wagtail has well over 1000 tests, which takes a while to
2015-03-18 20:44:30 +01:00
run. You can run tests for only one part of Wagtail by passing in the path as
2016-11-28 02:30:44 +01:00
an argument to `` runtests.py `` :
.. code-block :: console
2015-03-18 20:44:30 +01:00
2016-11-28 02:30:44 +01:00
$ python runtests.py wagtail.wagtailcore
2015-03-18 20:44:30 +01:00
**Testing against PostgreSQL**
2015-11-09 13:04:50 +01:00
By default, Wagtail tests against SQLite. You can switch to using PostgreSQL by
2016-11-28 02:30:44 +01:00
using the `` --postgres `` argument:
2015-03-18 20:44:30 +01:00
2016-11-28 02:30:44 +01:00
.. code-block :: console
$ python runtests.py --postgres
2015-03-18 20:44:30 +01:00
If you need to use a different user, password or host. Use the `` PGUSER `` , `` PGPASSWORD `` and `` PGHOST `` environment variables.
2015-11-09 13:04:50 +01:00
**Testing against a different database**
If you need to test against a different database, set the `` DATABASE_ENGINE ``
2016-11-28 02:30:44 +01:00
environment variable to the name of the Django database backend to test against:
.. code-block :: console
2015-11-09 13:04:50 +01:00
2016-11-28 02:30:44 +01:00
$ DATABASE_ENGINE=django.db.backends.mysql python runtests.py
2015-11-09 13:04:50 +01:00
This will create a new database called `` test_wagtail `` in MySQL and run
the tests against it.
2015-03-18 20:44:30 +01:00
**Testing Elasticsearch**
2015-11-19 17:00:54 +01:00
You can test Wagtail against Elasticsearch by passing the `` --elasticsearch ``
2016-11-28 02:30:44 +01:00
argument to `` runtests.py `` :
2015-11-09 13:13:07 +01:00
2016-11-28 02:30:44 +01:00
.. code-block :: console
$ python runtests.py --elasticsearch
2015-11-09 13:13:07 +01:00
Wagtail will attempt to connect to a local instance of Elasticsearch
(`` http://localhost:9200 `` ) and use the index `` test_wagtail `` .
2015-03-18 20:44:30 +01:00
If your Elasticsearch instance is located somewhere else, you can set the
2016-11-28 02:30:44 +01:00
`` ELASTICSEARCH_URL `` environment variable to point to its location:
.. code-block :: console
2015-03-18 20:44:30 +01:00
2016-11-28 02:30:44 +01:00
$ ELASTICSEARCH_URL=http://my-elasticsearch-instance:9200 python runtests.py --elasticsearch
2015-03-18 20:44:30 +01:00
2015-05-05 14:23:05 +02:00
Compiling static assets
~~~~~~~~~~~~~~~~~~~~~~~
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.
To compile the assets, run:
2016-11-28 02:30:44 +01:00
.. code-block :: console
2015-05-05 14:23:05 +02:00
2016-11-28 02:30:44 +01:00
$ npm run build
2015-05-05 14:23:05 +02:00
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:
2016-11-28 02:30:44 +01:00
.. code-block :: console
2015-05-05 14:23:05 +02:00
2016-11-28 02:30:44 +01:00
$ npm start
2016-03-03 05:43:55 +01:00
Compiling the documentation
~~~~~~~~~~~~~~~~~~~~~~~~~~~
The Wagtail documentation is built by Sphinx. To install Sphinx and compile the documentation, run:
2016-11-28 02:30:44 +01:00
.. code-block :: console
2016-03-03 05:43:55 +01:00
2016-11-28 02:30:44 +01:00
$ cd /path/to/wagtail some text
$ # Install the documentation dependencies
$ pip install -e .[docs]
$ # Compile the docs
$ cd docs/
$ make html
2016-03-03 05:43:55 +01:00
The compiled documentation will now be in `` docs/_build/html `` .
Open this directory in a web browser to see it.
Python comes with a module that makes it very easy to preview static files in a web browser.
To start this simple server, run the following commands:
2016-11-28 02:30:44 +01:00
.. code-block :: console
2016-03-03 05:43:55 +01:00
$ cd docs/_build/html/
2016-11-28 02:30:44 +01:00
$ # Python 2
2016-03-03 05:43:55 +01:00
$ python2 -mSimpleHTTPServer 8080
2016-11-28 02:30:44 +01:00
$ # Python 3
2016-03-03 05:43:55 +01:00
$ python3 -mhttp.server 8080
Now you can open <http://localhost:8080/> in your web browser to see the compiled documentation.
Sphinx caches the built documentation to speed up subsequent compilations.
Unfortunately, this cache also hides any warnings thrown by unmodified documentation source files.
To clear the built HTML and start fresh, so you can see all warnings thrown when building the documentation, run:
2016-11-28 02:30:44 +01:00
.. code-block :: console
2016-03-03 05:43:55 +01:00
$ cd docs/
$ make clean
$ make html