Skip to content

Commit

Permalink
fix: fix deprecation warning from matplotib about accessing colormaps…
Browse files Browse the repository at this point in the history
… from mpl.cm (#451)

* fix: fix deprecation warning from mpl

* add init and update setup

* return to pytest-mypy-plugins

* fix manifest warning

* undo changes

* remove addopts changes

* fix image test again

* skip magic-class tests
  • Loading branch information
tlambert03 committed Sep 18, 2022
1 parent c8bfc04 commit 284999e
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 7 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/test_and_deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,9 @@ jobs:
- name: Test magicclass
uses: GabrielBB/xvfb-action@v1
# continue-on-error: true
# magicclass is still in development, don't fail the whole build
# this makes this much less useful... but it's better than nothing?
continue-on-error: true
with:
working-directory: magic-class
run: pytest -v --color=yes
Expand Down
1 change: 0 additions & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,3 @@ recursive-exclude docs *
recursive-exclude examples *
recursive-exclude resources *
recursive-exclude tests *
recursive-exclude typesafety *
6 changes: 5 additions & 1 deletion magicgui/_mpl_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,11 +165,15 @@ def get_cmap(name):
return name
elif isinstance(name, str):
try:
import matplotlib
import matplotlib.cm
except ImportError:
raise ImportError("must install matplotlib to specify colormaps by name")
else:
return matplotlib.cm.get_cmap(name)
try:
return matplotlib.colormaps[name]
except AttributeError:
return matplotlib.cm.get_cmap(name)
return Colormap()


Expand Down
Empty file added magicgui/py.typed
Empty file.
7 changes: 6 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name = magicgui
url = https://github.com/napari/magicgui
download_url = https://github.com/napari/magicgui
license = MIT license
license_file = LICENSE
license_files = LICENSE
description = build GUIs from functions, using magic
long_description = file: README.md, CHANGELOG.md
long_description_content_type = text/markdown
Expand Down Expand Up @@ -51,6 +51,11 @@ install_requires =
exclude =
tests

[options.package_data]
magicgui =
py.typed
*.pyi

[options.extras_require]
pyside2 =
pyside2>=5.13 ; python_version=='3.7'
Expand Down
4 changes: 1 addition & 3 deletions tests/test_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,6 @@ def test_internal_cmap():


def test_mpl_cmap():
cm = pytest.importorskip("matplotlib.cm")

# 2D uint8
image = Image()
data = np.random.randint(0, 255, (60, 60)).astype("uint8")
Expand All @@ -120,7 +118,7 @@ def test_mpl_cmap():
assert data.size - np.count_nonzero(rendered2[..., 0] == data) > 3000

# can also use an mpl colormap instance
image.set_cmap(cm.get_cmap("viridis"))
image.set_cmap(_mpl_image.get_cmap("viridis"))
rendered3 = image.image_rgba
assert isinstance(rendered3, np.ndarray)
# the colormap has been applied
Expand Down
11 changes: 11 additions & 0 deletions tests/typesafety/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import os
import sys

import pytest

if (
os.getenv("CI")
and sys.version_info[:2] == (3, 10)
and not sys.platform.startswith("linux")
):
pytest.skip("Typing tests not working here at the moment.", allow_module_level=True)

0 comments on commit 284999e

Please sign in to comment.