-
Notifications
You must be signed in to change notification settings - Fork 45
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ipython notebook test #330
Changes from all commits
3fbb93e
b74789e
c612823
9064e45
afffea8
a2b861c
b12cedd
a6d8784
3b83724
bd11f44
44459c9
b722e62
71dcd1f
63f502a
34dd1d5
d08a726
63a17d8
8f0ed6b
5d1bfee
7c89d7b
f3852b6
55d97de
5341646
8673de3
ea932bf
2993b82
bb7b5c9
eaddc60
651cacb
5a11a8a
c8665b5
83d1d98
8f8c8e6
040c3b2
a546114
958305f
d31d9c1
0d5839d
3295c39
1166c53
998f4e0
fb2b808
f7b8da0
25542e5
2beacae
070c838
db8c207
5ebcbc9
5017aaf
815c10e
0ee3260
5ba6250
f649f23
9dc3694
e207a84
e767c0b
e45bbf8
7f497d6
3e0ff69
16a30de
aedd5fa
07020e4
01fb1c1
c177897
5549614
274aac0
77513ac
e268e79
d9af35f
3659770
0f0d397
03f61c1
223fe51
c6eb428
635b091
c5429a8
62a3a7c
24623f7
fcf1a66
b16bd37
e1a133d
d9f3af8
13ce5ae
6ab5196
6e602ab
cd01c92
61bda0f
a5e695e
f203642
30f6947
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
""" | ||
Dynamically creates a matrix for the GitHub Actions workflow that | ||
runs the notebooks in the examples directory. | ||
""" | ||
|
||
import os | ||
import json | ||
|
||
# Dictionary to store custom timeouts for each notebook | ||
notebook_timeouts = { | ||
"ADCP_Delft3D_TRTS_example.ipynb": 1200, | ||
"adcp_example.ipynb": 240, | ||
"adv_example.ipynb": 180, | ||
"cdip_example.ipynb": 180, | ||
"Delft3D_example.ipynb": 180, | ||
"directional_waves.ipynb": 180, | ||
"environmental_contours_example.ipynb": 720, | ||
"extreme_response_contour_example.ipynb": 360, | ||
"extreme_response_full_sea_state_example.ipynb": 420, | ||
"extreme_response_MLER_example.ipynb": 650, | ||
"loads_example.ipynb": 180, | ||
"metocean_example.ipynb": 240, | ||
"mooring_example.ipynb": 300, | ||
"PacWave_resource_characterization_example.ipynb": 780, | ||
"power_example.ipynb": 180, | ||
"qc_example.ipynb": 180, | ||
"river_example.ipynb": 240, | ||
"short_term_extremes_example.ipynb": 180, | ||
"SWAN_example.ipynb": 180, | ||
"tidal_example.ipynb": 240, | ||
"tidal_performance_example.ipynb": 180, | ||
"upcrossing_example.ipynb": 180, | ||
"wave_example.ipynb": 180, | ||
"wecsim_example.ipynb": 180, | ||
"WPTO_hindcast_example.ipynb": 1200, | ||
"default": 300, # Default timeout for other notebooks | ||
} | ||
notebooks = [] | ||
for root, dirs, files in os.walk("examples"): | ||
for file in files: | ||
if file.endswith(".ipynb"): | ||
notebooks.append(os.path.join(root, file)) | ||
|
||
# Generate the matrix configuration | ||
matrix = {"include": []} | ||
for notebook in notebooks: | ||
timeout = notebook_timeouts.get( | ||
os.path.basename(notebook), notebook_timeouts["default"] | ||
) | ||
|
||
matrix["include"].append({"notebook": notebook, "timeout": timeout}) | ||
|
||
|
||
# Print the matrix as a properly formatted JSON string | ||
matrix_json = json.dumps(matrix) | ||
print(f"matrix={matrix_json}") |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
name: Py 3.8, 3.9, 3.10, 3.11 | Windows Mac Linux | ||
name: Py 3.10, 3.11 | Windows Mac Linux | ||
|
||
on: | ||
push: | ||
|
@@ -52,7 +52,7 @@ jobs: | |
prepare-nonhindcast-cache: | ||
runs-on: ubuntu-latest | ||
env: | ||
PYTHON_VER: 3.9 | ||
PYTHON_VER: 3.11 | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v4 | ||
|
@@ -95,7 +95,7 @@ jobs: | |
needs: [check-changes] | ||
runs-on: ubuntu-latest | ||
env: | ||
PYTHON_VER: 3.9 | ||
PYTHON_VER: 3.11 | ||
if: (needs.check-changes.outputs.should-run-hindcast == 'true') | ||
steps: | ||
- name: Checkout code | ||
|
@@ -137,7 +137,7 @@ jobs: | |
needs: [check-changes, prepare-wave-hindcast-cache] | ||
runs-on: ubuntu-latest | ||
env: | ||
PYTHON_VER: 3.9 | ||
PYTHON_VER: 3.11 | ||
if: (needs.check-changes.outputs.should-run-hindcast == 'true') | ||
steps: | ||
- name: Checkout code | ||
|
@@ -183,7 +183,7 @@ jobs: | |
fail-fast: false | ||
matrix: | ||
os: ${{fromJson(needs.set-os.outputs.matrix_os)}} | ||
python-version: ['3.8', '3.9', '3.10', '3.11'] | ||
python-version: ['3.10', '3.11'] | ||
env: | ||
PYTHON_VER: ${{ matrix.python-version }} | ||
|
||
|
@@ -234,7 +234,7 @@ jobs: | |
fail-fast: false | ||
matrix: | ||
os: ${{fromJson(needs.set-os.outputs.matrix_os)}} | ||
python-version: ['3.8', '3.9', '3.10', '3.11'] | ||
python-version: ['3.10', '3.11'] | ||
|
||
steps: | ||
- uses: conda-incubator/setup-miniconda@v3 | ||
|
@@ -244,21 +244,6 @@ jobs: | |
with: | ||
python-version: ${{ matrix.python-version }} | ||
|
||
- name: Install HDF5 (macOS with Python 3.8) | ||
if: startsWith(runner.os, 'macOS') && matrix.python-version == '3.8' | ||
run: brew install hdf5 | ||
|
||
- name: Install NetCDF (macOS with Python 3.8) | ||
if: startsWith(runner.os, 'macOS') && matrix.python-version == '3.8' | ||
run: brew install netcdf | ||
|
||
- name: Set environment variables (macOS with Python 3.8) | ||
if: startsWith(runner.os, 'macOS') && matrix.python-version == '3.8' | ||
run: | | ||
echo "HDF5_DIR=$(brew --prefix hdf5)" >> $GITHUB_ENV | ||
echo "NETCDF4_DIR=$(brew --prefix netcdf)" >> $GITHUB_ENV | ||
echo "PKG_CONFIG_PATH=$(brew --prefix hdf5)/lib/pkgconfig:$(brew --prefix netcdf)/lib/pkgconfig:$PKG_CONFIG_PATH" >> $GITHUB_ENV | ||
|
||
- name: Set up Git repository | ||
uses: actions/checkout@v4 | ||
|
||
|
@@ -305,7 +290,7 @@ jobs: | |
fail-fast: false | ||
matrix: | ||
os: ${{fromJson(needs.set-os.outputs.matrix_os)}} | ||
python-version: ['3.8', '3.9', '3.10', '3.11'] | ||
python-version: ['3.10', '3.11'] | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
|
@@ -359,6 +344,104 @@ jobs: | |
parallel: true | ||
path-to-lcov: ./coverage.lcov | ||
|
||
notebook-matrix: | ||
runs-on: ubuntu-latest | ||
needs: | ||
[ | ||
check-changes, | ||
prepare-nonhindcast-cache, | ||
prepare-wave-hindcast-cache, | ||
prepare-wind-hindcast-cache, | ||
] | ||
if: | | ||
always() && | ||
( | ||
( | ||
Comment on lines
+357
to
+358
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "always() &&" seems redundant There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree, however, I have become accustomed to this syntax in actions and you will find it throughout our tests. There is discussion here agreeing that you should not need to but that you do: |
||
needs.prepare-nonhindcast-cache.result == 'success' && | ||
needs.prepare-wave-hindcast-cache.result == 'skipped' && | ||
needs.prepare-wind-hindcast-cache.result == 'skipped' && | ||
needs.check-changes.outputs.should-run-hindcast == 'false' | ||
) || | ||
( | ||
needs.prepare-nonhindcast-cache.result == 'success' && | ||
needs.prepare-wave-hindcast-cache.result == 'success' && | ||
needs.prepare-wind-hindcast-cache.result == 'success' && | ||
needs.check-changes.outputs.should-run-hindcast == 'true' | ||
) | ||
) | ||
outputs: | ||
matrix: ${{ steps.set-matrix.outputs.matrix }} | ||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v4 | ||
|
||
- name: Set up Python | ||
uses: actions/setup-python@v2 | ||
with: | ||
python-version: '3.11' | ||
|
||
- name: Generate matrix | ||
id: set-matrix | ||
run: | | ||
matrix_json=$(python .github/workflows/generate_notebook_matrix.py) | ||
echo "$matrix_json" >> $GITHUB_OUTPUT | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is the purpose of the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In bash here we are setting a variable So the |
||
|
||
test-notebooks: | ||
needs: | ||
[ | ||
notebook-matrix, | ||
check-changes, | ||
prepare-nonhindcast-cache, | ||
prepare-wave-hindcast-cache, | ||
prepare-wind-hindcast-cache, | ||
] | ||
strategy: | ||
matrix: ${{ fromJson(needs.notebook-matrix.outputs.matrix) }} | ||
if: | | ||
always() | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v4 | ||
|
||
- name: Set up Miniconda | ||
uses: conda-incubator/setup-miniconda@v3 | ||
with: | ||
miniconda-version: 'latest' | ||
auto-update-conda: true | ||
python-version: '3.11' | ||
activate-environment: TESTconda | ||
use-only-tar-bz2: true | ||
|
||
- name: Install dependencies | ||
shell: bash -l {0} | ||
run: | | ||
conda install numpy cython pip hdf5 libnetcdf cftime netcdf4 --strict-channel-priority | ||
pip install -e . --force-reinstall | ||
python -m pip install --upgrade pip wheel | ||
pip install nbval jupyter | ||
pip install utm folium | ||
|
||
- name: Ensure Conda environment is activated | ||
shell: bash -l {0} | ||
run: | | ||
echo "source ~/miniconda3/etc/profile.d/conda.sh" >> ~/.bashrc | ||
echo "conda activate TESTconda" >> ~/.bashrc | ||
source ~/.bashrc | ||
|
||
- name: Run notebook | ||
shell: bash -l {0} | ||
run: | | ||
if [[ "${{ matrix.notebook }}" == "examples/metocean_example.ipynb" || "${{ matrix.notebook }}" == "examples/WPTO_hindcast_example.ipynb" ]]; then | ||
if [[ "${{ needs.check-changes.outputs.should-run-hindcast }}" == 'true' ]]; then | ||
jupyter nbconvert --to notebook --execute --inplace --ExecutePreprocessor.timeout=${{ matrix.timeout }} "${{ matrix.notebook }}" | ||
else | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will "ExecutePreprocessor" fail each notebook test if it hits the timeout? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes each notebook in the repo has a custom timeout specified. It will fail if you go overtime. You can see some of these failures on previous commits such as the commit before "Increase ADCP timeout". |
||
echo "Skipping ${{ matrix.notebook }}" | ||
fi | ||
else | ||
jupyter nbconvert --to notebook --execute --inplace --ExecutePreprocessor.timeout=${{ matrix.timeout }} "${{ matrix.notebook }}" | ||
fi | ||
|
||
coveralls: | ||
name: Indicate completion to coveralls.io | ||
needs: | ||
|
Large diffs are not rendered by default.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does the key "include" have to do with how Actions creates a testing matrix from the test variable?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes.
The include key is a dummy key/ catch all for Actions because you can only have a single variable json at the top level.
So its called include to include all the keys I want to use.