Skip to content

Commit e046eb4

Browse files
authored
style: Replace black . with ruff format for improved user experience to match grass repo (#1298)
1 parent 74cefd6 commit e046eb4

File tree

29 files changed

+235
-270
lines changed

29 files changed

+235
-270
lines changed

.github/workflows/black.yml .github/workflows/linting.yml

+12-12
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
name: Python Black Formatting
2+
name: Linting & formatting
33
on:
44
push:
55
branches:
@@ -13,20 +13,20 @@ concurrency:
1313
${{ github.ref_protected != true }}
1414
env:
1515
# renovate: datasource=python-version depName=python
16-
PYTHON_VERSION: "3.12"
17-
# renovate: datasource=pypi depName=black
18-
BLACK_VERSION: "25.1.0"
16+
PYTHON_VERSION: "3.13"
17+
# renovate: datasource=pypi depName=ruff
18+
RUFF_VERSION: "0.9.4"
1919
permissions: {}
2020
jobs:
21-
run-black:
22-
name: Black formatting
21+
run-ruff:
22+
name: Ruff formatting
2323

2424
# Using matrix just to get variables which are not environmental variables
2525
# and also to sync with other workflows which use matrix.
2626
strategy:
2727
matrix:
2828
include:
29-
- os: ubuntu-22.04
29+
- os: ubuntu-24.04
3030

3131
runs-on: ${{ matrix.os }}
3232
steps:
@@ -42,15 +42,15 @@ jobs:
4242
- name: Install
4343
run: |
4444
python -m pip install --upgrade pip
45-
pip install black[jupyter]==${{ env.BLACK_VERSION }}
45+
pip install ruff==${{ env.RUFF_VERSION }}
4646
47-
- name: Run Black
47+
- name: Run ruff formatter
4848
run: |
49-
black .
49+
ruff format
5050
- name: Create and uploads code suggestions to apply
5151
id: diff
5252
uses: OSGeo/grass/.github/actions/create-upload-suggestions@main
5353
with:
54-
tool-name: black
54+
tool-name: ruff
5555
# To keep repo's file structure in formatted changes artifact
56-
extra-upload-changes: .clang-format
56+
extra-upload-changes: pyproject.toml

.github/workflows/post-pr-reviews.yml

+25-5
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ name: Post PR code suggestions
33

44
on:
55
workflow_run:
6-
workflows: ["ClangFormat Check", "Python Black Formatting"]
6+
workflows:
7+
["ClangFormat Check", "Python Black Formatting", "Linting & formatting"]
78
types:
89
- completed
910
permissions: {}
@@ -34,19 +35,20 @@ jobs:
3435
for tool_name in $INPUT_TOOL_NAMES
3536
do
3637
INPUT_TOOL_NAME_FILE="diff-${tool_name}.patch"
37-
echo "Checking if tool ${tool_name} left suggestions in ${INPUT_TOOL_NAME_FILE}"
38+
echo "Checking if tool ${tool_name} left suggestions in ${INPUT_TOOL_NAME_FILE}..."
3839
if [[ -f "${INPUT_TOOL_NAME_FILE}" ]]; then
39-
echo "${INPUT_TOOL_NAME_FILE} was found for tool ${tool_name}"
40+
echo " ${INPUT_TOOL_NAME_FILE} was found for tool ${tool_name}"
4041
echo "$tool_name=true" >> "${GITHUB_OUTPUT}"
4142
else
42-
echo "${INPUT_TOOL_NAME_FILE} was not found for tool ${tool_name}"
43+
echo " ${INPUT_TOOL_NAME_FILE} was not found for tool ${tool_name}"
4344
echo "$tool_name=false" >> "${GITHUB_OUTPUT}"
4445
fi
4546
done
4647
env:
4748
INPUT_TOOL_NAMES: >-
4849
black
4950
clang-format
51+
ruff
5052
- name: Post Black suggestions
5153
if: ${{ steps.tools.outputs.black == 'true' }}
5254
run: |
@@ -65,7 +67,7 @@ jobs:
6567
CI_REPO_OWNER: ${{ github.event.workflow_run.repository.owner.login }}
6668
CI_REPO_NAME: ${{ github.event.workflow_run.repository.name }}
6769
# CI_PULL_REQUEST: "" # Populated from reviewdog's "-guess" flag since hard to get
68-
- name: Post Clang-format suggestions
70+
- name: Post ClangFormat suggestions
6971
if: ${{ steps.tools.outputs.clang-format == 'true' }}
7072
run: |
7173
TMPFILE="diff-${INPUT_TOOL_NAME}.patch"
@@ -83,3 +85,21 @@ jobs:
8385
CI_REPO_OWNER: ${{ github.event.workflow_run.repository.owner.login }}
8486
CI_REPO_NAME: ${{ github.event.workflow_run.repository.name }}
8587
# CI_PULL_REQUEST: "" # Populated from reviewdog's "-guess" flag since hard to get
88+
- name: Post Ruff suggestions
89+
if: ${{ steps.tools.outputs.ruff == 'true' }}
90+
run: |
91+
TMPFILE="diff-${INPUT_TOOL_NAME}.patch"
92+
GITHUB_ACTIONS="" reviewdog \
93+
-name="${INPUT_TOOL_NAME:-reviewdog-suggester}" \
94+
-f=diff \
95+
-f.diff.strip=1 \
96+
-filter-mode=nofilter \
97+
-guess \
98+
-reporter="github-pr-review" < "${TMPFILE}"
99+
env:
100+
INPUT_TOOL_NAME: ruff
101+
REVIEWDOG_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }}
102+
CI_COMMIT: ${{ github.event.workflow_run.head_sha }}
103+
CI_REPO_OWNER: ${{ github.event.workflow_run.repository.owner.login }}
104+
CI_REPO_NAME: ${{ github.event.workflow_run.repository.name }}
105+
# CI_PULL_REQUEST: "" # Populated from reviewdog's "-guess" flag since hard to get

.github/workflows/super-linter.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ jobs:
5656
VALIDATE_MARKDOWN_PRETTIER: false # Until issues are fixed
5757
VALIDATE_NATURAL_LANGUAGE: false # Until issues are fixed, lots of valid suggestions
5858
VALIDATE_PERL: false # Until issues are fixed
59-
VALIDATE_PYTHON_BLACK: false # Until code is upgraded to a newer black version
59+
VALIDATE_PYTHON_BLACK: false # We are using ruff format
6060
VALIDATE_PYTHON_FLAKE8: false
6161
VALIDATE_PYTHON_ISORT: false # Until issues are fixed
6262
VALIDATE_PYTHON_MYPY: false # Issue with module name wx.wms

.pre-commit-config.yaml

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
---
22
repos:
3+
- repo: https://github.com/astral-sh/ruff-pre-commit
4+
# Ruff version.
5+
rev: v0.9.4
6+
hooks:
7+
# Run the formatter.
8+
- id: ruff-format
39
- repo: https://github.com/pre-commit/pre-commit-hooks
410
rev: v5.0.0
511
hooks:
@@ -27,11 +33,6 @@ repos:
2733
rev: v0.44.0
2834
hooks:
2935
- id: markdownlint-fix
30-
# Using this mirror lets us use mypyc-compiled black, which is about 2x faster
31-
- repo: https://github.com/psf/black-pre-commit-mirror
32-
rev: 25.1.0
33-
hooks:
34-
- id: black-jupyter
3536
- repo: https://github.com/pycqa/flake8
3637
rev: 7.1.1
3738
hooks:

src/gui/wxpython/wx.metadata/mdlib/cswlib.py

+27-2
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,20 @@ def __init__(self, parent, main, giface=None):
103103
wx.Panel.__init__(self, parent)
104104

105105
try:
106-
global BBox, CatalogueServiceWeb, Environment, ExceptionReport, FileSystemLoader, GError, GMessage, GUI, GWarning, HtmlFormatter, PropertyIsLike, XmlLexer, highlight
106+
global \
107+
BBox, \
108+
CatalogueServiceWeb, \
109+
Environment, \
110+
ExceptionReport, \
111+
FileSystemLoader, \
112+
GError, \
113+
GMessage, \
114+
GUI, \
115+
GWarning, \
116+
HtmlFormatter, \
117+
PropertyIsLike, \
118+
XmlLexer, \
119+
highlight
107120

108121
from jinja2 import Environment, FileSystemLoader
109122

@@ -1059,7 +1072,19 @@ class CSWConnectionPanel(wx.Panel):
10591072
def __init__(self, parent, main, cswBrowser=True):
10601073
wx.Panel.__init__(self, parent)
10611074
try:
1062-
global BBox, CatalogueServiceWeb, Environment, ExceptionReport, FileSystemLoader, GError, GMessage, GWarning, HtmlFormatter, PropertyIsLike, XmlLexer, highlight
1075+
global \
1076+
BBox, \
1077+
CatalogueServiceWeb, \
1078+
Environment, \
1079+
ExceptionReport, \
1080+
FileSystemLoader, \
1081+
GError, \
1082+
GMessage, \
1083+
GWarning, \
1084+
HtmlFormatter, \
1085+
PropertyIsLike, \
1086+
XmlLexer, \
1087+
highlight
10631088

10641089
from jinja2 import Environment, FileSystemLoader
10651090

src/gui/wxpython/wx.metadata/mdlib/mdeditorfactory.py

+10-1
Original file line numberDiff line numberDiff line change
@@ -1170,7 +1170,16 @@ def __init__(self, parent, profilePath, xmlMdPath, templateEditor=False):
11701170
wx.Panel.__init__(self, parent=parent, id=wx.ID_ANY)
11711171

11721172
try:
1173-
global CI_Date, CI_OnlineResource, CI_ResponsibleParty, DQ_DataQuality, EX_Extent, EX_GeographicBoundingBox, GError, MD_Distribution, MD_ReferenceSystem
1173+
global \
1174+
CI_Date, \
1175+
CI_OnlineResource, \
1176+
CI_ResponsibleParty, \
1177+
DQ_DataQuality, \
1178+
EX_Extent, \
1179+
EX_GeographicBoundingBox, \
1180+
GError, \
1181+
MD_Distribution, \
1182+
MD_ReferenceSystem
11741183

11751184
from owslib.iso import (
11761185
CI_Date,

src/gui/wxpython/wx.metadata/mdlib/mdgrass.py

+13-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,19 @@ class GrassMD:
4242

4343
def __init__(self, map, type):
4444
try:
45-
global CI_Date, CI_OnlineResource, CI_ResponsibleParty, DQ_DataQuality, Environment, etree, EX_Extent, EX_GeographicBoundingBox, FileSystemLoader, MD_Distribution, MD_ReferenceSystem, RunCommand
45+
global \
46+
CI_Date, \
47+
CI_OnlineResource, \
48+
CI_ResponsibleParty, \
49+
DQ_DataQuality, \
50+
Environment, \
51+
etree, \
52+
EX_Extent, \
53+
EX_GeographicBoundingBox, \
54+
FileSystemLoader, \
55+
MD_Distribution, \
56+
MD_ReferenceSystem, \
57+
RunCommand
4658

4759
from owslib.iso import (
4860
CI_Date,

src/gui/wxpython/wx.metadata/mdlib/mdpdftheme.py

+17-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,15 @@ class MySheet:
2323

2424
def __init__(self):
2525
try:
26-
global ParagraphStyle, TA_CENTER, _baseFontName, _baseFontNameB, _baseFontNameBI, _baseFontNameI, colors, inch
26+
global \
27+
ParagraphStyle, \
28+
TA_CENTER, \
29+
_baseFontName, \
30+
_baseFontNameB, \
31+
_baseFontNameBI, \
32+
_baseFontNameI, \
33+
colors, \
34+
inch
2735

2836
from reportlab.lib.styles import (
2937
ParagraphStyle,
@@ -351,7 +359,14 @@ class Pdf(object):
351359

352360
def __init__(self, title, author):
353361
try:
354-
global Image, KeepTogether, LongTable, Paragraph, SimpleDocTemplate, Spacer, Table
362+
global \
363+
Image, \
364+
KeepTogether, \
365+
LongTable, \
366+
Paragraph, \
367+
SimpleDocTemplate, \
368+
Spacer, \
369+
Table
355370

356371
from reportlab.platypus.doctemplate import SimpleDocTemplate
357372
from reportlab.platypus.flowables import Image

src/gui/wxpython/wx.mwprecip/mw3.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -1783,11 +1783,13 @@ def firstPreparation(self):
17831783
self.connection.executeSql(sql, False, True)
17841784

17851785
logger.info("Computing column lenght")
1786-
sql = "UPDATE link SET lenght = get_earth_distance1(n1.long,n1.lat,n2.long,n2.lat) \
1786+
sql = (
1787+
"UPDATE link SET lenght = get_earth_distance1(n1.long,n1.lat,n2.long,n2.lat) \
17871788
FROM node AS n1 JOIN \
17881789
link AS l ON n1.nodeid = fromnodeid \
17891790
JOIN node AS n2 ON n2.nodeid = tonodeid \
17901791
WHERE link.linkid = l.linkid; "
1792+
)
17911793
self.connection.executeSql(sql, False, True)
17921794

17931795
# logger.info("Add column precip")

src/imagery/i.ann.maskrcnn/maskrcnnlib/model.py

+13-13
Original file line numberDiff line numberDiff line change
@@ -1527,10 +1527,10 @@ def build_detection_targets(rpn_rois, gt_class_ids, gt_boxes, gt_masks, config):
15271527
# Fill the rest with repeated bg rois.
15281528
keep_extra_ids = np.random.choice(keep_bg_ids, remaining, replace=True)
15291529
keep = np.concatenate([keep, keep_extra_ids])
1530-
assert (
1531-
keep.shape[0] == config.TRAIN_ROIS_PER_IMAGE
1532-
), "keep doesn't match ROI batch size {}, {}".format(
1533-
keep.shape[0], config.TRAIN_ROIS_PER_IMAGE
1530+
assert keep.shape[0] == config.TRAIN_ROIS_PER_IMAGE, (
1531+
"keep doesn't match ROI batch size {}, {}".format(
1532+
keep.shape[0], config.TRAIN_ROIS_PER_IMAGE
1533+
)
15341534
)
15351535

15361536
# Reset the gt boxes assigned to BG ROIs.
@@ -2876,9 +2876,9 @@ def detect(self, images, verbosity=0):
28762876
verbose form in case of verbosity == 3, not 1
28772877
"""
28782878
assert self.mode == "inference", "Create model in inference mode."
2879-
assert (
2880-
len(images) == self.config.BATCH_SIZE
2881-
), "len(images) must be equal to BATCH_SIZE"
2879+
assert len(images) == self.config.BATCH_SIZE, (
2880+
"len(images) must be equal to BATCH_SIZE"
2881+
)
28822882

28832883
if verbosity == 3:
28842884
log("Processing {} images".format(len(images)))
@@ -2892,9 +2892,9 @@ def detect(self, images, verbosity=0):
28922892
# All images in a batch MUST be of the same size
28932893
image_shape = molded_images[0].shape
28942894
for g in molded_images[1:]:
2895-
assert (
2896-
g.shape == image_shape
2897-
), "After resizing, all images must have the same size. Check IMAGE_RESIZE_MODE and image sizes."
2895+
assert g.shape == image_shape, (
2896+
"After resizing, all images must have the same size. Check IMAGE_RESIZE_MODE and image sizes."
2897+
)
28982898

28992899
# Anchors
29002900
anchors = self.get_anchors(image_shape)
@@ -2950,9 +2950,9 @@ def detect_molded(self, molded_images, image_metas, verbose=0):
29502950
masks: [H, W, N] instance binary masks
29512951
"""
29522952
assert self.mode == "inference", "Create model in inference mode."
2953-
assert (
2954-
len(molded_images) == self.config.BATCH_SIZE
2955-
), "Number of images must be equal to BATCH_SIZE"
2953+
assert len(molded_images) == self.config.BATCH_SIZE, (
2954+
"Number of images must be equal to BATCH_SIZE"
2955+
)
29562956

29572957
if verbose:
29582958
log("Processing {} images".format(len(molded_images)))

src/imagery/i.eodag/i.eodag.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -1313,9 +1313,9 @@ def main():
13131313
]
13141314
)
13151315
else:
1316-
dag.providers_config["creodias"].auth.credentials[
1317-
"totp"
1318-
] = creodias_otp
1316+
dag.providers_config["creodias"].auth.credentials["totp"] = (
1317+
creodias_otp
1318+
)
13191319
dag._plugins_manager.get_auth_plugin("creodias").authenticate()
13201320
custom_config = {
13211321
"timeout": int(options["timeout"]),

src/imagery/i.landsat/i.landsat.qa/i.landsat.qa.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -178,9 +178,7 @@ def check_user_input(user_input):
178178
grass.fatal(
179179
_(
180180
"""All conditions for {} specified as
181-
unacceptable, this will result in an empty map.""".format(
182-
o
183-
)
181+
unacceptable, this will result in an empty map.""".format(o)
184182
)
185183
)
186184
# Check if valid combination of options if provided

src/imagery/i.landsat8.swlst/split_window_lst.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -128,9 +128,9 @@ def __init__(self, landcover):
128128

129129
if landcover in EMISSIVITIES.keys() or landcover == "Random":
130130
# a fixed land cover class requested
131-
assert self._landcover_string_validity(
132-
landcover_class
133-
), "Unknown land cover class name!"
131+
assert self._landcover_string_validity(landcover_class), (
132+
"Unknown land cover class name!"
133+
)
134134
self.landcover_class = landcover
135135

136136
# retrieve & set avg emissivities for channels t10, t11

0 commit comments

Comments
 (0)