Skip to main content

Setup

Prerequisites

To work with the template monorepo you'll need to install these tools.

Pre-commit

When contributing to this project, pre-commits are necessary, as they run certain tests, sanitisers, and formatters.

The project provides a .pre-commit-config.yaml file that is used to setup git pre-commit hooks.

On commit locally, code is automatically formatted and checked for security vulnerabilities using pre-commit git hooks.

Installation

To initialize pre-commit in your local repository, run

pre-commit install

This tells pre-commit to run for this repository on every commit.

Usage

Pre-commit will run on every commit, but can also be run manually on all files:

pre-commit run --all-files

Pre-commit tests can be skipped on commits with git commit --no-verify.

caution

If you have to skip the pre-commit tests, you're probably doing something you're not supposed to, and whoever commits after you might have to fix your "mistakes". Consider updating the pre-commit hooks if your code is non-compliant.

Hooks

Overview
RepositoryHookPurpose
pre-commit/pre-commit-hookscheck-astCheck whether files parse as valid python
check-merge-conflictCheck for files that contain merge conflict strings
check-case-conflictCheck for files with names that would conflict on a case-insensitive filesystem
check-jsonVerify syntax of all JSON files
check-tomlVerify syntax of all TOML files
check-yamlVerify syntax of all YAML files
trailing-whitespaceTrim trailing whitespace
mixed-line-endingReplaces or checks mixed line ending
detect-private-keyChecks for the existence of private keys
compilerla/conventional-pre-commitconventional-pre-commitA pre-commit hook to check commit messages for Conventional Commits formatting
ambv/blackblackPython code formatter
PyCQA/banditbanditA security linter designed to find common security issues in Python code
econchick/interrogateinterrogateCheck the code base for missing docstrings
hadialqattan/pyclnpyclnFinds and removes unused import statements
pycqa/isortisortSort imports alphabetically, and automatically separated into sections and by type
pre-commit/mirrors-prettierprettierTypeScript/JavaScript/JSON ++ code formatter
pre-commit/mirrors-eslinteslintHelps you find and fix problems in your JavaScript code
pycqa/flake8flake8Check the style and quality of Python code
localmypyPython type checker
pytestPython test runner

API

From inside the /api folder.

Create virtualenv

Virtual environment is used for running unit tests with pre-commit and upgrade packages. It also can be used to run the application if you not are using Docker.

python3 -m venv .venv

Activate virtualenv

source .venv/bin/activate

Install Poetry

Poetry is used to manage Python package dependencies.

$ pip install poetry
$ poetry config virtualenvs.create false # Not create venv

The installation instructions can be found here.

Install packages

$ poetry install

Web

From inside the /web folder.

Package management

This project uses Yarn 2 Plug'n'Play to manage web package dependencies. That means there is no need to run npm/yarn install. However, if you want to add/remove/update packages, you need yarn installed locally.

$ npm install -g yarn

Yarn PnP in Jetbrains IDEs

To let the IDE know that dependencies can be found in .yarn instead of node_modules, follow these steps; https://www.jetbrains.com/help/idea/installing-and-removing-external-software-using-node-package-manager.html#ws_npm_yarn_set_up_yarn2

Yarn PnP in VSCode

Because the project uses Yarn PnP, VSCode's language server must use the same typescript executable as the project in order to access dependencies. This is located in web/.yarn/sdks/typescript/lib. To use this version, simply open a .ts(x) file, open the command palette (default Ctrl+Shift+P or Cmd+Shift+P), find TypeScript: Select TypeScript Version... and select Use Workspace Version.

Not using the correct typescript executable might cause Cannot find module '***' or its corresponding type declarations. and JSX element implicitly has type 'any' because no interface 'JSX.IntrinsicElements' exists. errors.