Skip to content

Commit

Permalink
ENH: Add pre-commit
Browse files Browse the repository at this point in the history
  • Loading branch information
snowman2 committed Aug 12, 2022
1 parent d5de38a commit 80526c8
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 82 deletions.
21 changes: 21 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -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
18 changes: 4 additions & 14 deletions .github/workflows/code_checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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/[email protected]

doxygen:
runs-on: ubuntu-18.04
Expand Down
3 changes: 3 additions & 0 deletions .isort.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[settings]
known_first_party=osgeo,osgeo_utils
profile=black
29 changes: 29 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -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/
)
8 changes: 8 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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**
Expand Down
2 changes: 0 additions & 2 deletions autotest/pyscripts/setup.cfg

This file was deleted.

60 changes: 0 additions & 60 deletions autotest/setup.cfg

This file was deleted.

7 changes: 1 addition & 6 deletions ci/travis/trusty_clang/before_install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 80526c8

Please sign in to comment.