Skip to content

Commit

Permalink
dont require precommit for proper formatting (valhalla#3961)
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinkreiser authored Feb 11, 2023
1 parent 8e5a451 commit 0e8a12e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 32 deletions.
26 changes: 1 addition & 25 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,33 +1,9 @@
repos:
# C++
# liniting c++ and python
- repo: local
hooks:
- id: format
name: format
entry: bash ./scripts/format.sh
language: system
pass_filenames: false

# Python formatter
- repo: https://github.com/psf/black
rev: 22.10.0
hooks:
- id: black
language_version: python3
args: ['--line-length=105', '--skip-string-normalization']
files: ^(src/bindings/python/|scripts/)

# Python linter
- repo: https://github.com/pycqa/flake8
rev: 5.0.4
hooks:
- id: flake8
# E501: ignore line length (black auto-formats)
# E731: ignore replace-lambda-with-def warnings
# E203: ignore "whitespace before ':'"
args: [
'--max-line-length=105',
'--extend-ignore=E501,E731,E203',
'--extend-exclude=src/bindings/python/__init__.py'
]
files: ^(src/bindings/python/|scripts/)
9 changes: 3 additions & 6 deletions scripts/bash_utils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,15 @@ function setup_mason {

}

function setup_pre_commit {
function setup_python {
local python_bin=""
if [[ $(command -v python3) != "" ]]; then
python_bin="python3"
elif [[ $(command -v python) != "" ]]; then
python_bin="python"
else
echo "WARNING: install python3 to set up pre-commit hooks."
echo "WARNING: install python3 for linting" 1>&2
return
fi
echo "INFO: Installing pre-commit"
${python_bin} -m pip install --user --upgrade pre-commit
echo "INFO: Setting up pre-commit hooks"
${python_bin} -m pre_commit install
echo ${python_bin}
}
13 changes: 12 additions & 1 deletion scripts/format.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ readonly CLANG_FORMAT_VERSION=11.0.0

source scripts/bash_utils.sh
setup_mason
setup_pre_commit

./mason/mason install clang-format $CLANG_FORMAT_VERSION
./mason/mason link clang-format $CLANG_FORMAT_VERSION
Expand All @@ -22,3 +21,15 @@ echo "Using clang-format $CLANG_FORMAT_VERSION from ${CLANG_FORMAT}"

find src valhalla test bench -type f -name '*.h' -o -name '*.cc' \
| xargs -I{} -P ${NPROC} ${CLANG_FORMAT} -i -style=file {}


# Python setup
py=$(setup_python)
${py} -m pip install black==22.10.0 flake8==5.0.4
python_sources=$(LANG=C find scripts src/bindings/python -type f -exec file {} \; | grep -F "Python script" | sed 's/:.*//')

# Python formatter
${py} -m black --line-length=105 --skip-string-normalization ${python_sources}

# Python linter
${py} -m flake8 --max-line-length=105 --extend-ignore=E501,E731,E203 --extend-exclude=src/bindings/python/__init__.py ${python_sources}

0 comments on commit 0e8a12e

Please sign in to comment.