From d3ee34abba338ee547db8a745b150ce6269f4118 Mon Sep 17 00:00:00 2001
From: Benjamin Bertrand <benjamin.bertrand@ess.eu>
Date: Thu, 12 Mar 2020 09:21:27 +0100
Subject: [PATCH] Add pre-commit hooks

Automatically run:
- black
- flake8

See https://pre-commit.com
---
 .flake8                 | 4 ++++
 .gitlab-ci.yml          | 4 ++++
 .pre-commit-config.yaml | 9 +++++++++
 README.md               | 7 +++++++
 4 files changed, 24 insertions(+)
 create mode 100644 .flake8
 create mode 100644 .pre-commit-config.yaml

diff --git a/.flake8 b/.flake8
new file mode 100644
index 0000000..a9b2cc9
--- /dev/null
+++ b/.flake8
@@ -0,0 +1,4 @@
+[flake8]
+# E501: let black handle line length
+# W503 is incompatible with PEP 8
+ignore = E501,W503
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 87875d2..c11fcde 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -1,11 +1,15 @@
 image: docker:latest
+include:
+  - "https://gitlab.esss.lu.se/ics-infrastructure/gitlab-ci-yml/raw/master/PreCommit.gitlab-ci.yml"
 
 variables:
   NGINX_IMAGE: "$CI_REGISTRY_IMAGE/nginx"
   PYTHON_SERVER_IMAGE: "$CI_REGISTRY_IMAGE/python-server"
 
 stages:
+  - check
   - build
+  - test
   - release
   - deploy
 
diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
new file mode 100644
index 0000000..c87086f
--- /dev/null
+++ b/.pre-commit-config.yaml
@@ -0,0 +1,9 @@
+repos:
+  - repo: https://github.com/ambv/black
+    rev: 19.10b0
+    hooks:
+      - id: black
+  - repo: https://github.com/pre-commit/pre-commit-hooks
+    rev: v2.4.0
+    hooks:
+      - id: flake8
diff --git a/README.md b/README.md
index 9e42685..917e622 100644
--- a/README.md
+++ b/README.md
@@ -8,6 +8,13 @@ This repository contains the structure to create the public opi screens running
 If you want to contribute to the screens the sequence is the following:
 
 - Install Docker on your computer and clone the git archive
+- Install pre-commit: https://pre-commit.com
+- Install the git hook scripts (only required the first time you clone the repo):
+
+  ```
+  pre-commit install
+  ```
+
 - Build the docker images with
 ```
 docker-compose build
-- 
GitLab