Skip to content

Commit b14cd68

Browse files
authored
add example notebooks (and their execution through devops_tests) (#222)
1 parent 800f9ba commit b14cd68

11 files changed

+2129
-16
lines changed

.binder/postBuild

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/bash
2+
set -e
3+
shopt -s extglob
4+
rm -rfv !("examples")

.binder/requirements.txt

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
PyPartMC>=0.0.19
2+
matplotlib
3+
ipywidgets
4+
voila
5+
open-atmos-jupyter-utils
6+
PySDM

.github/workflows/pylint.yml

+3-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ jobs:
2020
python-version: 3.9
2121
- run: |
2222
python -m pip install --upgrade pip
23-
pip install pylint
23+
pip install pylint nbqa
2424
pip install -e .[tests]
25+
pip install -r .binder/requirements.txt
2526
- run: pylint --unsafe-load-any-extension=y --disable=fixme,no-member,trailing-newlines,missing-module-docstring,missing-class-docstring,missing-function-docstring,unnecessary-pass $(git ls-files '*.py')
27+
- run: nbqa pylint --unsafe-load-any-extension=y --disable=fixme,no-member,wrong-import-position,trailing-whitespace,missing-function-docstring,missing-module-docstring $(git ls-files '*.ipynb')

.github/workflows/tests+pypi.yml

+10-13
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,6 @@ on:
1515
types: [published]
1616

1717
jobs:
18-
devops_tests:
19-
runs-on: ubuntu-latest
20-
steps:
21-
- uses: actions/checkout@v2
22-
with:
23-
submodules: recursive
24-
fetch-depth: 0 # https://github.com/pypa/setuptools_scm/issues/480
25-
- run: pip install -r gitmodules/devops_tests/requirements.txt
26-
- env:
27-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
28-
run: pytest --durations=10 -v -s -We -p no:unraisableexception gitmodules/devops_tests
29-
3018
debug_build_ok:
3119
runs-on: ubuntu-latest
3220
steps:
@@ -37,11 +25,12 @@ jobs:
3725
- run: DEBUG=1 VERBOSE=1 pip install --verbose -e .[tests]
3826

3927
build:
40-
needs: [devops_tests, debug_build_ok]
28+
needs: [debug_build_ok]
4129
strategy:
4230
matrix:
4331
platform: [ubuntu-latest, macos-12, windows-latest]
4432
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"]
33+
fail-fast: false
4534
runs-on: ${{ matrix.platform }}
4635
steps:
4736
- if: startsWith(matrix.platform, 'macos-')
@@ -118,6 +107,14 @@ jobs:
118107
cd tests
119108
python -c "import PyPartMC"
120109
pytest --durations=10 -v -s -We -p no:unraisableexception -k 'not test_todos_annotated' .
110+
cd ..
111+
112+
- if: matrix.python-version != '3.7'
113+
run: |
114+
pip install -r gitmodules/devops_tests/requirements.txt
115+
ex -sc 'g/^PyPartMC/d' -cx .binder/requirements.txt
116+
pip install -r .binder/requirements.txt
117+
GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }} pytest --durations=10 -v -s -We -p no:unraisableexception gitmodules/devops_tests
121118
122119
### uncomment to gain ssh access in case of failure
123120
# - if: ${{ failure() }}

README.md

+8
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,14 @@ The Python API can facilitate using PartMC from other environments - see, e.g.,
2828
import PyPartMC
2929
```
3030

31+
#### Jupyter notebooks with examples
32+
33+
- Dry-Wet Particle Size Equilibration with PartMC and PySDM:
34+
[![nbviewer](https://raw.githubusercontent.com/jupyter/design/master/logos/Badges/nbviewer_badge.svg)](https://nbviewer.jupyter.org/github/open-atmos/PyPartMC/blob/main/examples/lognorm_ex.ipynb)
35+
[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/open-atmos/PyPartMC/blob/main/examples/lognorm_ex.ipynb)
36+
[![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/open-atmos/PyPartMC.git/main?urlpath=lab/tree/examples/lognorm_ex.ipynb)
37+
[![Voila](https://img.shields.io/static/v1?label=Voil%C3%A0&logo=jupyter&color=teal&message=web+app)](https://mybinder.org/v2/gh/open-atmos/PyPartMC/main?urlpath=voila%2Frender%2Fexamples%2Flognorm_ex.ipynb)
38+
3139
## Features
3240

3341
- works on Linux, macOS and Windows (compatibility assured with [CI builds](https://github.com/open-atmos/PyPartMC/blob/main/.github/workflows/tests.yml))

examples/hello_world.ipynb

+94
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {},
6+
"source": [
7+
"[![nbviewer](https://raw.githubusercontent.com/jupyter/design/master/logos/Badges/nbviewer_badge.svg)](https://nbviewer.jupyter.org/github/open-atmos/PyPartMC/blob/main/examples/hello_world.ipynb) \n",
8+
"[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/open-atmos/PyPartMC/blob/main/examples/hello_world.ipynb) \n",
9+
"[![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/open-atmos/PyPartMC.git/main?urlpath=lab/tree/examples/hello_world.ipynb)"
10+
]
11+
},
12+
{
13+
"cell_type": "code",
14+
"execution_count": 1,
15+
"metadata": {
16+
"id": "iEavJeJoPWzg"
17+
},
18+
"outputs": [],
19+
"source": [
20+
"import sys\n",
21+
"if 'google.colab' in sys.modules:\n",
22+
" !pip --verbose install PyPartMC"
23+
]
24+
},
25+
{
26+
"cell_type": "code",
27+
"execution_count": 3,
28+
"metadata": {
29+
"id": "VnLSclLsOxRz"
30+
},
31+
"outputs": [],
32+
"source": [
33+
"import PyPartMC as ppmc"
34+
]
35+
},
36+
{
37+
"cell_type": "code",
38+
"execution_count": 4,
39+
"metadata": {
40+
"id": "s2VeF72qPsKB"
41+
},
42+
"outputs": [
43+
{
44+
"data": {
45+
"text/plain": [
46+
"16"
47+
]
48+
},
49+
"execution_count": 4,
50+
"metadata": {},
51+
"output_type": "execute_result"
52+
}
53+
],
54+
"source": [
55+
"ppmc.pow2_above(13)"
56+
]
57+
},
58+
{
59+
"cell_type": "code",
60+
"execution_count": null,
61+
"metadata": {
62+
"id": "I_kD6AomXW6h"
63+
},
64+
"outputs": [],
65+
"source": []
66+
}
67+
],
68+
"metadata": {
69+
"colab": {
70+
"collapsed_sections": [],
71+
"name": "Untitled13.ipynb",
72+
"provenance": []
73+
},
74+
"kernelspec": {
75+
"display_name": "Python 3",
76+
"language": "python",
77+
"name": "python3"
78+
},
79+
"language_info": {
80+
"codemirror_mode": {
81+
"name": "ipython",
82+
"version": 3
83+
},
84+
"file_extension": ".py",
85+
"mimetype": "text/x-python",
86+
"name": "python",
87+
"nbconvert_exporter": "python",
88+
"pygments_lexer": "ipython3",
89+
"version": "3.9.1"
90+
}
91+
},
92+
"nbformat": 4,
93+
"nbformat_minor": 1
94+
}

0 commit comments

Comments
 (0)