diff --git a/cmocean/cm.py b/cmocean/cm.py index 7ffe563..e70984c 100644 --- a/cmocean/cm.py +++ b/cmocean/cm.py @@ -38,8 +38,11 @@ def _register_cmap(cmap, *, name): if MPL_VERSION >= Version("3.5"): mpl.colormaps.register(cmap, name=name) else: - # deprecated API - mpl.cm.register_cmap(name=name, cmap=cmap) + # deprecated API. `matplotlib.cm` is imported here because importing + # `matplotlib` alone does not make the submodule available, so this + # branch used to raise an AttributeError. + import matplotlib.cm + matplotlib.cm.register_cmap(name=name, cmap=cmap) # add colormaps and reversed to dictionary for cmapname in cmapnames: @@ -53,11 +56,11 @@ def _register_cmap(cmap, *, name): rgb_with_alpha = np.zeros((rgb.shape[0],4)) rgb_with_alpha[:,:3] = rgb rgb_with_alpha[:,3] = 1. #set alpha channel to 1 - reg_map = colors.ListedColormap(rgb_with_alpha, N=rgb.shape[0]) + reg_map = colors.ListedColormap(rgb_with_alpha) _register_cmap(reg_map, name=f'cmo.{cmapname}') # Register the reversed map - reg_map_r = colors.ListedColormap(rgb_with_alpha[::-1,:], N=rgb.shape[0]) + reg_map_r = colors.ListedColormap(rgb_with_alpha[::-1,:]) _register_cmap(reg_map_r, name=f'cmo.{cmapname}_r') # Load inverted cmaps @@ -71,9 +74,9 @@ def _register_cmap(cmap, *, name): rgb_with_alpha[:,3] = 1. #set alpha channel to 1 # Register inverted cmaps - reg_map_i = colors.ListedColormap(rgb_with_alpha, N=rgb_i.shape[0]) + reg_map_i = colors.ListedColormap(rgb_with_alpha) _register_cmap(reg_map_i, name=f'cmo.{cmapname}_i') - reg_map_r_i = colors.ListedColormap(rgb_with_alpha[::-1,:], N=rgb_i.shape[0]) + reg_map_r_i = colors.ListedColormap(rgb_with_alpha[::-1,:]) _register_cmap(reg_map_r_i, name=f'cmo.{cmapname}_r_i') # order shouldn't matter diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..b2fcc25 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["setuptools>=64"] +build-backend = "setuptools.build_meta" diff --git a/setup.py b/setup.py index 95d68bc..5c2c25b 100644 --- a/setup.py +++ b/setup.py @@ -4,22 +4,11 @@ setup.py for cmocean """ -import sys from setuptools import setup # to support "develop" mode -from setuptools.command.test import test as TestCommand - -class PyTest(TestCommand): - def finalize_options(self): - TestCommand.finalize_options(self) - self.verbose = True - - def run_tests(self): - import pytest - errno = pytest.main(self.test_args) - sys.exit(errno) extras_require={ 'plots': ["colorspacious", "viscm"], + 'test': ["pytest"], } # # in case I add more later # extras_require['complete'] = sorted(set(sum(extras_require.values(), []))) @@ -44,9 +33,7 @@ def run_tests(self): ext_package='cmocean', scripts = [], keywords = ['colormaps', 'oceanography', 'plotting', 'visualization'], - setup_requires=['setuptools'], install_requires=['matplotlib', 'numpy', 'packaging'], - tests_require=['pytest'], python_requires=">=3.8", extras_require=extras_require )