Skip to content

chore: migrate linting to ruff from black #160

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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

krishnanand5
Copy link
Collaborator

Description

This PR aims to migrate the linting for py_maidr from Black to Ruff

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • Any dependent changes have been merged and published in downstream modules

Pull Request

Description

This PR aims to establish ruff as the new linting dependancy, moving on from black

Related Issues

Closes #159

Changes Made

The following files have been changed as a result of this PR:

  1. Updated pyproject.toml to use ruff instead of black whilst retaining configurations from black.
  2. Modified ci.yml to use ruff instead of black
  3. Modified release.yml to use ruff instead of black
  4. Modified pre-commit-config.yaml to use ruff instead of black
  5. Modified .vscode/settings.json and .vscode/extensions.json to call upon ruff instead of black and removed its configurations

Checklist

  • I have read the Contributor Guidelines.
  • I have performed a self-review of my own code and ensured it follows the project's coding standards.
  • I have tested the changes locally following ManualTestingProcess.md, and all tests related to this pull request pass.
  • I have commented my code, particularly in hard-to-understand areas.
  • I have updated the documentation, if applicable.
  • I have added appropriate unit tests, if applicable.

@krishnanand5
Copy link
Collaborator Author

These lint errors have been thrown by ruff

Downloading ruff from "https://github.com/astral-sh/ruff/releases/download/0.11.5/ruff-x86_64-unknown-linux-gnu.tar.gz" ...
/usr/bin/tar xz --warning=no-unknown-keyword --overwrite -C /home/runner/work/_temp/dab16bde-a1a0-4a36-ad65-fd2775449271 -f /home/runner/work/_temp/ab12f1a9-d1[8](https://github.com/xability/py-maidr/actions/runs/14497614342/job/40669245037?pr=160#step:3:9)5-448d-b3a3-c95026066bb3
Added /opt/hostedtoolcache/ruff/0.11.5/x86_64 to the path
Set RUFF_OUTPUT_FORMAT to github
Successfully installed ruff version 0.11.5
/opt/hostedtoolcache/ruff/0.11.5/x86_64/ruff check --diff /home/runner/work/py-maidr/py-maidr
--- example/box/example_box_plot.ipynb:cell 1
+++ example/box/example_box_plot.ipynb:cell 1
--- example/box/example_box_plot.ipynb:cell 2
+++ example/box/example_box_plot.ipynb:cell 2
--- example/box/example_box_plot.ipynb:cell 3
+++ example/box/example_box_plot.ipynb:cell 3
--- example/box/example_box_plot.ipynb:cell 4
+++ example/box/example_box_plot.ipynb:cell 4
@@ -1,4 +1,3 @@
-import matplotlib.pyplot as plt
 import maidr
 import seaborn as sns
 
--- example/box/example_box_plot.ipynb:cell 5
+++ example/box/example_box_plot.ipynb:cell 5
--- example/box/example_box_plot.ipynb:cell 6
+++ example/box/example_box_plot.ipynb:cell 6

--- maidr/patch/highlight.py
+++ maidr/patch/highlight.py
@@ -5,7 +5,6 @@
 import wrapt
 from matplotlib.backends.backend_svg import XMLWriter
 from matplotlib.collections import PathCollection, QuadMesh
-from matplotlib.figure import Figure
 from matplotlib.lines import Line2D
 from matplotlib.patches import Patch
 

--- maidr/patch/barplot.py
+++ maidr/patch/barplot.py
@@ -1,[9](https://github.com/xability/py-maidr/actions/runs/14497614342/job/40669245037?pr=160#step:3:10) +1,7 @@
 from __future__ import annotations
 
-from numbers import Number
 from typing import Any, Callable, Dict, Tuple, Union
 
-import numpy as np
 import wrapt
 from matplotlib.axes import Axes
 from matplotlib.container import BarContainer

--- maidr/core/maidr.py
+++ maidr/core/maidr.py
@@ -[11](https://github.com/xability/py-maidr/actions/runs/14497614342/job/40669245037?pr=160#step:3:12),7 +11,6 @@
 from htmltools import HTML, HTMLDocument, Tag, tags
 from lxml import etree
 from matplotlib.figure import Figure
-from matplotlib.patches import Rectangle
 
 from maidr.core.context_manager import HighlightContextManager
 from maidr.core.enum.maidr_key import MaidrKey

Error: The process '/opt/hostedtoolcache/ruff/0.11.5/x86_64/ruff' failed with exit code 1

Should these be fixed or has any configuration not been carried over from black?

As per ruff's documentation, this would be the default configuration

@jooyoungseo jooyoungseo requested a review from Copilot April 16, 2025 17:05
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot reviewed 5 out of 7 changed files in this pull request and generated 1 comment.

Files not reviewed (2)
  • .vscode/extensions.json: Language not supported
  • .vscode/settings.json: Language not supported
Comments suppressed due to low confidence (1)

.pre-commit-config.yaml:5

  • Verify if 'ruff-format' is the correct hook id as specified by the ruff-pre-commit documentation, or if it should be updated to simply 'ruff' for consistency.
      - id: ruff-format

@krishnanand5
Copy link
Collaborator Author

I checked the suggestion provided by copilot locally using netkos/act. Looks like --check is not a valid argument for running ruff. Hence, discarding the suggestion.

(py-maidr) ➜  py_maidr git:(chore/migrate-to-ruff) ✗ act -j lint  --container-architecture linux/amd64     
INFO[0000] Using docker host 'unix:///var/run/docker.sock', and daemon socket 'unix:///var/run/docker.sock' 
[Test & Release/lint] 🚀  Start image=catthehacker/ubuntu:act-latest
[CI/lint            ] 🚀  Start image=catthehacker/ubuntu:act-latest
[CI/lint            ]   🐳  docker pull image=catthehacker/ubuntu:act-latest platform=linux/amd64 username= forcePull=true
[Test & Release/lint]   🐳  docker pull image=catthehacker/ubuntu:act-latest platform=linux/amd64 username= forcePull=true
[CI/lint            ] using DockerAuthConfig authentication for docker pull
[Test & Release/lint] using DockerAuthConfig authentication for docker pull
[CI/lint            ]   🐳  docker create image=catthehacker/ubuntu:act-latest platform=linux/amd64 entrypoint=["tail" "-f" "/dev/null"] cmd=[] network="host"
[Test & Release/lint]   🐳  docker create image=catthehacker/ubuntu:act-latest platform=linux/amd64 entrypoint=["tail" "-f" "/dev/null"] cmd=[] network="host"
[CI/lint            ]   🐳  docker run image=catthehacker/ubuntu:act-latest platform=linux/amd64 entrypoint=["tail" "-f" "/dev/null"] cmd=[] network="host"
[Test & Release/lint]   🐳  docker run image=catthehacker/ubuntu:act-latest platform=linux/amd64 entrypoint=["tail" "-f" "/dev/null"] cmd=[] network="host"
[CI/lint            ]   🐳  docker exec cmd=[node --no-warnings -e console.log(process.execPath)] user= workdir=
[Test & Release/lint]   🐳  docker exec cmd=[node --no-warnings -e console.log(process.execPath)] user= workdir=
[Test & Release/lint]   ☁  git clone 'https://github.com/astral-sh/ruff-action' # ref=v3
[CI/lint            ]   ☁  git clone 'https://github.com/astral-sh/ruff-action' # ref=v3
[Test & Release/lint] ⭐ Run Main actions/checkout@v4
[Test & Release/lint]   🐳  docker cp src=/Users/krishnaanandan/Desktop/maidr_krishna/py_maidr/. dst=/Users/krishnaanandan/Desktop/maidr_krishna/py_maidr
[CI/lint            ] ⭐ Run Main actions/checkout@v4
[CI/lint            ]   🐳  docker cp src=/Users/krishnaanandan/Desktop/maidr_krishna/py_maidr/. dst=/Users/krishnaanandan/Desktop/maidr_krishna/py_maidr
[Test & Release/lint]   ✅  Success - Main actions/checkout@v4
[CI/lint            ]   ✅  Success - Main actions/checkout@v4
[Test & Release/lint] ⭐ Run Main Check format with ruff
[Test & Release/lint]   🐳  docker cp src=/Users/krishnaanandan/.cache/act/astral-sh-ruff-action@v3/ dst=/var/run/act/actions/astral-sh-ruff-action@v3/
[CI/lint            ] ⭐ Run Main Check format with ruff
[CI/lint            ]   🐳  docker cp src=/Users/krishnaanandan/.cache/act/astral-sh-ruff-action@v3/ dst=/var/run/act/actions/astral-sh-ruff-action@v3/
[Test & Release/lint]   🐳  docker exec cmd=[/opt/acttoolcache/node/18.20.8/x64/bin/node /var/run/act/actions/astral-sh-ruff-action@v3/dist/ruff-action/index.js] user= workdir=
[CI/lint            ]   🐳  docker exec cmd=[/opt/acttoolcache/node/18.20.8/x64/bin/node /var/run/act/actions/astral-sh-ruff-action@v3/dist/ruff-action/index.js] user= workdir=
[Test & Release/lint]   💬  ::debug::Resolving latest...
[CI/lint            ]   💬  ::debug::Resolving latest...
[CI/lint            ]   💬  ::debug::isExplicit: 0.11.6
[CI/lint            ]   💬  ::debug::explicit? true
[CI/lint            ]   💬  ::debug::Version 0.11.6 is an explicit version.
[CI/lint            ]   💬  ::debug::Trying to get ruff from tool cache for 0.11.6...
[CI/lint            ]   💬  ::debug::isExplicit: 0.11.5
[CI/lint            ]   💬  ::debug::explicit? true
[CI/lint            ]   💬  ::debug::Cached versions: 0.11.5
[CI/lint            ]   💬  ::debug::evaluating 1 versions
[Test & Release/lint]   💬  ::debug::isExplicit: 0.11.6
[Test & Release/lint]   💬  ::debug::explicit? true
[Test & Release/lint]   💬  ::debug::Version 0.11.6 is an explicit version.
[Test & Release/lint]   💬  ::debug::Trying to get ruff from tool cache for 0.11.6...
[Test & Release/lint]   💬  ::debug::isExplicit: 0.11.5
[Test & Release/lint]   💬  ::debug::explicit? true
[Test & Release/lint]   💬  ::debug::Cached versions: 0.11.5
[Test & Release/lint]   💬  ::debug::evaluating 1 versions
[CI/lint            ]   💬  ::debug::match not found
[Test & Release/lint]   💬  ::debug::match not found
[CI/lint            ]   💬  ::debug::isExplicit: 0.11.6
[Test & Release/lint]   💬  ::debug::isExplicit: 0.11.6
[CI/lint            ]   💬  ::debug::explicit? true
[CI/lint            ]   💬  ::debug::checking cache: /opt/hostedtoolcache/ruff/0.11.6/x86_64
[CI/lint            ]   💬  ::debug::not found
| Downloading ruff from "https://github.com/astral-sh/ruff/releases/download/0.11.6/ruff-x86_64-unknown-linux-gnu.tar.gz" ...
[Test & Release/lint]   💬  ::debug::explicit? true
[Test & Release/lint]   💬  ::debug::checking cache: /opt/hostedtoolcache/ruff/0.11.6/x86_64
[Test & Release/lint]   💬  ::debug::not found
| Downloading ruff from "https://github.com/astral-sh/ruff/releases/download/0.11.6/ruff-x86_64-unknown-linux-gnu.tar.gz" ...
[CI/lint            ]   💬  ::debug::Downloading https://github.com/astral-sh/ruff/releases/download/0.11.6/ruff-x86_64-unknown-linux-gnu.tar.gz
[CI/lint            ]   💬  ::debug::Destination /tmp/6d70ec9c-e3a2-444b-9c81-bb117f457b9a
[Test & Release/lint]   💬  ::debug::Downloading https://github.com/astral-sh/ruff/releases/download/0.11.6/ruff-x86_64-unknown-linux-gnu.tar.gz
[Test & Release/lint]   💬  ::debug::Destination /tmp/09714f5d-9470-43b6-951b-2a324b05b2f9
[Test & Release/lint]   💬  ::debug::download complete
[Test & Release/lint]   💬  ::debug::Checksum not provided. Checking known checksums.
[Test & Release/lint]   💬  ::debug::No known checksum found for x86_64-unknown-linux-gnu-0.11.6.
[Test & Release/lint]   💬  ::debug::Checking tar --version
[CI/lint            ]   💬  ::debug::download complete
[CI/lint            ]   💬  ::debug::Checksum not provided. Checking known checksums.
[CI/lint            ]   💬  ::debug::No known checksum found for x86_64-unknown-linux-gnu-0.11.6.
[CI/lint            ]   💬  ::debug::Checking tar --version
[CI/lint            ]   💬  ::debug::tar (GNU tar) 1.34%0ACopyright (C) 2021 Free Software Foundation, Inc.%0ALicense GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>.%0AThis is free software: you are free to change and redistribute it.%0AThere is NO WARRANTY, to the extent permitted by law.%0A%0AWritten by John Gilmore and Jay Fenlason.
[Test & Release/lint]   💬  ::debug::tar (GNU tar) 1.34%0ACopyright (C) 2021 Free Software Foundation, Inc.%0ALicense GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>.%0AThis is free software: you are free to change and redistribute it.%0AThere is NO WARRANTY, to the extent permitted by law.%0A%0AWritten by John Gilmore and Jay Fenlason.
| [command]/usr/bin/tar xz --warning=no-unknown-keyword --overwrite -C /tmp/e8ad121e-24be-4c65-9c04-fe0c5322a5ab -f /tmp/6d70ec9c-e3a2-444b-9c81-bb117f457b9a
| [command]/usr/bin/tar xz --warning=no-unknown-keyword --overwrite -C /tmp/cd0712d3-3ad6-4d5c-8872-3c296c0f2c53 -f /tmp/09714f5d-9470-43b6-951b-2a324b05b2f9
[Test & Release/lint]   💬  ::debug::Caching tool ruff 0.11.6 x86_64
[Test & Release/lint]   💬  ::debug::source dir: /tmp/cd0712d3-3ad6-4d5c-8872-3c296c0f2c53/ruff-x86_64-unknown-linux-gnu
[Test & Release/lint]   💬  ::debug::destination /opt/hostedtoolcache/ruff/0.11.6/x86_64
[CI/lint            ]   💬  ::debug::Caching tool ruff 0.11.6 x86_64
[CI/lint            ]   💬  ::debug::source dir: /tmp/e8ad121e-24be-4c65-9c04-fe0c5322a5ab/ruff-x86_64-unknown-linux-gnu
[CI/lint            ]   💬  ::debug::destination /opt/hostedtoolcache/ruff/0.11.6/x86_64
[CI/lint            ]   💬  ::debug::finished caching tool
[Test & Release/lint]   💬  ::debug::finished caching tool
| Added /opt/hostedtoolcache/ruff/0.11.6/x86_64 to the path
| Added /opt/hostedtoolcache/ruff/0.11.6/x86_64 to the path
| Set RUFF_OUTPUT_FORMAT to github
[CI/lint            ]   ❓ add-matcher /run/act/actions/astral-sh-ruff-action@v3/.github/matchers/check.json
[CI/lint            ]   ❓ add-matcher /run/act/actions/astral-sh-ruff-action@v3/.github/matchers/format.json
| Successfully installed ruff version 0.11.6
| Set RUFF_OUTPUT_FORMAT to github
[Test & Release/lint]   ❓ add-matcher /run/act/actions/astral-sh-ruff-action@v3/.github/matchers/check.json
[Test & Release/lint]   ❓ add-matcher /run/act/actions/astral-sh-ruff-action@v3/.github/matchers/format.json
| Successfully installed ruff version 0.11.6
| [command]/opt/hostedtoolcache/ruff/0.11.6/x86_64/ruff --check --diff /Users/krishnaanandan/Desktop/maidr_krishna/py_maidr
| [command]/opt/hostedtoolcache/ruff/0.11.6/x86_64/ruff --check --diff /Users/krishnaanandan/Desktop/maidr_krishna/py_maidr
| error: unexpected argument '--check' found
| 
| Usage: ruff [OPTIONS] <COMMAND>
| 
| For more information, try '--help'.
[CI/lint            ]   ❗  ::error::The process '/opt/hostedtoolcache/ruff/0.11.6/x86_64/ruff' failed with exit code 2
| error: unexpected argument '--check' found
| 
| Usage: ruff [OPTIONS] <COMMAND>
| 
| For more information, try '--help'.
[Test & Release/lint]   ❗  ::error::The process '/opt/hostedtoolcache/ruff/0.11.6/x86_64/ruff' failed with exit code 2
[CI/lint            ]   ❌  Failure - Main Check format with ruff
[Test & Release/lint]   ❌  Failure - Main Check format with ruff
[CI/lint            ]   ⚙  ::set-env:: RUFF_OUTPUT_FORMAT=github
[Test & Release/lint]   ⚙  ::set-env:: RUFF_OUTPUT_FORMAT=github
[Test & Release/lint]   ⚙  ::set-output:: ruff-version=0.11.6
[CI/lint            ]   ⚙  ::set-output:: ruff-version=0.11.6
[Test & Release/lint]   ⚙  ::add-path:: /opt/hostedtoolcache/ruff/0.11.6/x86_64
[Test & Release/lint] exitcode '1': failure
[Test & Release/lint] 🏁  Job failed
[CI/lint            ]   ⚙  ::add-path:: /opt/hostedtoolcache/ruff/0.11.6/x86_64
[CI/lint            ] exitcode '1': failure
[CI/lint            ] 🏁  Job failed
Error: Job 'lint' failed
(py-maidr) ➜  py_maidr git:(chore/migrate-to-ruff) ✗

@krishnanand5 krishnanand5 added the dependencies Pull requests that update a dependency file label May 1, 2025
@krishnanand5 krishnanand5 self-assigned this May 1, 2025
@krishnanand5 krishnanand5 force-pushed the chore/migrate-to-ruff branch 2 times, most recently from 56a5e34 to 8a30662 Compare May 1, 2025 15:51
@dakshpokar
Copy link
Contributor

@krishnanand5 CI was failing due to some unused imports, just fixed those in that PR.

@krishnanand5
Copy link
Collaborator Author

This PR can be open until #179 is merged. Based on uv migration, relevant ruff migration points need to be handled.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dependencies Pull requests that update a dependency file
Projects
None yet
Development

Successfully merging this pull request may close these issues.

chore: migrate linting to ruff
2 participants