Skip to content

Commit 17151fb

Browse files
kozo2claude
andcommitted
Fix plot_world crash with matplotlib 3.6+ and bump version to 1.2.2
Replace deprecated fig.gca(projection='3d') with fig.add_subplot(111, projection='3d'), add regression test, and update release workflow to auto-publish on version bump. Closes #100 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent f38da95 commit 17151fb

7 files changed

Lines changed: 47 additions & 7 deletions

File tree

.github/workflows/release.yml

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,41 @@
11
name: Upload Python Package
22

33
on:
4-
release:
5-
types: [created]
4+
push:
5+
branches: [master]
6+
paths:
7+
- 'setup.py'
68

79
jobs:
810
deploy:
911
runs-on: ubuntu-latest
1012
steps:
11-
- uses: actions/checkout@v2
13+
- uses: actions/checkout@v4
14+
- name: Check version bump
15+
id: version_check
16+
run: |
17+
NEW_VERSION=$(python -c "import re; print(re.search(r\"version='([^']+)'\", open('setup.py').read()).group(1))")
18+
echo "version=$NEW_VERSION" >> "$GITHUB_OUTPUT"
19+
pip install ecell4 2>/dev/null && \
20+
CURRENT_VERSION=$(pip show ecell4 | grep ^Version | awk '{print $2}') || \
21+
CURRENT_VERSION="0.0.0"
22+
if [ "$NEW_VERSION" = "$CURRENT_VERSION" ]; then
23+
echo "changed=false" >> "$GITHUB_OUTPUT"
24+
else
25+
echo "changed=true" >> "$GITHUB_OUTPUT"
26+
fi
1227
- name: Set up Python
13-
uses: actions/setup-python@v1
28+
if: steps.version_check.outputs.changed == 'true'
29+
uses: actions/setup-python@v5
1430
with:
1531
python-version: '3.x'
1632
- name: Install dependencies
33+
if: steps.version_check.outputs.changed == 'true'
1734
run: |
1835
python -m pip install --upgrade pip
1936
pip install setuptools wheel twine
2037
- name: Build and publish
38+
if: steps.version_check.outputs.changed == 'true'
2139
env:
2240
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
2341
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,7 @@ docs/build
77
.cache/
88
.idea/
99
.pytest_cache/
10+
*.h5
11+
.claude/
12+
tutorial*.py
13+
tutorial*.ipynb

ecell4/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
from ecell4.util import *
22

3-
__version__ = '1.2.0'
3+
__version__ = '1.2.2'

ecell4/plotting/_matplotlib.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ def __prepare_mplot3d_with_matplotlib(
176176
import matplotlib.pyplot as plt
177177

178178
fig = plt.figure(figsize=(figsize, figsize))
179-
ax = fig.gca(projection='3d')
179+
ax = fig.add_subplot(111, projection='3d')
180180

181181
if wireframe:
182182
ax.w_xaxis.set_pane_color((0, 0, 0, 0))

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
setup(
1313
name='ecell4',
14-
version='1.2.1',
14+
version='1.2.2',
1515
packages=['ecell4', 'ecell4.util', 'ecell4.extra', 'ecell4.datasource', 'ecell4.mca', 'ecell4.plotting'],
1616
package_data = {"ecell4.util": [
1717
"templates/init_ipynb.js", "templates/init_cyjs.js", "templates/template.html",

tests/__init__.py

Whitespace-only changes.

tests/test_matplotlib.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
"""Regression test for https://github.com/ecell/ecell4/issues/100
2+
3+
fig.gca(projection='3d') was removed in matplotlib 3.6+.
4+
"""
5+
import matplotlib
6+
matplotlib.use('Agg')
7+
8+
import matplotlib.pyplot as plt
9+
from mpl_toolkits.mplot3d import Axes3D
10+
from ecell4.plotting._matplotlib import __prepare_mplot3d_with_matplotlib
11+
12+
13+
def test_prepare_mplot3d_returns_3d_axes():
14+
wrange = {'x': (0, 1), 'y': (0, 1), 'z': (0, 1)}
15+
fig, ax = __prepare_mplot3d_with_matplotlib(
16+
wrange, figsize=6, grid=True, wireframe=False, angle=None, noaxis=False)
17+
assert isinstance(ax, Axes3D)
18+
plt.close(fig)

0 commit comments

Comments
 (0)