Skip to content

Commit 3d990c8

Browse files
authored
Merge pull request #393 from simpeg/patches
Patches
2 parents 6561482 + 386df6f commit 3d990c8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+1006
-1209
lines changed

.bumpversion.cfg

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

.github/workflows/publish.yaml

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
name: Publish on PR merge
2+
3+
on:
4+
pull_request:
5+
types: [opened, synchronize, reopened, labeled, closed]
6+
branches:
7+
- main
8+
9+
permissions:
10+
contents: write
11+
id-token: write
12+
pull-requests: write
13+
14+
jobs:
15+
update-version-and-changelog:
16+
# Run only when a release label is added (not on every push)
17+
if: |
18+
github.event.action == 'labeled' &&
19+
github.event.pull_request.merged == false && (
20+
contains(github.event.pull_request.labels.*.name, 'release:major') ||
21+
contains(github.event.pull_request.labels.*.name, 'release:minor') ||
22+
contains(github.event.pull_request.labels.*.name, 'release:patch')
23+
)
24+
runs-on: ubuntu-latest
25+
26+
steps:
27+
- name: Check out PR branch
28+
uses: actions/checkout@v4
29+
with:
30+
ref: ${{ github.head_ref }}
31+
fetch-depth: 0
32+
token: ${{ secrets.GITHUB_TOKEN }}
33+
34+
- name: Set up Python
35+
uses: actions/setup-python@v5
36+
with:
37+
python-version: "3.13"
38+
39+
- name: Install tools
40+
run: |
41+
pip install bump-my-version build pandoc
42+
sudo apt-get update
43+
sudo apt-get install -y pandoc
44+
cargo install git-cliff
45+
46+
- name: Set up Git user
47+
run: |
48+
git config --local user.email "github-actions[bot]@users.noreply.github.com"
49+
git config --local user.name "github-actions[bot]"
50+
51+
- name: Determine version bump type
52+
id: bump
53+
run: |
54+
if [[ "${{ contains(github.event.pull_request.labels.*.name, 'release:major') }}" == "true" ]]; then
55+
echo "type=major" >> $GITHUB_OUTPUT
56+
elif [[ "${{ contains(github.event.pull_request.labels.*.name, 'release:minor') }}" == "true" ]]; then
57+
echo "type=minor" >> $GITHUB_OUTPUT
58+
else
59+
echo "type=patch" >> $GITHUB_OUTPUT
60+
fi
61+
62+
- name: Bump version
63+
run: bump-my-version bump ${{ steps.bump.outputs.type }}
64+
env:
65+
BMV_ALLOW_DIRTY: "true"
66+
67+
- name: Extract version
68+
id: version
69+
run: |
70+
VERSION=$(bump-my-version show current)
71+
echo "Extracted version: $VERSION"
72+
echo "version=$VERSION" >> $GITHUB_OUTPUT
73+
74+
- name: Generate changelog
75+
run: |
76+
git cliff -o CHANGELOG.md
77+
echo "Generated changelog for version ${{ steps.version.outputs.version }}"
78+
79+
80+
- name: Commit and push changes to PR branch
81+
run: |
82+
git add .
83+
git commit -m "chore: bump version to ${{ steps.version.outputs.version }} and update changelog [skip ci]" || echo "No changes to commit"
84+
git push origin HEAD:${{ github.head_ref }}
85+
86+
publish-after-merge:
87+
# Run only after PR is merged with release labels
88+
if: |
89+
github.event.pull_request.merged == true && (
90+
contains(github.event.pull_request.labels.*.name, 'release:major') ||
91+
contains(github.event.pull_request.labels.*.name, 'release:minor') ||
92+
contains(github.event.pull_request.labels.*.name, 'release:patch')
93+
)
94+
runs-on: ubuntu-latest
95+
96+
steps:
97+
- name: Check out repository
98+
uses: actions/checkout@v4
99+
with:
100+
fetch-depth: 0
101+
102+
- name: Set up Python
103+
uses: actions/setup-python@v5
104+
with:
105+
python-version: "3.12"
106+
107+
- name: Install tools
108+
run: pip install bump-my-version build
109+
110+
- name: Extract version
111+
id: version
112+
run: |
113+
VERSION=$(bump-my-version show current)
114+
echo "version=$VERSION" >> $GITHUB_OUTPUT
115+
116+
- name: Create GitHub Release
117+
uses: softprops/action-gh-release@v2
118+
with:
119+
tag_name: v${{ steps.version.outputs.version }}
120+
name: v${{ steps.version.outputs.version }}
121+
body_path: CHANGELOG.md
122+
generate_release_notes: false
123+
124+
- name: Build package
125+
run: python -m build
126+
127+
- name: Publish to TestPyPI
128+
id: test-pypi
129+
uses: pypa/gh-action-pypi-publish@v1.13.0
130+
with:
131+
repository-url: https://test.pypi.org/legacy/
132+
skip-existing: true
133+
attestations: false
134+
135+
- name: Publish to PyPI
136+
if: steps.test-pypi.outcome == 'success'
137+
uses: pypa/gh-action-pypi-publish@v1.13.0
138+
with:
139+
skip-existing: true
Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
# Notebook Testing Workflow
2+
#
3+
# This workflow tests Jupyter notebooks and runs by default on:
4+
# - Pull requests targeting the 'main' branch
5+
#
6+
# To manually trigger this workflow on any branch:
7+
# 1. Go to Actions tab in GitHub
8+
# 2. Select "Test Notebooks" workflow
9+
# 3. Click "Run workflow" dropdown
10+
# 4. Select your branch and click "Run workflow"
11+
12+
name: Test Notebooks
13+
14+
on:
15+
pull_request:
16+
branches:
17+
- main
18+
# Allow manual triggering from the Actions tab
19+
workflow_dispatch:
20+
21+
jobs:
22+
test-notebooks:
23+
name: Notebooks (${{ matrix.python-version }}, ${{ matrix.os }})
24+
runs-on: ${{ matrix.os }}
25+
defaults:
26+
run:
27+
shell: bash
28+
strategy:
29+
fail-fast: true
30+
matrix:
31+
os: ["ubuntu-latest"]
32+
python-version: ["3.10", "3.11", "3.12"]
33+
34+
steps:
35+
- uses: actions/checkout@v4
36+
37+
- name: Install uv
38+
uses: astral-sh/setup-uv@v3
39+
with:
40+
version: "latest"
41+
42+
- name: Set up Python ${{ matrix.python-version }}
43+
run: uv python install ${{ matrix.python-version }}
44+
45+
- name: Cache MTH5 test files
46+
uses: actions/cache@v4
47+
with:
48+
path: ~/.cache/aurora
49+
key: mth5-test-files-${{ runner.os }}-${{ hashFiles('tests/conftest.py') }}
50+
restore-keys: |
51+
mth5-test-files-${{ runner.os }}-
52+
53+
- name: Create virtual environment and install dependencies
54+
run: |
55+
uv venv --python ${{ matrix.python-version }}
56+
source .venv/bin/activate
57+
uv pip install --upgrade pip
58+
uv pip install 'setuptools<68'
59+
uv pip install -e ".[dev,test]"
60+
uv pip install mt_metadata[obspy]
61+
uv pip install "mt_metadata[obspy]"
62+
uv pip install mth5
63+
uv pip install git+https://github.com/kujaku11/mth5_test_data.git
64+
# Explicitly include nbconvert & ipykernel
65+
uv pip install jupyter nbconvert nbformat ipykernel
66+
python -m ipykernel install --user --name "python3"
67+
68+
- name: Install system dependencies
69+
run: |
70+
sudo apt-get update
71+
sudo apt-get install -y pandoc
72+
73+
- name: Execute Jupyter Notebooks
74+
run: |
75+
source .venv/bin/activate
76+
# debugging: print locations of key packages
77+
python -c "import pkg_resources; print('pkg_resources location:', pkg_resources.__file__)"
78+
python -c "import setuptools; print('setuptools location:', setuptools.__file__)"
79+
80+
python << 'EOF'
81+
import nbformat
82+
import subprocess
83+
import sys
84+
85+
notebooks = [
86+
"docs/examples/dataset_definition.ipynb",
87+
"docs/examples/operate_aurora.ipynb",
88+
"docs/tutorials/pkd_units_check.ipynb",
89+
"docs/tutorials/pole_zero_fitting/lemi_pole_zero_fitting_example.ipynb",
90+
"docs/tutorials/processing_configuration.ipynb",
91+
"docs/tutorials/process_cas04_multiple_station.ipynb",
92+
"docs/tutorials/synthetic_data_processing.ipynb"
93+
]
94+
95+
failures = []
96+
97+
for nb_path in notebooks:
98+
# Update kernel spec
99+
print(f"Updating kernel in {nb_path}")
100+
try:
101+
with open(nb_path, "r", encoding="utf-8") as f:
102+
nb = nbformat.read(f, as_version=4)
103+
104+
nb["metadata"]["kernelspec"]["name"] = "python3"
105+
nb["metadata"]["kernelspec"]["display_name"] = "Python (python3)"
106+
107+
with open(nb_path, "w", encoding="utf-8") as f:
108+
nbformat.write(nb, f)
109+
print(f"✓ Updated kernel in {nb_path}")
110+
except Exception as e:
111+
print(f"✗ Failed to update kernel in {nb_path}: {e}")
112+
failures.append(nb_path)
113+
continue
114+
115+
# Execute notebook
116+
print(f"Executing {nb_path}")
117+
result = subprocess.run(
118+
["jupyter", "nbconvert", "--to", "notebook", "--execute", nb_path],
119+
capture_output=True,
120+
text=True
121+
)
122+
123+
if result.returncode != 0:
124+
print(f"✗ Failed to execute {nb_path}")
125+
print(result.stderr)
126+
failures.append(nb_path)
127+
else:
128+
print(f"✓ Successfully executed {nb_path}")
129+
130+
if failures:
131+
print("\n======= Summary =======")
132+
print(f"Failed notebooks: {failures}")
133+
sys.exit(1)
134+
else:
135+
print("\n✓ All notebooks executed successfully!")
136+
EOF

.github/workflows/tests.yaml

Lines changed: 10 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
run:
1818
shell: bash
1919
strategy:
20-
fail-fast: false
20+
fail-fast: true
2121
matrix:
2222
os: ["ubuntu-latest"]
2323
python-version: ["3.10", "3.11", "3.12"]
@@ -46,10 +46,16 @@ jobs:
4646
uv venv --python ${{ matrix.python-version }}
4747
source .venv/bin/activate
4848
uv pip install --upgrade pip
49+
uv pip install 'setuptools<68'
4950
uv pip install -e ".[dev,test]"
50-
# uv pip install mt_metadata[obspy]
51-
uv pip install "mt_metadata[obspy] @ git+https://github.com/kujaku11/mt_metadata.git@patches"
52-
uv pip install git+https://github.com/kujaku11/mth5.git@patches
51+
uv pip install mt_metadata[obspy]
52+
# uv pip install "mt_metadata[obspy] @ git+https://github.com/kujaku11/mt_metadata.git@patches"
53+
# uv pip install git+https://github.com/kujaku11/mth5.git@patches
54+
# uv pip install "mt_metadata[obspy] @ git+https://github.com/kujaku11/mt_metadata.git"
55+
# uv pip install git+https://github.com/kujaku11/mth5.git
56+
uv pip install "mt_metadata[obspy]"
57+
uv pip install mth5
58+
5359
5460
# uv pip install mth5
5561
uv pip install git+https://github.com/kujaku11/mth5_test_data.git
@@ -62,67 +68,6 @@ jobs:
6268
sudo apt-get update
6369
sudo apt-get install -y pandoc
6470
65-
- name: Set kernel and execute Jupyter Notebooks
66-
run: |
67-
source .venv/bin/activate
68-
python << 'EOF'
69-
import nbformat
70-
import subprocess
71-
import sys
72-
73-
notebooks = [
74-
"docs/examples/dataset_definition.ipynb",
75-
"docs/examples/operate_aurora.ipynb",
76-
"docs/tutorials/pkd_units_check.ipynb",
77-
"docs/tutorials/pole_zero_fitting/lemi_pole_zero_fitting_example.ipynb",
78-
"docs/tutorials/processing_configuration.ipynb",
79-
"docs/tutorials/process_cas04_multiple_station.ipynb",
80-
"docs/tutorials/synthetic_data_processing.ipynb"
81-
]
82-
83-
failures = []
84-
85-
for nb_path in notebooks:
86-
# Update kernel spec
87-
print(f"Updating kernel in {nb_path}")
88-
try:
89-
with open(nb_path, "r", encoding="utf-8") as f:
90-
nb = nbformat.read(f, as_version=4)
91-
92-
nb["metadata"]["kernelspec"]["name"] = "python3"
93-
nb["metadata"]["kernelspec"]["display_name"] = "Python (python3)"
94-
95-
with open(nb_path, "w", encoding="utf-8") as f:
96-
nbformat.write(nb, f)
97-
print(f"✓ Updated kernel in {nb_path}")
98-
except Exception as e:
99-
print(f"✗ Failed to update kernel in {nb_path}: {e}")
100-
failures.append(nb_path)
101-
continue
102-
103-
# Execute notebook
104-
print(f"Executing {nb_path}")
105-
result = subprocess.run(
106-
["jupyter", "nbconvert", "--to", "notebook", "--execute", nb_path],
107-
capture_output=True,
108-
text=True
109-
)
110-
111-
if result.returncode != 0:
112-
print(f"✗ Failed to execute {nb_path}")
113-
print(result.stderr)
114-
failures.append(nb_path)
115-
else:
116-
print(f"✓ Successfully executed {nb_path}")
117-
118-
if failures:
119-
print("\n======= Summary =======")
120-
print(f"Failed notebooks: {failures}")
121-
sys.exit(1)
122-
else:
123-
print("\n✓ All notebooks executed successfully!")
124-
EOF
125-
12671
- name: Run Tests
12772
run: |
12873
source .venv/bin/activate

0 commit comments

Comments
 (0)