Skip to content

Commit 20c3289

Browse files
authored
Merge branch 'main' into readme-reproduce-viridis
2 parents 0a7ea27 + 2ff0668 commit 20c3289

16 files changed

+886
-580
lines changed

.git-blame-ignore-revs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Applied `ruff` and `black` (gh-64)
2+
1fec42d0baf90e00d510efd76cb6006fa0c70dc4

.github/workflows/check.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: "Check with pre-commit"
2+
on:
3+
- "push"
4+
- "pull_request"
5+
6+
jobs:
7+
8+
check-with-pre-commit:
9+
runs-on: "ubuntu-latest"
10+
strategy:
11+
matrix:
12+
python-version: ["3.11"]
13+
14+
steps:
15+
- uses: "actions/checkout@v3"
16+
17+
- name: "Set up Python ${{ matrix.python-version }}"
18+
uses: "actions/setup-python@v4"
19+
with:
20+
python-version: "${{ matrix.python-version }}"
21+
22+
- name: "Install pre-commit"
23+
run: "pip install pre-commit"
24+
25+
- name: "Run checks with pre-commit"
26+
run: "pre-commit run --all-files --show-diff-on-failure --color always"

.pre-commit-config.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
repos:
2+
- repo: "https://github.com/charliermarsh/ruff-pre-commit"
3+
rev: "v0.0.269"
4+
hooks:
5+
- id: "ruff"
6+
# NOTE: "--exit-non-zero-on-fix" is important for CI to function
7+
# correctly!
8+
args: ["--fix", "--exit-non-zero-on-fix"]
9+
10+
- repo: "https://github.com/psf/black"
11+
rev: "23.3.0"
12+
hooks:
13+
- id: "black"

README.rst

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ resulting visualizations and use the editor tool `on this website
1414
<https://bids.github.io/colormap/>`_.
1515

1616
Downloads:
17-
https://pypi.python.org/pypi/viscm/
17+
* https://pypi.python.org/pypi/viscm/
18+
* https://anaconda.org/conda-forge/viscm/
1819

1920
Code and bug tracker:
2021
https://github.com/matplotlib/viscm
@@ -23,16 +24,17 @@ Contact:
2324
Nathaniel J. Smith <njs@pobox.com> and Stéfan van der Walt <stefanv@berkeley.edu>
2425

2526
Dependencies:
26-
* Python 2.6+, or 3.3+
27+
* Python 3.8+
2728
* `colorspacious <https://pypi.python.org/pypi/colorspacious>`_
2829
* Matplotlib
2930
* NumPy
3031

3132
License:
32-
MIT, see LICENSE.txt for details.
33+
MIT, see `LICENSE <LICENSE>`__ for details.
3334

3435
Reproducing viridis
3536
-------------------
37+
3638
Load [viridis AKA option_d.py](https://github.com/BIDS/colormap/) using:
3739

3840
```
@@ -41,4 +43,4 @@ python -m viscm --uniform-space buggy-CAM02-UCS -m Bezier edit /tmp/option_d.py
4143

4244
Note that there was a small bug in the assumed sRGB viewing conditions
4345
while designing viridis. It does not affect the outcome by much. Also
44-
see `python -m viscm --help`.
46+
see `python -m viscm --help`.

doc/contributing.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Contributing
2+
3+
Install development dependencies:
4+
5+
```
6+
conda env create # or `mamba env create`
7+
```
8+
9+
10+
## Development install
11+
12+
```
13+
pip install -e .
14+
```
15+
16+
17+
## Testing the build
18+
19+
```
20+
rm -rf dist
21+
python -m build
22+
pip install dist/*.whl # or `dist/*.tar.gz`
23+
```
24+
25+
26+
## Code formatting and linting
27+
28+
This codebase uses [black](https://black.readthedocs.io/en/stable/) and
29+
[ruff](https://github.com/charliermarsh/ruff) to automatically format and lint the code.
30+
31+
[`pre-commit`](https://pre-commit.com/) is configured to run them automatically. You can
32+
trigger this manually with `pre-commit run --all-files`.
33+
34+
Thanks to pre-commit, all commits should be formatted. In cases where formatting needs
35+
to be fixed (e.g. changing config of a linter), a format-only commit should be created,
36+
and then another commit should immediately follow which updates
37+
`.git-blame-ignore-revs`. For example:
38+
[1fec42d](https://github.com/matplotlib/viscm/pull/64/commits/1fec42d0baf90e00d510efd76cb6006fa0c70dc4),
39+
[8aa7bb0](https://github.com/matplotlib/viscm/pull/64/commits/8aa7bb01440aeca6f8bbcefe0671c28f2ce284c6).

environment.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
name: "viscm"
2+
channels:
3+
- "conda-forge"
4+
- "nodefaults"
5+
dependencies:
6+
# Runtime
7+
- "python ~=3.11"
8+
- "numpy ~=1.24"
9+
- "matplotlib ~=3.7"
10+
- "colorspacious ~=1.1"
11+
- "scipy ~=1.10"
12+
13+
# Development
14+
- "pre-commit"
15+
16+
- pip:
17+
- "build ~=0.10"

pyproject.toml

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
[project]
2+
name = "viscm"
3+
dynamic = ["version"]
4+
description = "A colormap tool"
5+
readme = "README.rst"
6+
authors = [
7+
{name = "Nathaniel J. Smith", email = "njs@pobox.com"},
8+
{name = "Stefan van der Walt", email = "stefanv@berkeley.edu"},
9+
]
10+
classifiers = [
11+
"Development Status :: 3 - Alpha",
12+
"Intended Audience :: Developers",
13+
"Intended Audience :: Science/Research",
14+
"License :: OSI Approved :: MIT License",
15+
"Programming Language :: Python :: 3",
16+
]
17+
18+
requires-python = "~=3.8"
19+
dependencies = [
20+
"numpy",
21+
"matplotlib",
22+
"colorspacious",
23+
"scipy",
24+
]
25+
26+
[project.urls]
27+
repository = "https://github.com/matplotlib/viscm"
28+
# documentation = "https://viscm.readthedocs.io"
29+
30+
[project.license]
31+
text = "MIT"
32+
files = ["LICENSE"]
33+
34+
[project.scripts]
35+
viscm = "viscm.cli:cli"
36+
37+
38+
[build-system]
39+
requires = ["setuptools", "setuptools_scm"]
40+
build-backend = "setuptools.build_meta"
41+
42+
[tool.setuptools]
43+
zip-safe = false
44+
packages = {find = {}}
45+
package-data = {viscm = ["examples/*"]}
46+
47+
48+
[tool.black]
49+
target-version = ["py38", "py39", "py310", "py311"]
50+
51+
[tool.ruff]
52+
target-version = "py38"
53+
select = ["F", "E", "W", "C90", "I", "UP", "YTT", "B", "A", "C4", "T10", "RUF"]
54+
55+
[tool.ruff.mccabe]
56+
max-complexity = 11

setup.cfg

Lines changed: 0 additions & 5 deletions
This file was deleted.

setup.py

Lines changed: 2 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,3 @@
1-
from setuptools import setup, find_packages
2-
import sys
3-
import os.path
1+
from setuptools import setup
42

5-
import numpy as np
6-
7-
# Must be one line or PyPI will cut it off
8-
DESC = ("A colormap tool")
9-
10-
LONG_DESC = open("README.rst").read()
11-
12-
setup(
13-
name="viscm",
14-
version="0.9",
15-
description=DESC,
16-
long_description=LONG_DESC,
17-
author="Nathaniel J. Smith, Stefan van der Walt",
18-
author_email="njs@pobox.com, stefanv@berkeley.edu",
19-
url="https://github.com/bids/viscm",
20-
license="MIT",
21-
classifiers =
22-
[ "Development Status :: 3 - Alpha",
23-
"Intended Audience :: Developers",
24-
"Intended Audience :: Science/Research",
25-
"License :: OSI Approved :: MIT License",
26-
"Programming Language :: Python :: 2",
27-
"Programming Language :: Python :: 3",
28-
],
29-
packages=find_packages(),
30-
install_requires=["numpy", "matplotlib", "colorspacious", "scipy"],
31-
package_data={'viscm': ['examples/*']},
32-
)
3+
setup(use_scm_version=True)

tests.py

Lines changed: 64 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
from viscm.gui import *
2-
from viscm.bezierbuilder import *
31
import numpy as np
4-
import matplotlib as mpl
5-
from matplotlib.backends.qt_compat import QtGui, QtCore
6-
from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as FigureCanvas
72

8-
cms = {"viscm/examples/sample_linear.jscm",
9-
"viscm/examples/sample_diverging.jscm",
10-
"viscm/examples/sample_diverging_continuous.jscm"}
3+
from viscm.bezierbuilder import json
4+
from viscm.gui import Colormap, viscm_editor
5+
6+
cms = {
7+
"viscm/examples/sample_linear.jscm",
8+
"viscm/examples/sample_diverging.jscm",
9+
"viscm/examples/sample_diverging_continuous.jscm",
10+
}
1111

1212

1313
def test_editor_loads_native():
@@ -16,8 +16,13 @@ def test_editor_loads_native():
1616
data = json.loads(f.read())
1717
cm = Colormap(None, "CatmulClark", "CAM02-UCS")
1818
cm.load(k)
19-
viscm = viscm_editor(uniform_space=cm.uniform_space, cmtype=cm.cmtype, method=cm.method, **cm.params)
20-
assert viscm.name == data["name"]
19+
viscm = viscm_editor(
20+
uniform_space=cm.uniform_space,
21+
cmtype=cm.cmtype,
22+
method=cm.method,
23+
**cm.params,
24+
)
25+
assert viscm.name == data["name"]
2126

2227
extensions = data["extensions"]["https://matplotlib.org/viscm"]
2328
xp, yp, fixed = viscm.control_point_model.get_control_points()
@@ -26,7 +31,7 @@ def test_editor_loads_native():
2631
assert len(extensions["xp"]) == len(xp)
2732
assert len(extensions["yp"]) == len(yp)
2833
assert len(xp) == len(yp)
29-
for i in range(len(xp)):
34+
for i in range(len(xp)):
3035
assert extensions["xp"][i] == xp[i]
3136
assert extensions["yp"][i] == yp[i]
3237
assert extensions["min_Jp"] == viscm.min_Jp
@@ -35,19 +40,34 @@ def test_editor_loads_native():
3540
assert extensions["cmtype"] == viscm.cmtype
3641

3742
colors = data["colors"]
38-
colors = [[int(c[i:i + 2], 16) / 256 for i in range(0, 6, 2)] for c in [colors[i:i + 6] for i in range(0, len(colors), 6)]]
43+
colors = [
44+
[int(c[i : i + 2], 16) / 256 for i in range(0, 6, 2)]
45+
for c in [colors[i : i + 6] for i in range(0, len(colors), 6)]
46+
]
3947
editor_colors = viscm.cmap_model.get_sRGB(num=256)[0].tolist()
4048
for i in range(len(colors)):
4149
for z in range(3):
4250
assert colors[i][z] == np.rint(editor_colors[i][z] / 256)
4351

52+
53+
# import matplotlib as mpl
54+
# from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as FigureCanvas
55+
# from matplotlib.backends.qt_compat import QtCore, QtGui
56+
#
4457
# def test_editor_add_point():
4558
# # Testing linear
46-
59+
#
4760
# fig = plt.figure()
4861
# figure_canvas = FigureCanvas(fig)
49-
# linear = viscm_editor(min_Jp=40, max_Jp=60, xp=[-10, 10], yp=[0,0], figure=fig, cmtype="linear")
50-
62+
# linear = viscm_editor(
63+
# min_Jp=40,
64+
# max_Jp=60,
65+
# xp=[-10, 10],
66+
# yp=[0,0],
67+
# figure=fig,
68+
# cmtype="linear",
69+
# )
70+
#
5171
# Jp, ap, bp = linear.cmap_model.get_Jpapbp(3)
5272
# eJp, eap, ebp = [40, 50, 60], [-10, 0, 10], [0, 0, 0]
5373
# for i in range(3):
@@ -61,12 +81,24 @@ def test_editor_loads_native():
6181
# for i in range(3):
6282
# for z in range(3):
6383
# assert approxeq(rgb[i][z], ergb[i][z])
64-
84+
6585

6686
# # Testing adding a point to linear
6787
# linear.bezier_builder.mode = "add"
68-
# qtEvent = QtGui.QMouseEvent(QtCore.QEvent.MouseButtonPress, QtCore.QPoint(), QtCore.Qt.LeftButton, QtCore.Qt.LeftButton, QtCore.Qt.ShiftModifier)
69-
# event = mpl.backend_bases.MouseEvent("button_press_event", figure_canvas, 0, 10, guiEvent=qtEvent)
88+
# qtEvent = QtGui.QMouseEvent(
89+
# QtCore.QEvent.MouseButtonPress,
90+
# QtCore.QPoint(),
91+
# QtCore.Qt.LeftButton,
92+
# QtCore.Qt.LeftButton,
93+
# QtCore.Qt.ShiftModifier,
94+
# )
95+
# event = mpl.backend_bases.MouseEvent(
96+
# "button_press_event",
97+
# figure_canvas,
98+
# 0,
99+
# 10,
100+
# guiEvent=qtEvent,
101+
# )
70102
# event.xdata = 0
71103
# event.ydata = 10
72104
# event.inaxes = linear.bezier_builder.ax
@@ -87,8 +119,20 @@ def test_editor_loads_native():
87119

88120
# # Removing a point from linear
89121
# linear.bezier_builder.mode = "remove"
90-
# qtEvent = QtGui.QMouseEvent(QtCore.QEvent.MouseButtonPress, QtCore.QPoint(), QtCore.Qt.LeftButton, QtCore.Qt.LeftButton, QtCore.Qt.ControlModifier)
91-
# event = mpl.backend_bases.MouseEvent("button_press_event", figure_canvas, 0, 10, guiEvent=qtEvent)
122+
# qtEvent = QtGui.QMouseEvent(
123+
# QtCore.QEvent.MouseButtonPress,
124+
# QtCore.QPoint(),
125+
# QtCore.Qt.LeftButton,
126+
# QtCore.Qt.LeftButton,
127+
# QtCore.Qt.ControlModifier,
128+
# )
129+
# event = mpl.backend_bases.MouseEvent(
130+
# "button_press_event",
131+
# figure_canvas,
132+
# 0,
133+
# 10,
134+
# guiEvent=qtEvent,
135+
# )
92136
# event.xdata = 0
93137
# event.ydata = 10
94138
# event.inaxes = linear.bezier_builder.ax
@@ -102,7 +146,5 @@ def test_editor_loads_native():
102146
# # print(linear.cmap_model.get_Jpapbp(3))
103147

104148

105-
106149
def approxeq(x, y, err=0.0001):
107150
return abs(y - x) < err
108-

0 commit comments

Comments
 (0)