diff --git a/.github/setup/action.yml b/.github/setup/action.yml index 397aa86b..e965e3fe 100644 --- a/.github/setup/action.yml +++ b/.github/setup/action.yml @@ -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: diff --git a/.isort.cfg b/.isort.cfg new file mode 100644 index 00000000..f238bf7e --- /dev/null +++ b/.isort.cfg @@ -0,0 +1,2 @@ +[settings] +profile = black diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 00000000..b65e3379 --- /dev/null +++ b/.pre-commit-config.yaml @@ -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) diff --git a/docker/Dockerfile b/docker/Dockerfile index 499351a9..2b8df342 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -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] diff --git a/requirements-dev.txt b/requirements-dev.txt index 3149c9ed..511329f8 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -8,6 +8,7 @@ lxml-stubs mypy nbsphinx packaging +pre-commit pylint pytest pytest-cov diff --git a/scripts/format b/scripts/format index a19da7e5..28dc87f8 100755 --- a/scripts/format +++ b/scripts/format @@ -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 diff --git a/scripts/lint b/scripts/lint index 4eeeef42..1216871a 100755 --- a/scripts/lint +++ b/scripts/lint @@ -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