ENH: Add pre-commit

This commit is contained in:
snowman2 2022-08-11 20:42:52 -05:00
parent d5de38a5bb
commit 80526c82d9
8 changed files with 66 additions and 82 deletions

21
.flake8 Normal file
View File

@ -0,0 +1,21 @@
[flake8]
max_line_length = 88
ignore =
C408 # Unnecessary dict/list/tuple call - rewrite as a literal
E203 # whitespace before ':' - doesn't work well with black
E225 # missing whitespace around operator - let black worry about that
E262 # inline comment should start with '# '
E265 # block comment should start with '# '
E266 # too many leading '#' for block comment
E302 # expected 2 blank lines, found 1
E402 # module level import not at top of file
E501 # line too long - let black handle that
E711 # comparison to None should be
E712 # comparison to False/True should be
E741 # ambiguous variable name
F405 # may be undefined, or defined from star imports
W291 # trailing
W503 # line break occurred before a binary operator - let black worry about that
W504 # line break occurred adter a binary operator - let black worry about that
per-file-ignores =
.cmake-format.py:F821

View File

@ -63,22 +63,12 @@ jobs:
- name: Shellcheck
run: shellcheck -e SC2086,SC2046,SC2164,SC2054 $(find . -name '*.sh' -a -not -name ltmain.sh -a -not -wholename "./autotest/*" -a -not -wholename "./.github/*")
flake8:
linting:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Install Requirements
run: |
sudo apt install python3-pip
sudo pip3 install flake8
- name: Run flake8
run: |
export FLAKE8="flake8 --config autotest/setup.cfg"
$FLAKE8 autotest
$FLAKE8 swig/python/gdal-utils/
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
- uses: pre-commit/action@v2.0.0
doxygen:
runs-on: ubuntu-18.04

3
.isort.cfg Normal file
View File

@ -0,0 +1,3 @@
[settings]
known_first_party=osgeo,osgeo_utils
profile=black

29
.pre-commit-config.yaml Normal file
View File

@ -0,0 +1,29 @@
repos:
- repo: https://github.com/psf/black
rev: 22.3.0
hooks:
- id: black
exclude: >
(?x)^(
swig/python/osgeo/|
autotest/ogr/data/
)
- repo: https://github.com/timothycrosley/isort
rev: 5.10.1
hooks:
- id: isort
exclude: >
(?x)^(
swig/python/osgeo/|
autotest/ogr/data/
)
- repo: https://gitlab.com/pycqa/flake8
rev: 3.9.2
hooks:
- id: flake8
exclude: >
(?x)^(
swig/python/osgeo/|
examples/|
autotest/ogr/data/
)

View File

@ -44,6 +44,14 @@ python -m venv gdal_venv
python -m pip install numpy
```
Setup pre-commit:
```bash
python -m pip install pre-commit
pre-commit install
```
Configure and build:
> **Note**

View File

@ -1,2 +0,0 @@
[flake8]
max-line-length=100

View File

@ -1,60 +0,0 @@
[flake8]
ignore =
E101 # Indentation contains mised spaces and tabs
E111 # Indentation is not a multiple of 4
E114 # Indentation is not a multiple of 4 (comment)
E115 # Expected an indented block (comment)
E117 # Over-indented comment
E121 # Continuation line under-indented for hanging indent
E122 # Continuation line missing indentation or outdented
E123 # Closing bracket does not match indentation of opening bracket
E124 # Closing bracket does not match visual indentation
E125 # Continuation line with same indent as next logical line
E126 # Continuation line over-indented for hanging indent
E127 # Continuation line over-indented
E128 # Continuation line under-indented
E131 # Continuation line unaligned for handing indent
E201 # Whitespace after bracket
E202 # Whitespace before bracket
E203 # Whitespace before ','
E211 # Whitespace before bracket
E221 # Multiple spaces before operator
E222 # Multiple spaces after operator
E225 # Missing whitespace around operator
E226 # Missing whitespace around arithmetic operator
E227 # Missing whitespace around bitwise or shift operator
E228 # Missing whitespace around modulo operator
E231 # Missing whitespace after ','
E241 # Multiple spaces after ','
E251 # Unexpected spaces around keyword equals
E252 # Missing whitespace around parameter equals
E261 # At least two spaces before inline comment
E262 # Inline comment should start with '# '
E265 # Block comment should start with '# '
E266 # Too many leading '#' for block comment
E271 # Multiple spaces after keyword
E301 # Expected 1 blank line, found 0
E302 # Expected 2 blank lines, found 1
E303 # too many blank lines
E305 # Expected 2 blank lines after class or function definition
E306 # Expected 1 blank line before a nested definition
E402 # Module level import not at top of file
E501 # Line too long
E502 # Backslash is redundant between brackets
E703 # Statement ends with a semicolon
E711 # Comparison to None should be 'if cond is None'
E712 # Comparison to False should be 'if cond is False' or 'if not cond'
E713 # Test for membership should be 'not in'
E721 # Do not compare types, use isinstance()
E722 # Do not use bare 'except'
E731 # Do not assign a lambda expression, use a def
E741 # Ambiguous variable name 'l'
E291 # Trailing whitespace
W191 # Indentation contains tabs
W291 # Trailing whitespace
W292 # No newline at end of file
W293 # Blank line contains whitespace
W391 # Blank line at end of file
W503 # Line break before binary operator
W504 # Line break after binary operator
W605 # Invalid escape sequence

View File

@ -17,7 +17,7 @@ sudo apt-get install python3.5-dev
curl -sSL 'https://bootstrap.pypa.io/get-pip.py' | sudo python3.5
(cd autotest; sudo -H pip install -U -r ./requirements.txt)
sudo pip install lxml flake8 numpy
sudo pip install lxml numpy
# MSSQL: server side
docker pull mcr.microsoft.com/mssql/server:2017-latest
@ -33,11 +33,6 @@ sudo apt-get install -y libogdi3.2-dev
#sudo apt-get install -y libboost-regex-dev libboost-system-dev libboost-thread-dev
sudo apt-get install doxygen texlive-latex-base
# flake8 codes to just emulate pyflakes (http://flake8.pycqa.org/en/latest/user/error-codes.html)
FLAKE8="flake8 --select=F401,F402,F403,F404,F405,F406,F407,F601,F602,F621,F622,F631,F632,F633,F701,F702,F703,F704,F705,F706,F707,F721,F722,F811,F812,F821,F822,F823,F831,F841,F901"
$FLAKE8 autotest
$FLAKE8 gdal/swig/python/gdal-utils/scripts
$FLAKE8 gdal/swig/python/gdal-utils/osgeo_utils/samples
psql -c "drop database if exists autotest" -U postgres
psql -c "create database autotest" -U postgres
psql -c "create extension postgis" -d autotest -U postgres