Skip to content

Commit

Permalink
feat: add pre-commit
Browse files Browse the repository at this point in the history
  • Loading branch information
gadomski committed Apr 6, 2022
1 parent ac0afcc commit 43b51c7
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 9 deletions.
6 changes: 6 additions & 0 deletions .github/setup/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ runs:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ inputs.pip-cache-hash }}
restore-keys: ${{ runner.os }}-pip-
- name: Set up pre-commit cache
uses: actions/cache@v2
with:
path: ~/.cache/pre-commit
key: ${{ runner.os }}-pre-commit-${{ hashFiles('.pre-commit-config.yaml' )}}
restore-keys: ${{ runner.os }}-pre-commit-
- name: Set up Conda with Python ${{ inputs.python-version }}
uses: conda-incubator/setup-miniconda@v2
with:
Expand Down
2 changes: 2 additions & 0 deletions .isort.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[settings]
profile = black
42 changes: 42 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Configuration file for pre-commit (https://pre-commit.com/).
# Please run `pre-commit run --all-files` when adding or changing entries.

repos:
- repo: https://github.com/psf/black
rev: 22.3.0
hooks:
- id: black
- repo: https://github.com/codespell-project/codespell
rev: v2.1.0
hooks:
- id: codespell
args: [--ignore-words=.codespellignore]
types_or: [jupyter, markdown, python, shell]
- repo: https://github.com/PyCQA/doc8
rev: 0.11.1
hooks:
- id: doc8
- repo: https://github.com/PyCQA/flake8
rev: 4.0.1
hooks:
- id: flake8
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v0.942
hooks:
- id: mypy
# TODO lint test and scripts too
files: "^src/.*\\.py$"
args:
- --ignore-missing-imports
- --explicit-package-bases
additional_dependencies:
- click != 8.1.0
- numpy
- pyproj
- pystac
- types-requests
- repo: https://github.com/pycqa/isort
rev: 5.10.1
hooks:
- id: isort
name: isort (python)
1 change: 1 addition & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ RUN conda install -c conda-forge pandoc && conda clean -af
COPY requirements-dev.txt ./
RUN pip install -r requirements-dev.txt
COPY . ./
RUN git init
RUN pip install -e .[all]


Expand Down
1 change: 1 addition & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ lxml-stubs
mypy
nbsphinx
packaging
pre-commit
pylint
pytest
pytest-cov
Expand Down
4 changes: 1 addition & 3 deletions scripts/format
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,11 @@ Format code with black
"
}

DIRS_TO_CHECK=("src" "tests")

if [ "${BASH_SOURCE[0]}" = "${0}" ]; then
if [ "${1:-}" = "--help" ]; then
usage
else
# Code formatting
black ${DIRS_TO_CHECK[@]}
pre-commit run black --all-files
fi
fi
7 changes: 1 addition & 6 deletions scripts/lint
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,6 @@ if [ "${BASH_SOURCE[0]}" = "${0}" ]; then
if [ "${1:-}" = "--help" ]; then
usage
else
# Code formatting
scripts/format
# Lint
flake8 ${DIRS_TO_CHECK[@]}
# Type checking
mypy --install-types --non-interactive src
pre-commit run --all-files
fi
fi

0 comments on commit 43b51c7

Please sign in to comment.