Skip to content

Commit

Permalink
Add coverage for Python torch bindings
Browse files Browse the repository at this point in the history
  • Loading branch information
PicoCentauri committed Oct 11, 2023
1 parent 434f923 commit 97dba02
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 17 deletions.
12 changes: 4 additions & 8 deletions .codecov.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
coverage:
ignore:
- tests/.*
status:
project:
default:
target: 80%
patch: off
ignore:
- "tests/.*"
- "examples/.*"

comment: off

fixes:
# map coverage collected inside tox virtual environments
# to the source dir in git
- ".tox/all-deps/lib/*/site-packages/::python/"
comment: false
20 changes: 16 additions & 4 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
- name: install python dependencies
run: |
python -m pip install --upgrade pip
python -m pip install tox
python -m pip install tox coverage
- name: install lcov
run: sudo apt install -y lcov
Expand All @@ -47,7 +47,7 @@ jobs:
uses: actions/cache@v3
with:
path: .tox
key: tox-${{ matrix.os }}-${{ hashFiles('pyproject.toml', 'setup.cfg', 'tox.ini') }}
key: tox-${{ hashFiles('pyproject.toml', 'setup.cfg', 'tox.ini') }}

- name: Setup sccache
uses: mozilla-actions/[email protected]
Expand All @@ -69,10 +69,22 @@ jobs:
lcov --remove coverage.info '/usr/*' "$(pwd)/rascaline-c-api/tests/*" "$(pwd)/rascaline-c-api/examples/*" --output-file coverage.info
- name: collect Python coverage
run: tox -e all-deps
run: |
tox -e all-deps
tox -e torch-tests
env:
# Use the CPU only version of torch when building/running the code
PIP_EXTRA_INDEX_URL: https://download.pytorch.org/whl/cpu

- name: combine Python coverage files
run: |
coverage combine \
.coverage \
./python/rascaline-torch/.coverage \
coverage xml
- name: upload to codecov.io
uses: codecov/codecov-action@v3
with:
fail_ci_if_error: true
files: target/tarpaulin/cobertura.xml,.tox/coverage.xml,coverage.info
files: target/tarpaulin/cobertura.xml,coverage.xml,coverage.info
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ target/
Cargo.lock

.tox/
.coverage
build/
dist/
*.egg-info
__pycache__/
.vscode
*.DS_Store
htmlcov/
.coverage
coverage.xml
18 changes: 18 additions & 0 deletions CONTRIBUTING.rst
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,24 @@ of just testing it.
.. _`cargo` : https://doc.rust-lang.org/cargo/
.. _valgrind: https://valgrind.org/

Inspecting Python code coverage
-------------------------------

The code coverage is reported at `codecov`_. You can also inspect the coverage locally.
To get the full coverage first combine all reports and open produced html file in a
browser

.. code-block:: bash
tox
coverage combine \
.coverage \
./python/rascaline-torch/.coverage
coverage html
firefox htmlcov/index.html
.. _codecov: https://codecov.io/gh/lab-cosmo/metatensor

Writing your own calculator
---------------------------

Expand Down
27 changes: 23 additions & 4 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ min_version = 4.0
# execute `tox` in the command-line without anything else
envlist =
lint
all-deps
min-deps
all-deps
docs-tests
torch-tests

Expand All @@ -25,6 +25,7 @@ metatensor-torch-requirement =
metatensor-torch @ git+https://github.com/lab-cosmo/metatensor@ad3eda5\#subdirectory=python/metatensor-torch

build-single-wheel = --no-deps --no-build-isolation --check-build-dependencies
test_options = --cov={env_site_packages_dir}/rascaline --cov-append --import-mode=append

commands =
# error if the user gives a wrong testenv name in `tox -e`
Expand Down Expand Up @@ -55,24 +56,26 @@ deps =
pytest-cov

commands =
pytest --cov={env_site_packages_dir}/rascaline --cov-report xml:.tox/coverage.xml --import-mode=append {posargs}
pytest {[testenv]test_options} {posargs}


[testenv:min-deps]
# Run Python unit tests with the minimal dependencies installed
deps =
{[testenv]metatensor-core-requirement}
pytest
pytest-cov

commands =
pytest --import-mode=append {posargs}
pytest {[testenv]test_options} {posargs}


[testenv:torch-tests]
deps =
{[testenv]metatensor-torch-requirement}

pytest
pytest-cov
numpy
torch
ase
Expand All @@ -85,7 +88,7 @@ commands =
# install rascaline-torch
pip install . {[testenv]build-single-wheel} --force-reinstall
# run the unit tests
pytest --import-mode=append --assert=plain {posargs}
pytest {[testenv]test_options} --assert=plain {posargs}

[testenv:docs]
deps =
Expand Down Expand Up @@ -183,3 +186,19 @@ commands =
[flake8]
max_line_length = 88
extend-ignore = E203

[coverage:report]
skip_covered = True
show_missing = True
omit =
tests/.*
examples/.*

[coverage:paths]
notorch =
python/rascaline/rascaline
.tox/*/lib/python*/site-packages/rascaline

torch =
python/rascaline-torch/rascaline/torch
.tox/*/lib/python*/site-packages/rascaline/torch

0 comments on commit 97dba02

Please sign in to comment.