Skip to content

Commit e874e60

Browse files
authored
More CI (mypy, coverage), setup pre-commit, formatting (#24)
* 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
1 parent eb437b6 commit e874e60

14 files changed

+239
-137
lines changed

.clang-format

+7
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
11
---
22
Language: Cpp
33
BasedOnStyle: Google
4+
ColumnLimit: 100
45
TabWidth: 4
56
IndentWidth: 4
67
PointerAlignment: Left
78
ReferenceAlignment: Pointer
89
IndentAccessModifiers: false
910
AccessModifierOffset: -4
11+
BinPackArguments: false
12+
BinPackParameters: false
13+
ExperimentalAutoDetectBinPacking: false
14+
AllowAllParametersOfDeclarationOnNextLine: false
15+
AllowShortFunctionsOnASingleLine: Empty
16+
AllowShortLambdasOnASingleLine: Inline
1017
...

.github/workflows/lint.yaml

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
on:
2+
push:
3+
branches: [main]
4+
pull_request:
5+
branches: [main]
6+
7+
name: Lint
8+
9+
jobs:
10+
lint:
11+
name: mypy
12+
runs-on: ubuntu-latest
13+
defaults:
14+
run:
15+
shell: bash -l {0}
16+
17+
steps:
18+
- name: Checkout repo
19+
uses: actions/checkout@v3
20+
21+
- name: Setup micromamba
22+
uses: mamba-org/provision-with-micromamba@v15
23+
with:
24+
environment-file: ci/environment.yml
25+
environment-name: spherely-dev
26+
extra-specs: |
27+
python=3.11
28+
29+
- name: Build and install spherely
30+
run: |
31+
python -m pip install . -v --no-build-isolation
32+
33+
- name: Install mypy
34+
run: |
35+
python -m pip install 'mypy<0.990'
36+
37+
- name: Run mypy
38+
run: |
39+
python -m mypy --install-types --non-interactive

.github/workflows/run-tests.yaml

+31-41
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ jobs:
1010
test:
1111
name: ${{ matrix.os }}, ${{ matrix.python-version }}, ${{ matrix.env }}
1212
runs-on: ${{ matrix.os }}
13+
defaults:
14+
run:
15+
shell: bash -l {0}
1316
strategy:
1417
fail-fast: false
1518
matrix:
@@ -36,41 +39,20 @@ jobs:
3639
- name: Checkout repo
3740
uses: actions/checkout@v3
3841

39-
- name: Setup mambaforge
40-
uses: conda-incubator/setup-miniconda@v2
41-
with:
42-
miniforge-variant: Mambaforge
43-
miniforge-version: latest
44-
activate-environment: spherely-dev
45-
use-mamba: true
46-
python-version: ${{ matrix.python-version }}
47-
environment-file: ${{ matrix.env }}
48-
4942
- name: Get Date
5043
id: get-date
51-
shell: bash -l {0}
5244
# cache will last one day
5345
run: echo "::set-output name=today::$(/bin/date -u '+%Y%m%d')"
5446

55-
- name: Cache environment
56-
uses: actions/cache@v2
47+
- name: Setup micromamba
48+
uses: mamba-org/provision-with-micromamba@v15
5749
with:
58-
path: ${{ env.CONDA }}/envs
59-
key: ${{ runner.os }}-{{ matrix.python-version }}-conda-${{ hashFiles( matrix.env ) }}-${{ steps.get-date.outputs.today }}-${{ env.CACHE_NUMBER }}
60-
env:
61-
# Increase this value to reset cache if ci/environment.yml has not changed
62-
CACHE_NUMBER: 0
63-
id: conda-cache
64-
65-
- name: Update environment
66-
run: mamba env update -n spherely-dev -f ${{ matrix.env }}
67-
if: steps.conda-cache.outputs.cache-hit != 'true'
68-
69-
- name: Conda info
70-
shell: bash -l {0}
71-
run: |
72-
conda info
73-
conda list
50+
environment-file: ${{ matrix.env }}
51+
environment-name: spherely-dev
52+
cache-env: true
53+
cache-env-key: "${{ runner.os }}-${{ runner.arch }}-py${{ matrix.python-version }}-${{ steps.get-date.outputs.today }}-${{ hashFiles( matrix.env) }}"
54+
extra-specs: |
55+
python=${{ matrix.python-version }}
7456
7557
- name: Fetch s2geography
7658
uses: actions/checkout@v3
@@ -80,11 +62,9 @@ jobs:
8062
path: deps/s2geography
8163
fetch-depth: 0
8264
if: |
83-
matrix.dev == true &&
84-
steps.conda-cache.outputs.cache-hit != 'true'
65+
matrix.dev == true
8566
8667
- name: Configure, build & install s2geography (unix)
87-
shell: bash -l {0}
8868
run: |
8969
cd deps/s2geography
9070
cmake -S . -B build \
@@ -96,11 +76,9 @@ jobs:
9676
cmake --install build
9777
if: |
9878
matrix.dev == true &&
99-
(steps.conda-cache.outputs.cache-hit != 'true' &&
100-
(runner.os == 'Linux' || runner.os == 'macOS'))
79+
(runner.os == 'Linux' || runner.os == 'macOS')
10180
10281
- name: Configure, build & install s2geography (win)
103-
shell: bash -l {0}
10482
run: |
10583
cd deps/s2geography
10684
cmake -S . -B build \
@@ -111,15 +89,27 @@ jobs:
11189
cmake --build build --config Release
11290
cmake --install build
11391
if: |
114-
matrix.dev == true &&
115-
(steps.conda-cache.outputs.cache-hit != 'true' &&
116-
runner.os == 'Windows')
92+
matrix.dev == true && runner.os == 'Windows'
11793
11894
- name: Build and install spherely
119-
shell: bash -l {0}
120-
run: python -m pip install . -v --no-build-isolation
95+
run: |
96+
python -m pip install . -v --no-build-isolation --config-settings cmake.define.SPHERELY_CODE_COVERAGE=ON --config-settings build-dir=_skbuild
12197
12298
- name: Run tests
123-
shell: bash -l {0}
12499
run: |
125100
pytest . -vv
101+
102+
- name: Generate coverage report
103+
run: |
104+
python -m pip install gcovr
105+
gcovr --exclude-unreachable-branches --print-summary -x -o coverage.xml
106+
if: |
107+
runner.os == 'Linux' && matrix.python-version == '3.11' && matrix.dev == false
108+
109+
- name: Upload coverage report
110+
uses: codecov/codecov-action@v3
111+
with:
112+
files: ./coverage.xml
113+
verbose: true
114+
if: |
115+
runner.os == 'Linux' && matrix.python-version == '3.11' && matrix.dev == false

.pre-commit-config.yaml

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
repos:
2+
- repo: https://github.com/pre-commit/pre-commit-hooks
3+
rev: v4.4.0
4+
hooks:
5+
- id: trailing-whitespace
6+
- id: end-of-file-fixer
7+
- id: check-yaml
8+
- id: debug-statements
9+
- id: mixed-line-ending
10+
- repo: https://github.com/psf/black
11+
rev: 23.1.0
12+
hooks:
13+
- id: black
14+
args: [--safe, --quiet]
15+
- repo: https://github.com/pre-commit/mirrors-clang-format
16+
rev: v15.0.7
17+
hooks:
18+
- id: clang-format
19+
args: [--style=file]
20+
21+
ci:
22+
autofix_prs: false

CMakeLists.txt

+13
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ project(
77
set(CMAKE_CXX_STANDARD 17 CACHE STRING "The C++ standard to build with")
88
set(CMAKE_CXX_STANDARD_REQUIRED ON)
99

10+
option(SPHERELY_CODE_COVERAGE "Enable coverage reporting" OFF)
11+
1012
# Dependencies
1113

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

30+
if(SPHERELY_CODE_COVERAGE)
31+
message(STATUS "Building spherely with coverage enabled")
32+
add_library(coverage_config INTERFACE)
33+
endif()
34+
2835
# Compile definitions and flags
2936

3037
if (MSVC)
@@ -72,6 +79,12 @@ endif()
7279

7380
set_target_properties(spherely PROPERTIES CXX_VISIBILITY_PRESET "hidden")
7481

82+
if (SPHERELY_CODE_COVERAGE)
83+
target_compile_options(coverage_config INTERFACE -O0 -g --coverage)
84+
target_link_options(coverage_config INTERFACE --coverage)
85+
target_link_libraries(spherely PUBLIC coverage_config)
86+
endif()
87+
7588
# Install
7689

7790
install(TARGETS spherely LIBRARY DESTINATION .)

README.md

+12-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

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

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

@@ -67,7 +68,17 @@ Run the tests:
6768
$ pytest . -v
6869
```
6970

70-
## Using the latest s2geography
71+
Spherely also uses [pre-commit](https://pre-commit.com/) for code
72+
auto-formatting and linting at every commit. After installing it, you can enable
73+
pre-commit hooks with the following command:
74+
75+
```
76+
$ pre-commit install
77+
```
78+
79+
(Note: you can skip the pre-commit checks with `git commit --no-verify`)
80+
81+
## Using the latest s2geography version
7182

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

docs/api.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,4 @@ Predicates
5454
intersects
5555
contains
5656
within
57-
disjoint
57+
disjoint

pyproject.toml

+5
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,8 @@ Repository = "https://github.com/benbovy/spherely"
2727

2828
[project.optional-dependencies]
2929
test = ["pytest>=6.0"]
30+
31+
[tool.mypy]
32+
files = ["tests", "src/spherely.pyi"]
33+
show_error_codes = true
34+
warn_unused_ignores = true

0 commit comments

Comments
 (0)