Skip to content

Commit

Permalink
Add code coverage to CI (#694)
Browse files Browse the repository at this point in the history
* Add code coverage to CI

* Use coverage.py for generating coverage report

* Trial: use "Cython" with a capital C

* Add Cython linetracing in CI

* Use scip.pxi file to avoid coverage error when using pyx

* Separate test coverage into its own CI workflow

* Rename test coverage job

* Add comment to make it clear why redirection to .pxi is needed

* Remove unneeded packages

* Trial: add back cython install
  • Loading branch information
mmghannam authored Jun 30, 2023
1 parent a3a9c42 commit 341e9e6
Show file tree
Hide file tree
Showing 7 changed files with 5,096 additions and 5,039 deletions.
9 changes: 5 additions & 4 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[run]
plugins = Cython.Coverage
#source = src/pyscipopt
#omit =
# tests
# *__init__.py
source = src/pyscipopt
omit =
tests
__init__.py
scip.pyx
50 changes: 50 additions & 0 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: Run tests with coverage
env:
version: 8.0.3

# runs on branches and pull requests; doesn't run on tags.
on:
push:
branches:
- '**'
pull_request:

jobs:

test-coverage:
runs-on: ubuntu-20.04
strategy:
fail-fast: true
matrix:
python-version: ["3.11"]
steps:
- uses: actions/checkout@v3

- name: Install dependencies (SCIPOptSuite)
run: |
wget --quiet --no-check-certificate https://scipopt.org/download/release/SCIPOptSuite-${{ env.version }}-Linux-ubuntu.deb
sudo apt-get update && sudo apt install -y ./SCIPOptSuite-${{ env.version }}-Linux-ubuntu.deb
- name: Setup python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

- name: Prepare python environment
run: |
python -m pip install --upgrade pip
python -m pip install networkx cython pytest-cov
- name: Install PySCIPOpt
run: python -m pip install .

- name: Run pyscipopt tests
run: |
coverage run -m pytest
coverage report -m
coverage xml
- name: Upload to codecov.io
uses: codecov/codecov-action@v2
with:
fail_ci_if_error: true
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ from pyscipopt import Model
model = Model("Example") # model name is optional
```

3) Access the methods in the `scip.pyx` file using the solver/model
3) Access the methods in the `scip.pxi` file using the solver/model
instance `model`, e.g.:

``` {.sourceCode .python}
Expand Down Expand Up @@ -108,7 +108,7 @@ may also extend it to increase the functionality of this interface. The
following will provide some directions on how this can be achieved:

The two most important files in PySCIPOpt are the `scip.pxd` and
`scip.pyx`. These two files specify the public functions of SCIP that
`scip.pxi`. These two files specify the public functions of SCIP that
can be accessed from your python code.

To make PySCIPOpt aware of the public functions you would like to
Expand All @@ -122,7 +122,7 @@ be done in order to properly add the functions:

After following the previous two steps, it is then possible to create
functions in python that reference the SCIP public functions included in
`scip.pxd`. This is achieved by modifying the `scip.pyx` file to add the
`scip.pxd`. This is achieved by modifying the `scip.pxi` file to add the
functionality you require.

We are always happy to accept pull request containing patches or
Expand Down
4 changes: 2 additions & 2 deletions docs/maindoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
#following will provide some directions on how this can be achieved:
#
#The two most important files in PySCIPOpt are the `scip.pxd` and
#`scip.pyx`. These two files specify the public functions of SCIP that
#`scip.pxi`. These two files specify the public functions of SCIP that
#can be accessed from your python code.
#
#To make PySCIPOpt aware of the public functions you would like to
Expand All @@ -44,7 +44,7 @@
#
#After following the previous two steps, it is then possible to create
#functions in python that reference the SCIP public functions included in
#`scip.pxd`. This is achieved by modifying the `scip.pyx` file to add the
#`scip.pxd`. This is achieved by modifying the `scip.pxi` file to add the
#functionality you require.
#
#We are always happy to accept pull request containing patches or
Expand Down
5 changes: 4 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@

ext = ".pyx" if use_cython else ".c"

on_github_actions = os.getenv('GITHUB_ACTIONS') == 'true'

extensions = [
Extension(
"pyscipopt.scip",
Expand All @@ -97,11 +99,12 @@
libraries=[libname],
extra_compile_args=extra_compile_args,
extra_link_args=extra_link_args,
define_macros= [("CYTHON_TRACE_NOGIL", 1), ("CYTHON_TRACE", 1)] if on_github_actions else []
)
]

if use_cython:
extensions = cythonize(extensions, compiler_directives={"language_level": 3})
extensions = cythonize(extensions, compiler_directives={"language_level": 3, "linetrace": on_github_actions})

with open("README.md") as f:
long_description = f.read()
Expand Down
Loading

0 comments on commit 341e9e6

Please sign in to comment.