Skip to content

Commit

Permalink
More CI (mypy, coverage), setup pre-commit, formatting (#24)
Browse files Browse the repository at this point in the history
* add pre-commit config file

* clang format tweaks

* run black

* ci: add mypy gha workflow

* add pre-commit note in README

* fix mypy gha job

* fix trailing whitespace

* configure mypy

* use micromamba gha for tests

* fix tests gha

* typo

* enable coverage

* try fix codecov upload

* add coverage badge in README
  • Loading branch information
benbovy committed Mar 14, 2023
1 parent eb437b6 commit e874e60
Show file tree
Hide file tree
Showing 14 changed files with 239 additions and 137 deletions.
7 changes: 7 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
---
Language: Cpp
BasedOnStyle: Google
ColumnLimit: 100
TabWidth: 4
IndentWidth: 4
PointerAlignment: Left
ReferenceAlignment: Pointer
IndentAccessModifiers: false
AccessModifierOffset: -4
BinPackArguments: false
BinPackParameters: false
ExperimentalAutoDetectBinPacking: false
AllowAllParametersOfDeclarationOnNextLine: false
AllowShortFunctionsOnASingleLine: Empty
AllowShortLambdasOnASingleLine: Inline
...
39 changes: 39 additions & 0 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
on:
push:
branches: [main]
pull_request:
branches: [main]

name: Lint

jobs:
lint:
name: mypy
runs-on: ubuntu-latest
defaults:
run:
shell: bash -l {0}

steps:
- name: Checkout repo
uses: actions/checkout@v3

- name: Setup micromamba
uses: mamba-org/provision-with-micromamba@v15
with:
environment-file: ci/environment.yml
environment-name: spherely-dev
extra-specs: |
python=3.11
- name: Build and install spherely
run: |
python -m pip install . -v --no-build-isolation
- name: Install mypy
run: |
python -m pip install 'mypy<0.990'
- name: Run mypy
run: |
python -m mypy --install-types --non-interactive
72 changes: 31 additions & 41 deletions .github/workflows/run-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ jobs:
test:
name: ${{ matrix.os }}, ${{ matrix.python-version }}, ${{ matrix.env }}
runs-on: ${{ matrix.os }}
defaults:
run:
shell: bash -l {0}
strategy:
fail-fast: false
matrix:
Expand All @@ -36,41 +39,20 @@ jobs:
- name: Checkout repo
uses: actions/checkout@v3

- name: Setup mambaforge
uses: conda-incubator/setup-miniconda@v2
with:
miniforge-variant: Mambaforge
miniforge-version: latest
activate-environment: spherely-dev
use-mamba: true
python-version: ${{ matrix.python-version }}
environment-file: ${{ matrix.env }}

- name: Get Date
id: get-date
shell: bash -l {0}
# cache will last one day
run: echo "::set-output name=today::$(/bin/date -u '+%Y%m%d')"

- name: Cache environment
uses: actions/cache@v2
- name: Setup micromamba
uses: mamba-org/provision-with-micromamba@v15
with:
path: ${{ env.CONDA }}/envs
key: ${{ runner.os }}-{{ matrix.python-version }}-conda-${{ hashFiles( matrix.env ) }}-${{ steps.get-date.outputs.today }}-${{ env.CACHE_NUMBER }}
env:
# Increase this value to reset cache if ci/environment.yml has not changed
CACHE_NUMBER: 0
id: conda-cache

- name: Update environment
run: mamba env update -n spherely-dev -f ${{ matrix.env }}
if: steps.conda-cache.outputs.cache-hit != 'true'

- name: Conda info
shell: bash -l {0}
run: |
conda info
conda list
environment-file: ${{ matrix.env }}
environment-name: spherely-dev
cache-env: true
cache-env-key: "${{ runner.os }}-${{ runner.arch }}-py${{ matrix.python-version }}-${{ steps.get-date.outputs.today }}-${{ hashFiles( matrix.env) }}"
extra-specs: |
python=${{ matrix.python-version }}
- name: Fetch s2geography
uses: actions/checkout@v3
Expand All @@ -80,11 +62,9 @@ jobs:
path: deps/s2geography
fetch-depth: 0
if: |
matrix.dev == true &&
steps.conda-cache.outputs.cache-hit != 'true'
matrix.dev == true
- name: Configure, build & install s2geography (unix)
shell: bash -l {0}
run: |
cd deps/s2geography
cmake -S . -B build \
Expand All @@ -96,11 +76,9 @@ jobs:
cmake --install build
if: |
matrix.dev == true &&
(steps.conda-cache.outputs.cache-hit != 'true' &&
(runner.os == 'Linux' || runner.os == 'macOS'))
(runner.os == 'Linux' || runner.os == 'macOS')
- name: Configure, build & install s2geography (win)
shell: bash -l {0}
run: |
cd deps/s2geography
cmake -S . -B build \
Expand All @@ -111,15 +89,27 @@ jobs:
cmake --build build --config Release
cmake --install build
if: |
matrix.dev == true &&
(steps.conda-cache.outputs.cache-hit != 'true' &&
runner.os == 'Windows')
matrix.dev == true && runner.os == 'Windows'
- name: Build and install spherely
shell: bash -l {0}
run: python -m pip install . -v --no-build-isolation
run: |
python -m pip install . -v --no-build-isolation --config-settings cmake.define.SPHERELY_CODE_COVERAGE=ON --config-settings build-dir=_skbuild
- name: Run tests
shell: bash -l {0}
run: |
pytest . -vv
- name: Generate coverage report
run: |
python -m pip install gcovr
gcovr --exclude-unreachable-branches --print-summary -x -o coverage.xml
if: |
runner.os == 'Linux' && matrix.python-version == '3.11' && matrix.dev == false
- name: Upload coverage report
uses: codecov/codecov-action@v3
with:
files: ./coverage.xml
verbose: true
if: |
runner.os == 'Linux' && matrix.python-version == '3.11' && matrix.dev == false
22 changes: 22 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: debug-statements
- id: mixed-line-ending
- repo: https://github.com/psf/black
rev: 23.1.0
hooks:
- id: black
args: [--safe, --quiet]
- repo: https://github.com/pre-commit/mirrors-clang-format
rev: v15.0.7
hooks:
- id: clang-format
args: [--style=file]

ci:
autofix_prs: false
13 changes: 13 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ project(
set(CMAKE_CXX_STANDARD 17 CACHE STRING "The C++ standard to build with")
set(CMAKE_CXX_STANDARD_REQUIRED ON)

option(SPHERELY_CODE_COVERAGE "Enable coverage reporting" OFF)

# Dependencies

list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/third_party/cmake")
Expand All @@ -25,6 +27,11 @@ set(S2GEOGRAPHY_ROOT_DIR "$ENV{CONDA_PREFIX}")
find_package(s2 REQUIRED)
find_package(s2geography REQUIRED)

if(SPHERELY_CODE_COVERAGE)
message(STATUS "Building spherely with coverage enabled")
add_library(coverage_config INTERFACE)
endif()

# Compile definitions and flags

if (MSVC)
Expand Down Expand Up @@ -72,6 +79,12 @@ endif()

set_target_properties(spherely PROPERTIES CXX_VISIBILITY_PRESET "hidden")

if (SPHERELY_CODE_COVERAGE)
target_compile_options(coverage_config INTERFACE -O0 -g --coverage)
target_link_options(coverage_config INTERFACE --coverage)
target_link_libraries(spherely PUBLIC coverage_config)
endif()

# Install

install(TARGETS spherely LIBRARY DESTINATION .)
Expand Down
13 changes: 12 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

![Tests](https://github.com/benbovy/spherely/actions/workflows/run-tests.yaml/badge.svg)
[![Docs](https://readthedocs.org/projects/spherely/badge/?version=latest)](https://spherely.readthedocs.io)
[![Coverage](https://codecov.io/gh/benbovy/spherely/branch/main/graph/badge.svg)](https://app.codecov.io/gh/benbovy/spherely?branch=main)

*Python library for manipulation and analysis of geometric objects on the sphere.*

Expand Down Expand Up @@ -67,7 +68,17 @@ Run the tests:
$ pytest . -v
```

## Using the latest s2geography
Spherely also uses [pre-commit](https://pre-commit.com/) for code
auto-formatting and linting at every commit. After installing it, you can enable
pre-commit hooks with the following command:

```
$ pre-commit install
```

(Note: you can skip the pre-commit checks with `git commit --no-verify`)

## Using the latest s2geography version

If you want to compile spherely against the latest version of s2geography, use:

Expand Down
2 changes: 1 addition & 1 deletion docs/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,4 @@ Predicates
intersects
contains
within
disjoint
disjoint
5 changes: 5 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,8 @@ Repository = "https://github.com/benbovy/spherely"

[project.optional-dependencies]
test = ["pytest>=6.0"]

[tool.mypy]
files = ["tests", "src/spherely.pyi"]
show_error_codes = true
warn_unused_ignores = true
Loading

0 comments on commit e874e60

Please sign in to comment.