Skip to content

Commit b38708a

Browse files
authored
Enhanced starter project by using pyproject.toml, formatting, pytest and CI (#7)
1 parent c1d955b commit b38708a

File tree

10 files changed

+156
-65
lines changed

10 files changed

+156
-65
lines changed

.github/dependabot.yml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
1-
# Set update schedule for GitHub Actions
1+
# Set update schedule for GitHub Actions and Python packages
22

33
version: 2
44
updates:
55

6+
# Check for updates to GitHub Actions every week
67
- package-ecosystem: "github-actions"
78
directory: "/"
89
schedule:
9-
# Check for updates to GitHub Actions every week
1010
interval: "weekly"
1111

12+
# Check for updates to pip packages every week
13+
- package-ecosystem: "pip"
14+
directory: "/"
15+
schedule:
16+
interval: "weekly"

.github/workflows/buildtest.yml

Lines changed: 5 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ on:
1414

1515
jobs:
1616
test:
17-
name: Test and Deploy (${{ matrix.config.stormpyImg }})
17+
name: Build and Test (${{ matrix.config.stormpyImg }})
1818
runs-on: ubuntu-latest
1919
strategy:
2020
matrix:
@@ -27,35 +27,11 @@ jobs:
2727
- name: Git clone
2828
uses: actions/checkout@v6
2929
- name: Build from Dockerfile
30-
run: docker build -t movesrwth/stormpy-starter . --build-arg STORMPY_BASE=movesrwth/stormpy:${{ matrix.config.stormpyImg }}
30+
run: docker build -t stormchecker/stormpy-starter . --build-arg STORMPY_BASE=movesrwth/stormpy:${{ matrix.config.stormpyImg }}
3131
- name: Run Docker
32-
run: docker run -d -it --name ci -p 8888:8888 movesrwth/stormpy-starter
33-
- name: Run and check output of example commands
32+
run: docker run -d -it --name ci -p 8888:8888 stormchecker/stormpy-starter
33+
- name: Run tests
3434
run: |
35-
docker exec ci bash -c "python stormpy_starter/check.py --model examples/die.pm --property examples/die.pctl | grep 'no'"
36-
docker exec ci bash -c "python stormpy_starter/check.py --model examples/die.pm --property examples/die2.pctl | grep 'yes'"
35+
docker exec ci bash -c "pip install .[test]; pytest"
3736
- name: Run notebook
3837
run: docker exec ci bash -c "pip install papermill && papermill stormpy_starter.ipynb"
39-
40-
notify:
41-
name: Email notification
42-
runs-on: ubuntu-latest
43-
needs: [test]
44-
# Only run in main repo and even if previous step failed
45-
if: github.repository_owner == 'moves-rwth' && always()
46-
steps:
47-
- uses: technote-space/workflow-conclusion-action@v3
48-
- uses: dawidd6/action-send-mail@v6
49-
with:
50-
server_address: ${{ secrets.STORM_CI_MAIL_SERVER }}
51-
server_port: 587
52-
username: ${{ secrets.STORM_CI_MAIL_USERNAME }}
53-
password: ${{ secrets.STORM_CI_MAIL_PASSWORD }}
54-
subject: "[You broke it] CI run failed for ${{ github.repository }}"
55-
body:
56-
"CI job of ${{ github.repository }} has failed for commit ${{ github.sha }}.\n\
57-
The error type is: ${{ env.WORKFLOW_CONCLUSION }}.\n\n\
58-
For more information, see https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}"
59-
to: ${{ secrets.STORM_CI_MAIL_RECIPIENTS }}
60-
from: Github Actions <you-broke-it@stormchecker.org>
61-
if: env.WORKFLOW_CONCLUSION != 'success' # notify only if failure

.github/workflows/formatapply.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
name: Apply code format
2+
3+
on:
4+
workflow_dispatch:
5+
6+
jobs:
7+
build:
8+
runs-on: ubuntu-latest
9+
10+
steps:
11+
- uses: actions/checkout@v5
12+
- uses: psf/black@stable
13+
with:
14+
options: ""
15+
src: "."
16+
jupyter: true
17+
- name: Commit Formatting
18+
run: |
19+
git config user.name 'Auto Format'
20+
git config user.email 'test@test'
21+
if [ -z "$(git status --porcelain)" ]
22+
then
23+
echo "Code did not change"
24+
else
25+
git commit -am "Applied code formatting"
26+
git rev-parse HEAD >> .git-blame-ignore-revs
27+
git commit -am "Add code formatting commit to .git-blame-ignore-revs"
28+
fi
29+
- name: Create Pull Request
30+
id: cpr
31+
uses: peter-evans/create-pull-request@v7
32+
with:
33+
branch: ci/apply-code-format
34+
delete-branch: true
35+
title: 'Code formatting'
36+
body: |
37+
Auto-generated pull request triggered by the `apply-code-format` workflow.
38+
- Manually close and reopen this PR to trigger the CI.
39+
- Make sure to **merge** (and not rebase) this PR so that the added commit hash in `.git-blame-ignore-revs` remains valid.

.github/workflows/formatcheck.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: Check code format
2+
3+
on:
4+
push:
5+
pull_request:
6+
workflow_dispatch:
7+
8+
jobs:
9+
build:
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- uses: actions/checkout@v5
14+
- uses: psf/black@stable
15+
with:
16+
options: "--check --diff --color"
17+
src: "."
18+
jupyter: true

Dockerfile

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
# Run Docker container for Jupyter notebook
2+
###################################
3+
# The Docker image can be built by executing:
4+
# docker build -t yourusername/stormpy-starter .
5+
# A different stormpy base image can be set from the commandline with:
6+
# --build-arg STORMPY_BASE=<new_base_image>
7+
8+
# Set stormpy base image
29
ARG STORMPY_BASE=movesrwth/stormpy:stable
310
FROM $STORMPY_BASE
4-
MAINTAINER Matthias Volk <m.volk@utwente.nl>
11+
LABEL org.opencontainers.image.authors="dev@stormchecker.org"
512

613

714
##########

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
# storm-project-starter-python
22
Starter project for the Python API of Storm via Stormpy
33

4-
[![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/moves-rwth/storm-project-starter-python/master?filepath=stormpy_starter.ipynb)
4+
[![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/stormchecker/storm-project-starter-python/master?filepath=stormpy_starter.ipynb)
55

66
## Getting started
77
Before starting, make sure that Storm and stormpy are installed. If not, see the [documentation](https://moves-rwth.github.io/stormpy/installation.html) for details on how to install stormpy.
88

99
First, install the Python package. If you use a virtual environment, make sure to use it.
1010
To install the starter package, execute
1111
```
12-
python setup.py develop
12+
pip install .
1313
```
1414

1515
Then, run the script using
@@ -27,17 +27,17 @@ The answer should be yes.
2727
## Try out in browser via Jupyterlab
2828
You can also try out the starter project in your browser by using Jupyterlab.
2929

30-
You can use this [Binder link](https://mybinder.org/v2/gh/moves-rwth/storm-project-starter-python/master?filepath=stormpy_starter.ipynb) which starts an interactive Jupyter notebook.
30+
You can use this [Binder link](https://mybinder.org/v2/gh/stormchecker/storm-project-starter-python/master?filepath=stormpy_starter.ipynb) which starts an interactive Jupyter notebook.
3131

3232
### Running Jupyter locally.
3333
You can also start the Jupyterlab locally using [Docker](https://www.docker.com/).
3434
First, build the Docker container with
3535
```
36-
docker build -t movesrwth/stormpy-starter .
36+
docker build -t stormchecker/stormpy-starter .
3737
```
3838
Then start the Docker container with the following command:
3939
```
40-
docker run -it --rm -p 8888:8888 movesrwth/stormpy-starter jupyter notebook --NotebookApp.default_url=/lab/ --ip=0.0.0.0 --port=8888
40+
docker run -it --rm -p 8888:8888 stormchecker/stormpy-starter jupyter notebook --NotebookApp.default_url=/lab/ --ip=0.0.0.0 --port=8888
4141
```
4242
You can find the URL to the notebook in the output.
4343

pyproject.toml

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
[build-system]
2+
requires = ["hatchling >= 1.26"]
3+
build-backend = "hatchling.build"
4+
5+
[project]
6+
name = "storm-project-starter-python"
7+
description = "Starter project for the Python API of Storm via Stormpy"
8+
version = "0.1"
9+
readme = "README.md"
10+
license.file = "LICENSE"
11+
authors = [
12+
{ name = "S. Junges", email = "sebastian.junges@ru.nl" },
13+
{ name = "M. Volk", email = "m.volk@tue.nl" }
14+
]
15+
requires-python = ">=3.9"
16+
dependencies = [
17+
"stormpy>=1.10",
18+
]
19+
classifiers = [
20+
'Intended Audience :: Science/Research',
21+
'Topic :: Scientific/Engineering',
22+
'Topic :: Software Development :: Libraries :: Python Modules',
23+
]
24+
25+
[project.urls]
26+
Homepage = "https://github.com/stormchecker/storm-project-starter-python"
27+
28+
[project.optional-dependencies]
29+
dev = [
30+
# Formatting
31+
"black[jupyter]",
32+
]
33+
test = [
34+
"pytest",
35+
"nbval",
36+
]
37+
38+
[tool.hatch.build.targets.wheel]
39+
only-include = ["stormpy_starter"]
40+
41+
[tool.black]
42+
line-length = 160
43+
44+
[tool.pytest.ini_options]
45+
minversion = "6.0"
46+
addopts = "--nbval"
47+
#testpaths = [
48+
# "tests",
49+
# "examples",
50+
# "doc",
51+
#]
52+
#python_files = [
53+
# "test*.py",
54+
# "examples/*.py",
55+
#]
56+
#python_functions = [
57+
# "*_test",
58+
# "test_*",
59+
# "example_*",
60+
#]

setup.py

Lines changed: 0 additions & 25 deletions
This file was deleted.

stormpy_starter/check.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ def check(path_to_model, property_str):
1212

1313

1414
def main():
15-
parser = argparse.ArgumentParser(description='Starter project for stormpy.')
15+
parser = argparse.ArgumentParser(description="Starter project for stormpy.")
1616

17-
parser.add_argument('--model', '-m', help='Model file', required=True)
18-
parser.add_argument('--property', '-p', help='Property', required=True)
17+
parser.add_argument("--model", "-m", help="Model file", required=True)
18+
parser.add_argument("--property", "-p", help="Property", required=True)
1919
args = parser.parse_args()
2020

2121
# Call function

tests/test_starter.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
from stormpy_starter import check
2+
3+
4+
def test_prop1():
5+
answer = check.check("examples/die.pm", "examples/die.pctl")
6+
assert not answer
7+
8+
9+
def test_prop2():
10+
answer = check.check("examples/die.pm", "examples/die2.pctl")
11+
assert answer

0 commit comments

Comments
 (0)