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
| Repository | Hook | Purpose | |-------------------------------------------------------------------------------------|-------------------------|------------------------------------------------------------------------------------| | [pre-commit/pre-commit-hooks](https://github.com/pre-commit/pre-commit-hooks) | check-ast | Check whether files parse as valid python | | | check-merge-conflict | Check for files that contain merge conflict strings | | | check-case-conflict | Check for files with names that would conflict on a case-insensitive filesystem | | | check-json | Verify syntax of all JSON files | | | check-toml | Verify syntax of all TOML files | | | check-yaml | Verify syntax of all YAML files | | | trailing-whitespace | Trim trailing whitespace | | | mixed-line-ending | Replaces or checks mixed line ending | | | detect-private-key | Checks for the existence of private keys | | [compilerla/conventional-pre-commit](https://github.com/compilerla/conventional-pre-commit) | conventional-pre-commit | A pre-commit hook to check commit messages for Conventional Commits formatting | | [ambv/black](https://github.com/ambv/black) | black | Python code formatter | | [PyCQA/bandit](https://github.com/PyCQA/bandit) | bandit | A security linter designed to find common security issues in Python code | | [econchick/interrogate](https://github.com/econchick/interrogate) | interrogate | Check the code base for missing docstrings | | [hadialqattan/pycln](https://github.com/hadialqattan/pycln) | pycln | Finds and removes unused import statements | | [pycqa/isort](https://github.com/pycqa/isort) | isort | Sort imports alphabetically, and automatically separated into sections and by type | | [pre-commit/mirrors-prettier](https://github.com/pre-commit/mirrors-prettier) | prettier | TypeScript/JavaScript/JSON ++ code formatter | | [pre-commit/mirrors-eslint](https://github.com/pre-commit/mirrors-eslint) | eslint | Helps you find and fix problems in your JavaScript code | | [pycqa/flake8](https://gitlab.com/pycqa/flake8) | flake8 | Check the style and quality of Python code | | [local](https://github.com/equinor/template-fastapi-react/blob/main/.pre-commit-config.yaml) | mypy | Python type checker | | | pytest | Python test runner | | | | |API¶
From inside the /api folder.
Install uv¶
uv is used to manage Python package dependencies.
$ pip install uv
The installation instructions can be found here.
Install packages¶
$ uv sync --dev
Web¶
From inside the /web folder.
Package management¶
This project uses Yarn 2 Plug'n'Play to manage web package dependencies.
After cloning or switching branches, you need to run yarn install to generate the PnP resolution files.
cd web
corepack enable
yarn install
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.