Skip to content
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

MNT: upgrade linters #83

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
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
13 changes: 9 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,17 @@ jobs:
unit-test-and-typecheck:
runs-on: "ubuntu-latest"
strategy:
fail-fast: false
matrix:
python-version:
- "3.13"
- "3.12"
- "3.11"
- "3.10"
- "3.9"
pyqt-dependency:
- "PyQt6"
- "PySide6"
- "PyQt"
- "PySide"

steps:
- uses: "actions/checkout@v3"
Expand All @@ -30,17 +33,19 @@ jobs:
run: |
# Project dependencies from pyproject.toml
# NOTE: Also builds viscm. How do we avoid this?
pip install .
pip install .[${{ matrix.pyqt-dependency }}]

# Test dependencies
pip install pytest pytest-cov pytest-qt pytest-xvfb ${{ matrix.pyqt-dependency }}
pip install pytest pytest-cov pytest-qt pytest-xvfb
# pytest-qt CI dependencies: https://pytest-qt.readthedocs.io/en/latest/troubleshooting.html#github-actions
sudo apt update
sudo apt install -y \
xvfb libegl1 \
libxkbcommon-x11-0 libxcb-icccm4 libxcb-image0 libxcb-keysyms1 libxcb-randr0 libxcb-render-util0 libxcb-xinerama0 libxcb-xfixes0 x11-utils \
libxcb-cursor0

- run: pip list

- name: "Run tests"
run: "make test"
env:
Expand Down
8 changes: 4 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
repos:
- repo: "https://github.com/pre-commit/pre-commit-hooks"
rev: "v4.4.0"
rev: "v5.0.0"
hooks:
- id: "check-added-large-files"
- id: "check-vcs-permalinks"
- id: "end-of-file-fixer"

- repo: "https://github.com/charliermarsh/ruff-pre-commit"
rev: "v0.0.269"
- repo: "https://github.com/astral-sh/ruff-pre-commit"
rev: "v0.7.1"
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"
rev: "24.10.0"
hooks:
- id: "black"
22 changes: 8 additions & 14 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ classifiers = [
"Programming Language :: Python :: 3",
]

requires-python = "~=3.9"
requires-python = ">=3.9"
dependencies = [
"numpy ~=1.22",
"matplotlib ~=3.5",
"colorspacious ~=1.1",
"scipy ~=1.8",
"numpy >=1.22",
"matplotlib >=3.5",
"colorspacious >=1.1",
"scipy >=1.8",
]

[project.optional-dependencies]
Expand Down Expand Up @@ -64,13 +64,7 @@ module = [
]
ignore_missing_imports = true



[tool.black]
target-version = ["py39", "py310", "py311"]
Copy link
Author

Choose a reason for hiding this comment

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

this is not needed since black 23.1.0, see https://black.readthedocs.io/en/stable/change_log.html#id85


[tool.ruff]
target-version = "py39"
Copy link
Author

Choose a reason for hiding this comment

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

[tool.ruff.lint]
select = [
"F",
"E",
Expand All @@ -87,8 +81,8 @@ select = [
"RUF",
]

[tool.ruff.per-file-ignores]
[tool.ruff.lint.per-file-ignores]
"viscm/gui.py" = ["N8"]

[tool.ruff.mccabe]
[tool.ruff.lint.mccabe]
max-complexity = 11
1 change: 1 addition & 0 deletions test/data/option_d.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
You should have received a copy of the CC0 legalcode along with this
work. If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.
"""

from matplotlib.colors import LinearSegmentedColormap

# Used to reconstruct the colormap in viscm
Expand Down
2 changes: 1 addition & 1 deletion viscm/bezierbuilder/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"""

import numpy as np
from matplotlib.backends.qt_compat import QtCore
from matplotlib.backends.qt_compat import QtCore # type: ignore [attr-defined]
from matplotlib.lines import Line2D

from viscm.bezierbuilder.curve import curve_method
Expand Down
21 changes: 11 additions & 10 deletions viscm/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@
# matplotlib.rcParams['backend'] = "QtAgg"
# Do this first before any other matplotlib imports, to force matplotlib to
# use a Qt backend
from matplotlib.backends.qt_compat import QtCore, QtGui, QtWidgets
from matplotlib.backends.qt_compat import ( # type: ignore [attr-defined]
QtCore,
QtGui,
QtWidgets,
)
from matplotlib.colors import ListedColormap
from matplotlib.gridspec import GridSpec

Expand Down Expand Up @@ -280,9 +284,8 @@ def delta_ymax(values):
title(ax, "Perceptual derivative")
label(
ax,
"Length: {:0.1f}\nRMS deviation from flat: {:0.1f} ({:0.1f}%)".format(
arclength, rmse, 100 * rmse / arclength
),
f"Length: {arclength:0.1f}\nRMS deviation from flat: "
f"{rmse:0.1f} ({100 * rmse / arclength:0.1f}%)",
)
ax.set_ylim(-delta_ymax(-local_derivs), delta_ymax(local_derivs))
ax.get_xaxis().set_visible(False)
Expand All @@ -304,11 +307,9 @@ def delta_ymax(values):
lightness_rmse = np.std(lightness_derivs)
label(
ax,
"Length: {:0.1f}\nRMS deviation from flat: {:0.1f} ({:0.1f}%)".format(
lightness_arclength,
lightness_rmse,
100 * lightness_rmse / lightness_arclength,
),
f"Length: {lightness_arclength:0.1f}\nRMS deviation from flat: "
f"{lightness_rmse:0.1f} "
f"({100 * lightness_rmse / lightness_arclength:0.1f}%)",
)

ax.set_ylim(-delta_ymax(-lightness_derivs), delta_ymax(lightness_derivs))
Expand Down Expand Up @@ -666,7 +667,7 @@ def save_colormap(self, filepath):
hex_blob = ""
for color in rgb:
for component in color:
hex_blob += "%02x" % (int(round(component * 255)))
hex_blob += f"{int(round(component * 255)):02x}"
usage_hints = ["red-green-colorblind-safe", "greyscale-safe"]
if self.cmtype == "diverging":
usage_hints.append("diverging")
Expand Down