Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Applied `ruff` and `black` (gh-64)
1fec42d0baf90e00d510efd76cb6006fa0c70dc4
26 changes: 26 additions & 0 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: "Check with pre-commit"
on:
- "push"
- "pull_request"

jobs:

check-with-pre-commit:
runs-on: "ubuntu-latest"
strategy:
matrix:
python-version: ["3.11"]

steps:
- uses: "actions/checkout@v3"

- name: "Set up Python ${{ matrix.python-version }}"
uses: "actions/setup-python@v4"
with:
python-version: "${{ matrix.python-version }}"

- name: "Install pre-commit"
run: "pip install pre-commit"

- name: "Run checks with pre-commit"
run: "pre-commit run --all-files --show-diff-on-failure --color always"
13 changes: 13 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
repos:
- repo: "https://github.com/charliermarsh/ruff-pre-commit"
rev: "v0.0.269"
hooks:
- id: "ruff"
# NOTE: "--exit-non-zero-on-fix" is important for CI to function
# correctly!
args: ["--fix", "--exit-non-zero-on-fix"]

- repo: "https://github.com/psf/black"
rev: "23.3.0"
hooks:
- id: "black"
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Contact:
Nathaniel J. Smith <[email protected]> and Stéfan van der Walt <[email protected]>

Dependencies:
* Python 3.7+
* Python 3.8+
* `colorspacious <https://pypi.python.org/pypi/colorspacious>`_
* Matplotlib
* NumPy
Expand Down
16 changes: 16 additions & 0 deletions doc/contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,19 @@ rm -rf dist
python -m build
pip install dist/*.whl # or `dist/*.tar.gz`
```


## Code formatting and linting

This codebase uses [black](https://black.readthedocs.io/en/stable/) and
[ruff](https://github.com/charliermarsh/ruff) to automatically format and lint the code.

[`pre-commit`](https://pre-commit.com/) is configured to run them automatically. You can
trigger this manually with `pre-commit run --all-files`.

Thanks to pre-commit, all commits should be formatted. In cases where formatting needs
to be fixed (e.g. changing config of a linter), a format-only commit should be created,
and then another commit should immediately follow which updates
`.git-blame-ignore-revs`. For example:
[1fec42d](https://github.com/matplotlib/viscm/pull/64/commits/1fec42d0baf90e00d510efd76cb6006fa0c70dc4),
[8aa7bb0](https://github.com/matplotlib/viscm/pull/64/commits/8aa7bb01440aeca6f8bbcefe0671c28f2ce284c6).
5 changes: 5 additions & 0 deletions environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,15 @@ channels:
- "conda-forge"
- "nodefaults"
dependencies:
# Runtime
- "python ~=3.11"
- "numpy ~=1.24"
- "matplotlib ~=3.7"
- "colorspacious ~=1.1"
- "scipy ~=1.10"

# Development
- "pre-commit"

- pip:
- "build ~=0.10"
12 changes: 10 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ classifiers = [
"Programming Language :: Python :: 3",
]

requires-python = "~=3.7"
requires-python = "~=3.8"
dependencies = [
"numpy",
"matplotlib",
Expand Down Expand Up @@ -45,4 +45,12 @@ packages = {find = {}}
package-data = {viscm = ["examples/*"]}


# [tool.black]
[tool.black]
target-version = ["py38", "py39", "py310", "py311"]

[tool.ruff]
target-version = "py38"
select = ["F", "E", "W", "C90", "I", "UP", "YTT", "B", "A", "C4", "T10", "RUF"]

[tool.ruff.mccabe]
max-complexity = 11
86 changes: 64 additions & 22 deletions tests.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
from viscm.gui import *
from viscm.bezierbuilder import *
import numpy as np
import matplotlib as mpl
from matplotlib.backends.qt_compat import QtGui, QtCore
from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as FigureCanvas

cms = {"viscm/examples/sample_linear.jscm",
"viscm/examples/sample_diverging.jscm",
"viscm/examples/sample_diverging_continuous.jscm"}
from viscm.bezierbuilder import json
from viscm.gui import Colormap, viscm_editor

cms = {
"viscm/examples/sample_linear.jscm",
"viscm/examples/sample_diverging.jscm",
"viscm/examples/sample_diverging_continuous.jscm",
}


def test_editor_loads_native():
Expand All @@ -16,8 +16,13 @@ def test_editor_loads_native():
data = json.loads(f.read())
cm = Colormap(None, "CatmulClark", "CAM02-UCS")
cm.load(k)
viscm = viscm_editor(uniform_space=cm.uniform_space, cmtype=cm.cmtype, method=cm.method, **cm.params)
assert viscm.name == data["name"]
viscm = viscm_editor(
uniform_space=cm.uniform_space,
cmtype=cm.cmtype,
method=cm.method,
**cm.params,
)
assert viscm.name == data["name"]

extensions = data["extensions"]["https://matplotlib.org/viscm"]
xp, yp, fixed = viscm.control_point_model.get_control_points()
Expand All @@ -26,7 +31,7 @@ def test_editor_loads_native():
assert len(extensions["xp"]) == len(xp)
assert len(extensions["yp"]) == len(yp)
assert len(xp) == len(yp)
for i in range(len(xp)):
for i in range(len(xp)):
assert extensions["xp"][i] == xp[i]
assert extensions["yp"][i] == yp[i]
assert extensions["min_Jp"] == viscm.min_Jp
Expand All @@ -35,19 +40,34 @@ def test_editor_loads_native():
assert extensions["cmtype"] == viscm.cmtype

colors = data["colors"]
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)]]
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)]
]
editor_colors = viscm.cmap_model.get_sRGB(num=256)[0].tolist()
for i in range(len(colors)):
for z in range(3):
assert colors[i][z] == np.rint(editor_colors[i][z] / 256)


# import matplotlib as mpl
# from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as FigureCanvas
# from matplotlib.backends.qt_compat import QtCore, QtGui
#
# def test_editor_add_point():
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pulled all the imports associated with this commented block into the commented block. Any reason to keep this function though?

# # Testing linear

#
# fig = plt.figure()
# figure_canvas = FigureCanvas(fig)
# linear = viscm_editor(min_Jp=40, max_Jp=60, xp=[-10, 10], yp=[0,0], figure=fig, cmtype="linear")

# linear = viscm_editor(
# min_Jp=40,
# max_Jp=60,
# xp=[-10, 10],
# yp=[0,0],
# figure=fig,
# cmtype="linear",
# )
#
# Jp, ap, bp = linear.cmap_model.get_Jpapbp(3)
# eJp, eap, ebp = [40, 50, 60], [-10, 0, 10], [0, 0, 0]
# for i in range(3):
Expand All @@ -61,12 +81,24 @@ def test_editor_loads_native():
# for i in range(3):
# for z in range(3):
# assert approxeq(rgb[i][z], ergb[i][z])


# # Testing adding a point to linear
# linear.bezier_builder.mode = "add"
# qtEvent = QtGui.QMouseEvent(QtCore.QEvent.MouseButtonPress, QtCore.QPoint(), QtCore.Qt.LeftButton, QtCore.Qt.LeftButton, QtCore.Qt.ShiftModifier)
# event = mpl.backend_bases.MouseEvent("button_press_event", figure_canvas, 0, 10, guiEvent=qtEvent)
# qtEvent = QtGui.QMouseEvent(
# QtCore.QEvent.MouseButtonPress,
# QtCore.QPoint(),
# QtCore.Qt.LeftButton,
# QtCore.Qt.LeftButton,
# QtCore.Qt.ShiftModifier,
# )
# event = mpl.backend_bases.MouseEvent(
# "button_press_event",
# figure_canvas,
# 0,
# 10,
# guiEvent=qtEvent,
# )
# event.xdata = 0
# event.ydata = 10
# event.inaxes = linear.bezier_builder.ax
Expand All @@ -87,8 +119,20 @@ def test_editor_loads_native():

# # Removing a point from linear
# linear.bezier_builder.mode = "remove"
# qtEvent = QtGui.QMouseEvent(QtCore.QEvent.MouseButtonPress, QtCore.QPoint(), QtCore.Qt.LeftButton, QtCore.Qt.LeftButton, QtCore.Qt.ControlModifier)
# event = mpl.backend_bases.MouseEvent("button_press_event", figure_canvas, 0, 10, guiEvent=qtEvent)
# qtEvent = QtGui.QMouseEvent(
# QtCore.QEvent.MouseButtonPress,
# QtCore.QPoint(),
# QtCore.Qt.LeftButton,
# QtCore.Qt.LeftButton,
# QtCore.Qt.ControlModifier,
# )
# event = mpl.backend_bases.MouseEvent(
# "button_press_event",
# figure_canvas,
# 0,
# 10,
# guiEvent=qtEvent,
# )
# event.xdata = 0
# event.ydata = 10
# event.inaxes = linear.bezier_builder.ax
Expand All @@ -102,7 +146,5 @@ def test_editor_loads_native():
# # print(linear.cmap_model.get_Jpapbp(3))



def approxeq(x, y, err=0.0001):
return abs(y - x) < err

1 change: 1 addition & 0 deletions viscm/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
# See file LICENSE.txt for license information.

from .cli import cli

cli()
Loading