Skip to content

Commit

Permalink
Merge pull request #49 from neutrinoceros/future_python
Browse files Browse the repository at this point in the history
ENH: future proofing
  • Loading branch information
neutrinoceros authored Oct 6, 2021
2 parents 9b7de1c + 18d63ce commit 07705b7
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 21 deletions.
2 changes: 1 addition & 1 deletion cmyt/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from .cm import *

__version__ = "0.2.0"
__version__ = "0.2.1"
22 changes: 12 additions & 10 deletions cmyt/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,25 @@
from typing import Optional
from typing import Tuple

import matplotlib
import matplotlib.pyplot as plt
import numpy as np
from colorspacious import cspace_converter
from matplotlib import __version__ as mpl_version
from matplotlib.cm import register_cmap as register_cmap_mpl
from matplotlib.colors import LinearSegmentedColormap
from more_itertools import always_iterable
from packaging.version import parse as parse_version
from packaging.version import Version

# type aliases
if sys.version_info >= (3, 8):
from typing import Final, Literal

_CMYT_PREFIX: Final[str] = "cmyt."
PrimaryColorName = Literal["blue", "green", "red"]
from typing import Final
from typing import Literal
else:
_CMYT_PREFIX: str = "cmyt."
PrimaryColorName = str
from typing_extensions import Final
from typing_extensions import Literal

_CMYT_PREFIX: Final[str] = "cmyt."
PrimaryColorName = Literal["blue", "green", "red"]
ColorDict = Dict[PrimaryColorName, List[Tuple[float, float, float]]]

# this is used in cmyt.cm to programmatically import all cmaps
Expand All @@ -43,6 +43,8 @@
)
)

MPL_VERSION = Version(matplotlib.__version__)


def prefix_name(name: str) -> str:
if not name.startswith(_CMYT_PREFIX):
Expand Down Expand Up @@ -156,10 +158,10 @@ def create_cmap_overview(
subset = cmyt_cmaps

if with_grayscale:
if parse_version(mpl_version) < parse_version("3.0.0"):
if MPL_VERSION < Version("3.0.0"):
raise RuntimeError(
"`with_grayscale=True` requires Matplotlib 3.0 or greater. "
f"Version {mpl_version} is currently installed."
f"Version {MPL_VERSION} is currently installed."
)

cmaps = sorted(prefix_name(_) for _ in always_iterable(subset))
Expand Down
8 changes: 4 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ target-version = [
'py39',
]

[tool.isort]
profile = "black"
combine_as_imports = true

[tool.pytest.ini_options]
filterwarnings = [
"error",
]
addopts = "--doctest-modules --mpl"


[tool.mypy]
python_version = "3.6"
3 changes: 2 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = cmyt
version = 0.2.0
version = 0.2.1
description = A collection of Matplotlib colormaps from the yt project
long_description = file: README.md
long_description_content_type = text/markdown
Expand Down Expand Up @@ -38,6 +38,7 @@ install_requires =
matplotlib>=2.1.0
more-itertools>=8.4
numpy>=1.13.3
typing_extensions>=3.10.0.2
python_requires = >=3.6

[options.extras_require]
Expand Down
8 changes: 3 additions & 5 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import matplotlib as mpl
import pytest
from packaging.version import parse as parse_version
from packaging.version import Version

import cmyt # noqa: F401
from cmyt.utils import create_cmap_overview

MPL_VERSION = parse_version(mpl.__version__)
from cmyt.utils import MPL_VERSION


mpl_compare = pytest.mark.mpl_image_compare(
Expand All @@ -16,7 +14,7 @@

@mpl_compare
@pytest.mark.skipif(
MPL_VERSION < parse_version("3.0"),
MPL_VERSION < Version("3.0"),
reason="Support for image cropping is significantly worse in older versions of MPL.",
)
@pytest.mark.parametrize("subset", [None, ["pastel", "arbre", "algae"]])
Expand Down

0 comments on commit 07705b7

Please sign in to comment.