Skip to content

Latest commit

 

History

History
180 lines (125 loc) · 6.83 KB

README.md

File metadata and controls

180 lines (125 loc) · 6.83 KB

Access Civil Legal Aid

Standards Icon

Getting started

Local install for development:

Setup

Create a virtual environment and install the python dependencies:

python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.in -r requirements_dev.in

Assets setup

For this you'll need to install node > v20.9.0.

nvm install --lts
nvm use --lts
npm install

Once installed you now have access to GOVUK components, stylesheets and JS via the node_module

To copy some of the assets you'll need into your project, run the following:

npm run build

Ensure you do this before starting your Flask project as you're JS and SCSS imports will fail in the flask run.

Configuration environment variables

Create your local config file .env from the template file:

cp .env.example .env

Don't worry, you can't commit your .env file.

Run the service

source .venv/bin/activate
flask --app app run --debug --port=8020

Now you can browse: http://127.0.0.1:8020

(The default port for flask apps is 5000, but on Macs this is often found to conflict with Apple's Airplay service, hence using another port here.)

Running in Docker

For local development and deployments, run the below code:

./run_local.sh

Testing

To run the tests:

python -m pytest --cov=app --cov-report=term-missing --cov-branch

Playwright Testing

To run all tests:

pytest

To run unit tests:

pytest tests/unit_tests

To run functional/non-functional tests:

pytest tests/functional_tests

Run tests in headed mode:

pytest --headed

Run tests in a different browser (chromium, firefox, webkit):

pytest --browser firefox

Run tests in multiple browsers:

pytest --browser chromium --browser webkit

If you are running into issues where it states a browser needs to be installed run:

playwright install

For further guidance on writing tests https://playwright.dev/python/docs/writing-tests

Code formatting and linting

The following will:

  • Generate requirement.txt files from files inside requirements/source/.in and put them into requirements/generated/.txt
  • Run linting checks with ruff
  • Run secret detection via trufflehog3
pre-commit install

Manually running linting

The Ruff linter looks for code quality issues. Ensure there are no ruff issues before committing.

To lint all files in the directory, run:

ruff check

To format all files in the directory, run:

ruff format

Manually running secret detection

The trufflehog3 package looks for any exposed secrets in your project.

To use trufflehog on your current project, run:

trufflehog3 filesystem .

Translation

We are using the Flask-Babel package to translate text. There are 4 key components to translating text on the website.

  1. babel.cfg - Identifies which files to look for strings that can be translated
  2. ./bin/translate.sh - Script to collect/update all translatable strings
  3. pybabel compile - Should be run after updating any messages.po files. The full command is given in the output of translate.sh script
  4. There are two languages(English and Welsh) available on the site. No translation is provided for English as that is the default language

How to translate text in template

  1. Wrap text in {% trans %}...{% endtrans %}
  2. Run ./bin/translate.sh
  3. Update app/translations/cy/LC_MESSAGES/messages.po with welsh text
  4. Run pybabel compile -d app/translations -l cy -f

How to translate text in python

from flask_babel import lazy_gettext as _
_("text to translate")
  1. Run ./bin/translate.sh
  2. Update app/translations/cy/LC_MESSAGES/messages.po with welsh text
  3. Run `pybabel compile -d app/translations -l