diff --git a/.cmake-format b/.cmake-format
new file mode 100644
index 0000000000..8b28e7c9e2
--- /dev/null
+++ b/.cmake-format
@@ -0,0 +1,22 @@
+# ------------------------------------------------
+# Options affecting comment reflow and formatting.
+# ------------------------------------------------
+with section("markup"):
+ # If comment markup is enabled, don't reflow the first comment block in each
+ # listfile. Use this to preserve formatting of your copyright/license
+ # statements.
+ first_comment_is_literal = True
+
+# -----------------------------
+# Options affecting formatting.
+# -----------------------------
+with section("format"):
+ # If an argument group contains more than this many sub-groups (parg or kwarg
+ # groups) then force it to a vertical layout.
+ max_subgroups_hwrap = 12
+ # If a positional argument group contains more than this many arguments, then
+ # force it to a vertical layout.
+ max_pargs_hwrap = 12
+ # If a candidate layout is wrapped horizontally but it exceeds this many
+ # lines, then reject the layout.
+ max_lines_hwrap = 6
diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
index f2bde6a780..78a5a5d65a 100644
--- a/.pre-commit-config.yaml
+++ b/.pre-commit-config.yaml
@@ -1,10 +1,11 @@
fail_fast: false
+exclude: 'libs'
repos:
- repo: local
hooks:
- id: clang-format
name: clang-format
- entry: bash maintainer/CI/clang-format.sh
+ entry: sh maintainer/format/clang-format.sh
language: system
always_run: false
files: '.*\.(cpp|hpp|cu|cuh)'
@@ -12,8 +13,25 @@ repos:
- id: autopep8
name: autopep8
- entry: bash maintainer/CI/autopep8.sh
+ entry: sh maintainer/format/autopep8.sh
language: system
always_run: false
files: '.*\.(py|pyx|pxd)'
+ exclude: '\.pylintrc|.*.\.py\.in'
args: ["--ignore=E266,W291,W293", "--in-place", "--aggressive"]
+
+ - id: cmake-format
+ name: cmake-format
+ entry: sh maintainer/format/cmake-format.sh
+ language: system
+ always_run: false
+ files: 'CMakeLists.txt'
+ args: ["-i"]
+
+ - id: ex-flags
+ name: executable flags
+ entry: sh maintainer/format/ex_flag.sh
+ language: system
+ always_run: false
+ exclude: '.*\.(sh|py|sh\.in|cmakein)|.git'
+ types: [file, executable]
diff --git a/doc/logo/CMakeLists.txt b/doc/logo/CMakeLists.txt
index ded9cfb02f..e11fab3055 100644
--- a/doc/logo/CMakeLists.txt
+++ b/doc/logo/CMakeLists.txt
@@ -7,7 +7,7 @@ set(logo_FILES
)
-foreach(lf in logo_FILES)
+foreach(lf logo_FILES)
add_custom_command(OUTPUT ${lf}
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_CURRENT_SOURCE_DIR}/${lf} ${CMAKE_CURRENT_BINARY_DIR}
)
diff --git a/maintainer/CI/autopep8.sh b/maintainer/CI/autopep8.sh
deleted file mode 100644
index 79d7378587..0000000000
--- a/maintainer/CI/autopep8.sh
+++ /dev/null
@@ -1,19 +0,0 @@
-#!/bin/bash
-
-AUTOPEP8_VER=1.3.4
-PYCODESTYLE_VER=2.3.1
-
-if hash autopep8 2>/dev/null; then
- AUTOPEP8="$(which autopep8)"
-else
- echo "No autopep8 found."
- exit 2
-fi
-
-if ! "${AUTOPEP8}" --version 2>&1 | grep -qFo "autopep8 ${AUTOPEP8_VER} (pycodestyle: ${PYCODESTYLE_VER})"; then
- echo "Could not find autopep8 ${AUTOPEP8_VER} with pycodestyle ${PYCODESTYLE_VER}"
- echo "${AUTOPEP8} is $(${AUTOPEP8} --version 2>&1)"
- exit 2
-fi
-
-${AUTOPEP8} "$@"
diff --git a/maintainer/CI/clang-format.sh b/maintainer/CI/clang-format.sh
deleted file mode 100644
index e73b252858..0000000000
--- a/maintainer/CI/clang-format.sh
+++ /dev/null
@@ -1,19 +0,0 @@
-#!/bin/bash
-
-
-CLANG_FORMAT_VER=6.0
-if hash clang-format_${CLANG_FORMAT_VER} 2>/dev/null; then
- CLANGFORMAT="$(which clang-format-${CLANG_FORMAT_VER})"
-elif hash clang-format 2>/dev/null; then
- CLANGFORMAT="$(which clang-format)"
-else
- echo "No clang-format found."
- exit 2
-fi
-
-if ! "${CLANGFORMAT}" --version | grep -qEo "version ${CLANG_FORMAT_VER}\.[0-9]+"; then
- echo "Could not find clang-format ${CLANG_FORMAT_VER}. ${CLANGFORMAT} is $(${CLANGFORMAT} --version | grep -Eo '[0-9\.]{5}' | head -n 1)."
- exit 2
-fi
-
-${CLANGFORMAT} "$@"
diff --git a/maintainer/CI/fix_style.sh b/maintainer/CI/fix_style.sh
index 7e54a0b04a..eed04b88b9 100755
--- a/maintainer/CI/fix_style.sh
+++ b/maintainer/CI/fix_style.sh
@@ -1,5 +1,5 @@
#!/usr/bin/env sh
-# Copyright (C) 2018-2019 The ESPResSo project
+# Copyright (C) 2018-2020 The ESPResSo project
#
# This file is part of ESPResSo.
#
@@ -25,10 +25,12 @@ if ! git diff-index --quiet HEAD -- && [ "${1}" != "-f" ]; then
exit 1
fi
+if ! hash pre-commit 2>/dev/null; then
+ echo "pre-commit command not found."
+ exit 2
+fi
-find . \( -name '*.hpp' -o -name '*.cpp' -o -name '*.cu' -o -name '*.cuh' \) -not -path './libs/*' | xargs -n 5 -P 8 bash maintainer/CI/clang-format.sh -i -style=file || exit 3
-find . \( -name '*.py' -o -name '*.pyx' -o -name '*.pxd' \) -not -path './libs/*' | xargs -n 5 -P 8 bash maintainer/CI/autopep8.sh --ignore=E266,W291,W293 --in-place --aggressive || exit 3
-find . -type f -perm +111 ! -name '*.sh' ! -name '*.py' ! -name '*.sh.in' ! -name pypresso.cmakein -not -path './.git/*' | xargs -n 5 -P 8 chmod -x || exit 3
+pre-commit run --all-files
if [ "${CI}" != "" ]; then
git --no-pager diff > style.patch
diff --git a/maintainer/format/autopep8.sh b/maintainer/format/autopep8.sh
new file mode 100644
index 0000000000..b53b7a6e34
--- /dev/null
+++ b/maintainer/format/autopep8.sh
@@ -0,0 +1,36 @@
+#!/bin/sh
+# Copyright (C) 2018-2020 The ESPResSo project
+#
+# This file is part of ESPResSo.
+#
+# ESPResSo is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# ESPResSo is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see .
+
+
+AUTOPEP8_VER=1.3.4
+PYCODESTYLE_VER=2.3.1
+
+if hash autopep8 2>/dev/null; then
+ AUTOPEP8="$(which autopep8)"
+else
+ echo "No autopep8 found."
+ exit 2
+fi
+
+if ! "${AUTOPEP8}" --version 2>&1 | grep -qFo "autopep8 ${AUTOPEP8_VER} (pycodestyle: ${PYCODESTYLE_VER})"; then
+ echo "Could not find autopep8 ${AUTOPEP8_VER} with pycodestyle ${PYCODESTYLE_VER}"
+ echo "${AUTOPEP8} is $(${AUTOPEP8} --version 2>&1)"
+ exit 2
+fi
+
+${AUTOPEP8} "$@"
diff --git a/maintainer/format/clang-format.sh b/maintainer/format/clang-format.sh
new file mode 100644
index 0000000000..13d91bbacd
--- /dev/null
+++ b/maintainer/format/clang-format.sh
@@ -0,0 +1,36 @@
+#!/bin/sh
+# Copyright (C) 2018-2020 The ESPResSo project
+#
+# This file is part of ESPResSo.
+#
+# ESPResSo is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# ESPResSo is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see .
+
+
+
+CLANG_FORMAT_VER=6.0
+if hash clang-format_${CLANG_FORMAT_VER} 2>/dev/null; then
+ CLANGFORMAT="$(which clang-format-${CLANG_FORMAT_VER})"
+elif hash clang-format 2>/dev/null; then
+ CLANGFORMAT="$(which clang-format)"
+else
+ echo "No clang-format found."
+ exit 2
+fi
+
+if ! "${CLANGFORMAT}" --version | grep -qEo "version ${CLANG_FORMAT_VER}\.[0-9]+"; then
+ echo "Could not find clang-format ${CLANG_FORMAT_VER}. ${CLANGFORMAT} is $(${CLANGFORMAT} --version | grep -Eo '[0-9\.]{5}' | head -n 1)."
+ exit 2
+fi
+
+${CLANGFORMAT} "$@"
diff --git a/maintainer/format/cmake-format.sh b/maintainer/format/cmake-format.sh
new file mode 100644
index 0000000000..3a0e48f135
--- /dev/null
+++ b/maintainer/format/cmake-format.sh
@@ -0,0 +1,33 @@
+#!/bin/sh
+# Copyright (C) 2018-2020 The ESPResSo project
+#
+# This file is part of ESPResSo.
+#
+# ESPResSo is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# ESPResSo is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see .
+
+CMAKE_FORMAT_VER=0.6.9
+if hash cmake-format 2>/dev/null; then
+ CMAKE_FORMAT="$(which cmake-format)"
+else
+ echo "No cmake-format found."
+ exit 2
+fi
+
+
+if ! "${CMAKE_FORMAT}" --version | grep -qEo "${CMAKE_FORMAT_VER}"; then
+ echo "Could not find cmake-format ${CMAKE_FORMAT_VER}."
+ exit 2
+fi
+
+${CMAKE_FORMAT} "$@"
diff --git a/maintainer/format/ex_flag.sh b/maintainer/format/ex_flag.sh
new file mode 100644
index 0000000000..0836c3f150
--- /dev/null
+++ b/maintainer/format/ex_flag.sh
@@ -0,0 +1,20 @@
+#!/bin/sh
+# Copyright (C) 2018-2020 The ESPResSo project
+#
+# This file is part of ESPResSo.
+#
+# ESPResSo is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# ESPResSo is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see .
+
+
+chmod -x "$@"
diff --git a/maintainer/header_template.txt b/maintainer/header_template.txt
index 93111efd49..7ecabd6064 100644
--- a/maintainer/header_template.txt
+++ b/maintainer/header_template.txt
@@ -1,4 +1,4 @@
-Copyright (C) 2010-2019 The ESPResSo project
+Copyright (C) 2010-2020 The ESPResSo project
This file is part of ESPResSo.
diff --git a/requirements.txt b/requirements.txt
index 6ee6a1e1f5..785bbb22bf 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -28,3 +28,5 @@ pylint>=2.2.2
astroid>=2.1.0
isort>=4.3.4
setuptools>=20.7.0
+pre-commit>=2.2.0
+cmake-format==0.6.9
diff --git a/src/core/unit_tests/CMakeLists.txt b/src/core/unit_tests/CMakeLists.txt
index 181964d6a5..ada4b606d0 100644
--- a/src/core/unit_tests/CMakeLists.txt
+++ b/src/core/unit_tests/CMakeLists.txt
@@ -1,19 +1,19 @@
# Copyright (C) 2010-2019 The ESPResSo project
# Copyright (C) 2002,2003,2004,2005,2006,2007,2008,2009,2010
# Max-Planck-Institute for Polymer Research, Theory Group
-
+#
# This file is part of ESPResSo.
-
+#
# ESPResSo is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
-
+#
# ESPResSo is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
-
+#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see .