Skip to content

Commit

Permalink
maintainer: added cmake-format check.
Browse files Browse the repository at this point in the history
  • Loading branch information
KaiSzuttor committed Apr 2, 2020
1 parent 0c8a23e commit 8f54b3e
Show file tree
Hide file tree
Showing 13 changed files with 181 additions and 50 deletions.
22 changes: 22 additions & 0 deletions .cmake-format
Original file line number Diff line number Diff line change
@@ -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
22 changes: 20 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,19 +1,37 @@
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)'
args: ["-i", "-style=file"]

- 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]
2 changes: 1 addition & 1 deletion doc/logo/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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}
)
Expand Down
19 changes: 0 additions & 19 deletions maintainer/CI/autopep8.sh

This file was deleted.

19 changes: 0 additions & 19 deletions maintainer/CI/clang-format.sh

This file was deleted.

10 changes: 6 additions & 4 deletions maintainer/CI/fix_style.sh
Original file line number Diff line number Diff line change
@@ -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.
#
Expand All @@ -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
Expand Down
36 changes: 36 additions & 0 deletions maintainer/format/autopep8.sh
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.


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} "$@"
36 changes: 36 additions & 0 deletions maintainer/format/clang-format.sh
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.



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} "$@"
33 changes: 33 additions & 0 deletions maintainer/format/cmake-format.sh
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.

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} "$@"
20 changes: 20 additions & 0 deletions maintainer/format/ex_flag.sh
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.


chmod -x "$@"
2 changes: 1 addition & 1 deletion maintainer/header_template.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (C) 2010-2019 The ESPResSo project
Copyright (C) 2010-2020 The ESPResSo project

This file is part of ESPResSo.

Expand Down
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
8 changes: 4 additions & 4 deletions src/core/unit_tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.

Expand Down

0 comments on commit 8f54b3e

Please sign in to comment.