diff --git a/.github/workflows/install_from_wheel.yml b/.github/workflows/install_from_wheel.yml index 92125ce0..7753caea 100644 --- a/.github/workflows/install_from_wheel.yml +++ b/.github/workflows/install_from_wheel.yml @@ -35,7 +35,7 @@ jobs: sudo apt-get update sudo apt-get install -y inkscape pip install --upgrade pip - pip install wheel numpy "cython<3.0" + pip install build wheel numpy "cython<3.0" - name: Create the wheel run: python setup.py bdist_wheel diff --git a/.github/workflows/run_tests.yml b/.github/workflows/run_tests.yml index 2d56dabb..7caa453d 100644 --- a/.github/workflows/run_tests.yml +++ b/.github/workflows/run_tests.yml @@ -13,7 +13,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: [3.7, 3.8, 3.9, "3.10"] + python-version: [3.7, 3.8, 3.9, "3.10", "3.11"] max-parallel: 5 steps: @@ -35,7 +35,7 @@ jobs: sudo apt-get update sudo apt-get install -y inkscape pip install --upgrade pip - pip install wheel numpy "cython<3.0" + pip install wheel setuptools numpy "cython<3.0" # force using latest nibabel pip install -U nibabel pip install -e . --no-build-isolation diff --git a/cortex/dataset/views.py b/cortex/dataset/views.py index 8a74a468..4f65c605 100644 --- a/cortex/dataset/views.py +++ b/cortex/dataset/views.py @@ -1,14 +1,23 @@ -import os import glob import json +import os + import h5py import numpy as np from .. import options -from .braindata import BrainData, VolumeData, VertexData +from .braindata import BrainData, VertexData, VolumeData default_cmap = options.config.get("basic", "default_cmap") +# register_cmap is deprecated in matplotlib > 3.7.0 and replaced by colormaps.register +try: + from matplotlib import colormaps as cm + def register_cmap(cmap): + return cm.register(cmap) +except ImportError: + from matplotlib.cm import register_cmap + def normalize(data): if isinstance(data, tuple): @@ -193,7 +202,8 @@ def _write_hdf(self, h5, name="data", data=None, xfmname=None): def get_cmapdict(self): """Returns a dictionary with cmap information.""" - from matplotlib import colors, pyplot as plt + from matplotlib import colors + from matplotlib import pyplot as plt try: # plt.get_cmap accepts: @@ -206,18 +216,19 @@ def get_cmapdict(self): cmapdir = options.config.get('webgl', 'colormaps') colormaps = glob.glob(os.path.join(cmapdir, "*.png")) colormaps = dict(((os.path.split(c)[1][:-4], c) for c in colormaps)) - if not self.cmap in colormaps: + if self.cmap not in colormaps: raise ValueError('Unkown color map %s' % self.cmap) I = plt.imread(colormaps[self.cmap]) - cmap = colors.ListedColormap(np.squeeze(I)) + name = self.cmap if isinstance(self.cmap, str) else self.cmap.name + cmap = colors.ListedColormap(np.squeeze(I), name=name) # Register colormap to matplotlib to avoid loading it again - plt.register_cmap(self.cmap, cmap) + register_cmap(cmap) return dict(cmap=cmap, vmin=self.vmin, vmax=self.vmax) @property def raw(self): - from matplotlib import colors, cm + from matplotlib import cm, colors cmap = self.get_cmapdict()['cmap'] # Normalize colors according to vmin, vmax @@ -398,5 +409,5 @@ def u(s, encoding='utf8'): return s -from .viewRGB import VolumeRGB, VertexRGB, Colors -from .view2D import Volume2D, Vertex2D +from .viewRGB import Colors, VertexRGB, VolumeRGB +from .view2D import Vertex2D, Volume2D diff --git a/cortex/utils.py b/cortex/utils.py index c5d5315d..ce8c4327 100644 --- a/cortex/utils.py +++ b/cortex/utils.py @@ -23,6 +23,14 @@ from .testing_utils import INKSCAPE_VERSION from .volume import anat2epispace +# register_cmap is deprecated in matplotlib > 3.7.0 and replaced by colormaps.register +try: + from matplotlib import colormaps as cm + def register_cmap(cmap): + return cm.register(cmap) +except ImportError: + from matplotlib.cm import register_cmap + class DocLoader(object): def __init__(self, func, mod, package): @@ -1000,9 +1008,9 @@ def get_cmap(name): colormaps = dict((c[:-4], os.path.join(cmapdir, c)) for c in colormaps) if name in colormaps: I = plt.imread(colormaps[name]) - cmap = colors.ListedColormap(np.squeeze(I)) + cmap = colors.ListedColormap(np.squeeze(I), name=name) try: - plt.cm.register_cmap(name,cmap) + register_cmap(cmap) except: print(f"Color map {name} is already registered.") else: diff --git a/pyproject.toml b/pyproject.toml index bad27b4f..fe641d85 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,7 +1,8 @@ [build-system] # Minimum requirements for the build system to execute, according to PEP518 # specification. -requires = ["numpy", "cython<3.0", "setuptools", "wheel"] +requires = ["setuptools", "build", "numpy", "cython<3.0", "wheel"] +build-backend = "setuptools.build_meta" [tool.codespell] skip = '.git,*.pdf,*.svg,*.css,*.min.*,*.gii,resources,OpenCTM-1.0.3,filestore,build,_build' diff --git a/requirements.txt b/requirements.txt index fce8407f..acfa10d6 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,4 @@ +setuptools future numpy scipy