Skip to content

Commit

Permalink
CI(deps): Update ruff to v0.8.1 (#4785)
Browse files Browse the repository at this point in the history
* CI(deps): Update ruff to v0.8.1

* style: Fix RUF055 [*] Plain string pattern passed to `re` function

* style: Fix or ignore os-listdir (PTH208)
Use `pathlib.Path.iterdir()` instead.
Ruff rule: https://docs.astral.sh/ruff/rules/os-listdir/

---------

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Edouard Choinière <[email protected]>
  • Loading branch information
renovate[bot] and echoix authored Nov 30, 2024
1 parent 0c3a9c7 commit a6e03d3
Show file tree
Hide file tree
Showing 7 changed files with 88 additions and 60 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/python-code-quality.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
# renovate: datasource=pypi depName=bandit
BANDIT_VERSION: "1.8.0"
# renovate: datasource=pypi depName=ruff
RUFF_VERSION: "0.8.0"
RUFF_VERSION: "0.8.1"

runs-on: ${{ matrix.os }}
permissions:
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ repos:
)
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.8.0
rev: v0.8.1
hooks:
# Run the linter.
- id: ruff
Expand Down
3 changes: 1 addition & 2 deletions gui/wxpython/photo2image/ip2i_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -426,14 +426,13 @@ def __init__(
GMessage(_("A POINTS file exists, renaming it to POINTS_BAK"))

# """Make a POINTS file """
import re

try:
fc = open(self.file["camera"])
fc_count = 0
for line in fc:
fc_count += 1
if re.search(r"NUM", line):
if "NUM" in line:
storeLine = fc_count
numberOfFiducial = int(line.split()[-1])
dataFiducialX = []
Expand Down
13 changes: 9 additions & 4 deletions man/build_manual_gallery.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,16 @@
# for details.
#
#############################################################################
from __future__ import annotations

import os
from pathlib import Path
import fnmatch
import re
from typing import TYPE_CHECKING

if TYPE_CHECKING:
from collections.abc import Iterable

img_extensions = ["png", "jpg", "gif"]
img_patterns = ["*." + extension for extension in img_extensions]
Expand Down Expand Up @@ -88,7 +93,7 @@
"""


def img_in_file(filename, imagename, ext) -> bool:
def img_in_file(filename: str | os.PathLike[str], imagename: str, ext: str) -> bool:
# for some reason, calling search just once is much faster
# than calling it on every line (time is spent in _compile)
if ext == "html":
Expand All @@ -99,7 +104,7 @@ def img_in_file(filename, imagename, ext) -> bool:
return bool(re.search(pattern, Path(filename).read_text()))


def file_matches(filename, patterns):
def file_matches(filename: str, patterns: Iterable[str]):
return any(fnmatch.fnmatch(filename, pattern) for pattern in patterns)


Expand Down Expand Up @@ -163,11 +168,11 @@ def main(ext):
continue
if file_matches(filename, img_patterns):
for man_filename in man_files:
if img_in_file(os.path.join(man_dir, man_filename), filename, ext):
if img_in_file(Path(man_dir, man_filename), filename, ext):
img_files[filename] = man_filename
# for now suppose one image per manual filename

with open(os.path.join(man_dir, output_name), "w") as output:
with open(Path(man_dir, output_name), "w") as output:
output.write(
header1_tmpl.substitute(
title="GRASS GIS %s Reference Manual: Manual gallery" % grass_version
Expand Down
31 changes: 25 additions & 6 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -268,14 +268,20 @@ ignore = [
"gui/**" = ["PLW0108"] # See https://github.com/OSGeo/grass/issues/4124
"gui/wxpython/animation/temporal_manager.py" = ["SIM115"]
"gui/wxpython/core/*.py" = ["SIM115"]
"gui/wxpython/core/globalvar.py" = ["PTH208"]
"gui/wxpython/core/settings.py" = ["PTH208"]
"gui/wxpython/datacatalog/catalog.py" = ["PTH208"]
"gui/wxpython/dbmgr/base.py" = ["SIM115"]
"gui/wxpython/gcp/manager.py" = ["SIM115"]
"gui/wxpython/gcp/manager.py" = ["PTH208", "SIM115"]
"gui/wxpython/gmodeler/*.py" = ["SIM115"]
"gui/wxpython/gui_core/*.py" = ["SIM115"]
"gui/wxpython/gui_core/dialogs.py" = ["PTH208"]
"gui/wxpython/iclass/frame*.py" = ["SIM115"]
"gui/wxpython/iclass/frame.py" = ["FLY002"]
"gui/wxpython/iclass/statistics.py" = ["A005"]
"gui/wxpython/icons/grass_icons.py" = ["PTH208"]
"gui/wxpython/image2target/*.py" = ["SIM115"]
"gui/wxpython/image2target/ii2t_manager.py" = ["PTH208"]
"gui/wxpython/iscatt/plots.py" = ["PLW0108"]
"gui/wxpython/lmgr/workspace.py" = ["SIM115"]
"gui/wxpython/location_wizard/wizard.py" = ["SIM115"]
Expand All @@ -284,9 +290,11 @@ ignore = [
"gui/wxpython/modules/mcalc_builder.py" = ["SIM115"]
"gui/wxpython/photo2image/*.py" = ["SIM115"]
"gui/wxpython/psmap/*.py" = ["SIM115"]
"gui/wxpython/psmap/dialogs.py" = ["PTH208"]
"gui/wxpython/psmap/utils.py" = ["PGH004"]
"gui/wxpython/rdigit/controller.py" = ["SIM115"]
"gui/wxpython/rlisetup/*.py" = ["SIM115"]
"gui/wxpython/rlisetup/frame.py" = ["PTH208"]
"gui/wxpython/timeline/frame.py" = ["FLY002"]
"gui/wxpython/tools/update_menudata.py" = ["SIM115"]
"gui/wxpython/tplot/frame.py" = ["FLY002"]
Expand All @@ -299,31 +307,39 @@ ignore = [
"lib/imagery/testsuite/test_imagery_signature_management.py" = ["SIM115"]
"lib/imagery/testsuite/test_imagery_sigsetfile.py" = ["FURB152"]
"lib/init/grass.py" = ["SIM115"]
"lib/init/testsuite/test_grass_tmp_mapset.py" = ["PTH208"]
"locale/grass_po_stats.py" = ["SIM115"]
"man/build.py" = ["PTH208"]
"man/build_class_graphical.py" = ["PTH208"]
"man/build_manual_gallery.py" = ["PTH208"]
"man/build_rest.py" = ["PTH208"]
"python/grass/__init__.py" = ["PYI056"]
"python/grass/exp*/tests/grass_script_mapset_session_test.py" = ["SIM117"]
"python/grass/exp*/tests/grass_script_tmp_mapset_session_test.py" = ["SIM117"]
"python/grass/gunittest/case.py" = ["PT009"]
"python/grass/gunittest/loader.py" = ["PYI024"]
"python/grass/gunittest/loader.py" = ["PTH208", "PYI024"]
"python/grass/gunittest/multireport.py" = ["PYI024"]
"python/grass/gunittest/testsu*/d*/s*/s*/subsub*/t*/test_segfaut.py" = ["B018"]
"python/grass/gunittest/testsuite/test_assertions_rast3d.py" = ["FLY002"]
"python/grass/imaging/images2*.py" = ["SIM115"]
"python/grass/imaging/images2ims.py" = ["PTH208"]
"python/grass/jupyter/testsuite/interactivemap_test.py" = ["PGH004"]
"python/grass/jupyter/testsuite/map_test.py" = ["PGH004"]
"python/grass/pydispatch/signal.py" = ["A005"]
"python/grass/pygrass/modules/grid/grid.py" = ["SIM115"]
"python/grass/pygrass/gis/__init__.py" = ["PTH208"]
"python/grass/pygrass/modules/grid/grid.py" = ["PTH208", "SIM115"]
"python/grass/pygrass/modules/grid/testsuite/test_*_modules_grid_doctests.py" = ["F401"]
"python/grass/pygrass/modules/interface/env.py" = ["SIM115"]
"python/grass/pygrass/modules/testsuite/test_pygrass_modules_doctests.py" = ["F401"]
"python/grass/pygrass/raster/category.py" = ["FURB189"]
"python/grass/pygrass/raster/segment.py" = ["SIM115"]
"python/grass/pygrass/tests/*.py" = ["SIM115"]
"python/grass/pygrass/utils.py" = ["PTH208"]
"python/grass/pygrass/vector/geometry.py" = ["PYI024"]
"python/grass/pygrass/vector/sql.py" = ["FLY002"]
"python/grass/pygrass/vector/testsuite/test_table.py" = ["PLW0108"]
"python/grass/script/array.py" = ["A005"]
"python/grass/script/core.py" = ["SIM115"]
"python/grass/script/core.py" = ["PTH208", "SIM115"]
"python/grass/script/db.py" = ["SIM115"]
"python/grass/script/raster.py" = ["SIM115"]
"python/grass/script/utils.py" = ["FURB189", "SIM115"]
Expand All @@ -332,7 +348,7 @@ ignore = [
"python/grass/temporal/stds_export.py" = ["SIM115"]
"python/grass/temporal/stds_import.py" = ["SIM115"]
"python/grass/temporal/univar_statistics.py" = ["SIM115"]
"python/grass/utils/download.py" = ["SIM115"]
"python/grass/utils/download.py" = ["PTH208", "SIM115"]
"raster/r.*/testsuite/*.py" = ["SIM115"]
"raster/r.topidx/*.py" = ["SIM115"]
"raster3d/r3.flow/testsuite/r3flow_test.py" = ["FLY002"]
Expand All @@ -343,8 +359,10 @@ ignore = [
"scripts/db.in.ogr/db.in.ogr.py" = ["SIM115"]
"scripts/db.test/db.test.py" = ["SIM115"]
"scripts/db.univar/db.univar.py" = ["SIM115"]
"scripts/g.download.project/g.download.project.py" = ["PTH208"]
"scripts/g.extension.all/g.extension.all.py" = ["SIM115"]
"scripts/g.extension/g.extension.py" = ["SIM115"]
"scripts/g.extension/g.extension.py" = ["PTH208", "SIM115"]
"scripts/g.extension/testsuite/test_addons_modules.py" = ["PTH208"]
"scripts/g.search.modules/g.search.modules.py" = ["SIM115"]
"scripts/i.in.spotvgt/i.in.spotvgt.py" = ["SIM115"]
"scripts/i.oif/i.oif*.py" = ["SIM115"]
Expand All @@ -370,6 +388,7 @@ ignore = [
"temporal/t.unregister/t.unregister.py" = ["SIM115"]
"utils/**.py" = ["SIM115"]
"utils/generate_release_notes.py" = ["PGH004"]
"utils/thumbnails.py" = ["PTH208"]
"vector/v.fill.holes/examples.ipynb" = ["PTH201"]

[tool.ruff.lint.flake8-import-conventions.extend-aliases]
Expand Down
Loading

0 comments on commit a6e03d3

Please sign in to comment.