-
Notifications
You must be signed in to change notification settings - Fork 32
Set up ruff
& black
with pre-commit
and document usage
#64
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
cf11834
Configure black & ruff with pre-commit
mfisher87 1fec42d
Lint and format with `ruff` and `black`
mfisher87 8aa7bb0
Add git-blame-ignore-revs entry for ruff/black application
mfisher87 c51735e
Drop Python 3.7 support
mfisher87 ccf1101
Run pre-commit checks in CI
mfisher87 2c63ce5
Add example commits for our formatting best practice
mfisher87 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# Applied `ruff` and `black` (gh-64) | ||
1fec42d0baf90e00d510efd76cb6006fa0c70dc4 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(): | ||
|
@@ -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() | ||
|
@@ -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 | ||
|
@@ -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(): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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): | ||
|
@@ -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 | ||
|
@@ -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 | ||
|
@@ -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 | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,4 +4,5 @@ | |
# See file LICENSE.txt for license information. | ||
|
||
from .cli import cli | ||
|
||
cli() |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.