This describes installing fala locally for development purposes.
"pyenv" is the tool we use to install and use the correct version of Python. (Other CLA repos need different python versions, and we've settled on pyenv as the best way to easily switch versions, depending on the repo you're in.)
-
Install pyenv with brew:
brew install pyenv
-
Set up your shell for pyenv. Make the changes to
~/.zshrc
described here: Set up your shell for pyenv (This is so that pyenv's python binary can be found in your path) -
To make the shell changes take effect:
exec "$SHELL"
(or alternatively, restart your shell)
-
Install into pyenv the python version this repo uses (which is defined in
.python-version
):pyenv install 3.12 --skip-existing
When you're in this repo's directory, pyenv will automatically use the version defined in .python-version
:
$ cd fala
$ python --version
3.12
If you have the wrong python version in your virtual environment, then it's easiest to delete it and re-create it with the right python version:
rm -rf venv
pyenv local 3.12
python --version # check the version is now correct
python3 -m venv venv
source venv/bin/activate
pip install -r requirements/generated/requirements-dev.txt
# etc
It's suggested to use 'nvm' to install Node.
-
Install NVM: https://github.com/nvm-sh/nvm#install--update-script
-
Install the NodeJS version (specified in
.nvmrc
):nvm install
Now when you run nvm use
it'll modify your PATH to point to the NodeJS version specified in .nvmrc
. So if you're swapping between repos with different Node versions, you'll need to rerun nvm use
each time, or you can automate it.
You can check your NodeJS version:
node --version
-
Clone the repository:
git clone [email protected]:ministryofjustice/fala.git
-
Check your Python version:
$ cd fala $ python --version 3.12
-
Create the python environment, activate it and install the requirements:
python3 -m venv venv source venv/bin/activate pip install -r requirements/generated/requirements-dev.txt
-
Build the assets:
nvm use npm install npm run build
-
Create a
.env
file from the example file:`cp .env.example .env`
Run the Django server with:
./manage.py runserver
Frontend assets have their source in fala/assets-src/
and the build outputs to: fala/assets/
.
FALA uses Gulp for this build. The following Gulp tasks are used in development:
build
builds and minifies all assets and does all of the followingsass
builds the SCSS and generates source mapsserve
watches the files for changes and reloads the browser using BrowserSync
Usage during frontend development:
-
Ensure you have the correct NodeJS version - see NodeJS install
-
Run the build:
nvm use npm install npm run build
-
Serve assets:
npm run serve
python3 ./manage.py test
To run a single test, specify the app name, file structure to access the test, test class and test method name:
python3 ./manage.py test <app_folder>.<test_folder>.<test_file_name>.<test_class>.<test_method>
For example:
python3 ./manage.py test adviser.tests.test_results_view.ResultsPageWithBothOrgAndPostcodeTest.test_search_parameters_box_is_visible
You can also omit the test method from the command and run the whole class.
Your test files and methods must be prefixed with the word 'test' e.g. def test_search_parameters_box_is_visible
To lint with Black and flake8, install pre-commit hooks:
source venv/bin/activate
pip install -r requirements/generated/requirements-dev.txt
pre-commit install
To run them manually:
pre-commit run --all-files
Django is our web-framework, Jinja2 is our templating language, and i18n is an acronym which stands for internationalization. As we are not using Django's template engine, we have to add an extension to the Jinja2 set-up in order to use it's i18n features, enabling the use of translation functions (_()
or gettext
) within the Jinja templates.
Typical workflow for creating translations in this project:
- Create/update the
django.po
file with translatable strings (these-i
flags, ignore folders where we don't want to translate):
python manage.py makemessages -l cy -i locale -i venv
-
Add translations in
django.po
file -
Compile the translated
django.po
file into the optimiseddjango.mo
file:
python manage.py compilemessages -l cy
Django will use the django.mo
file to display translations.
TODO - The makemessages
command in Django doesn't natively support Jinja2 templates. It is designed to work with Django's default template engine and expects translation strings to be in those templates.Still need to configure Django to handle Jinja2 templates during makemessages
by adding the appropriate options and ensuring Jinja2 templates are included.