Skip to content

Commit

Permalink
Merge branch 'main' into tests-unused-imports
Browse files Browse the repository at this point in the history
  • Loading branch information
echoix authored Oct 18, 2024
2 parents 4ccafbf + 2a0ad5f commit 84dc11d
Show file tree
Hide file tree
Showing 108 changed files with 613 additions and 694 deletions.
1 change: 1 addition & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ omit =
${INITIAL_PWD-.}/.github/*
${INITIAL_PWD-.}/bin.*/*
${INITIAL_PWD-.}/dist.*/*
**/gui/wxpython/*/**
**/OBJ.*/*
source =
.
Expand Down
11 changes: 3 additions & 8 deletions .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,11 @@ per-file-ignores =
gui/scripts/d.wms.py: E501
gui/wxpython/image2target/g.gui.image2target.py: E501
gui/wxpython/modules/*: F841, E722
gui/wxpython/nviz/*: F841, E266, E722, F403, F405
gui/wxpython/nviz/*: E722, F403, F405
gui/wxpython/photo2image/*: F841, E722, E265
gui/wxpython/photo2image/g.gui.photo2image.py: E501, F841
gui/wxpython/psmap/*: F841, E266, E722, F405, F403
gui/wxpython/psmap/*: F841, E266, E722
gui/wxpython/vdigit/*: F841, E722, F405, F403
gui/wxpython/vnet/*: F841
gui/wxpython/wxgui.py: F841
gui/wxpython/animation/g.gui.animation.py: E501
gui/wxpython/tplot/frame.py: F841, E722
gui/wxpython/tplot/g.gui.tplot.py: E501
Expand Down Expand Up @@ -67,7 +65,6 @@ per-file-ignores =
# TODO: Is this really needed?
python/grass/pygrass/vector/__init__.py: E402
python/grass/pygrass/raster/__init__.py: E402
python/grass/gunittest/invoker.py: E721
python/grass/pygrass/vector/__init__.py: E402
python/grass/pygrass/raster/category.py: E721
python/grass/pygrass/rpc/__init__.py: F403
Expand All @@ -81,13 +78,11 @@ per-file-ignores =
python/grass/temporal/temporal_granularity.py: E722
python/grass/temporal/temporal_raster_base_algebra.py: E722
python/grass/temporal/temporal_topology_dataset_connector.py: E722
python/grass/temporal/univar_statistics.py: E231
# Current benchmarks/tests are changing sys.path before import.
# Possibly, a different approach should be taken there anyway.
python/grass/pygrass/tests/benchmark.py: E402, F821
# Configuration file for Sphinx:
# Ignoring import/code mix and line length.
python/grass/docs/conf.py: E402
# Files not managed by Black
python/grass/imaging/images2gif.py: E226
# Unused imports in init files
Expand All @@ -112,7 +107,7 @@ per-file-ignores =
scripts/r.in.srtm/r.in.srtm.py: E722
scripts/r.fillnulls/r.fillnulls.py: E722
scripts/d.rast.edit/d.rast.edit.py: E722
scripts/v.what.strds/v.what.strds.py: E722, E501
scripts/v.what.strds/v.what.strds.py: E501
# Line too long (esp. module interface definitions)
scripts/*/*.py: E501
temporal/t.rast.to.vect/t.rast.to.vect.py: E501
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ jobs:
if: ${{ matrix.language == 'c-cpp' }}

- name: Initialize CodeQL
uses: github/codeql-action/init@c36620d31ac7c881962c3d9dd939c40ec9434f2b # v3.26.12
uses: github/codeql-action/init@f779452ac5af1c261dce0346a8f964149f49322b # v3.26.13
with:
languages: ${{ matrix.language }}
config-file: ./.github/codeql/codeql-config.yml
Expand All @@ -81,6 +81,6 @@ jobs:
run: .github/workflows/build_ubuntu-22.04.sh "${HOME}/install"

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@c36620d31ac7c881962c3d9dd939c40ec9434f2b # v3.26.12
uses: github/codeql-action/analyze@f779452ac5af1c261dce0346a8f964149f49322b # v3.26.13
with:
category: "/language:${{matrix.language}}"
70 changes: 70 additions & 0 deletions .github/workflows/milestones.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
---
name: Assign Milestone

on:
pull_request_target:
types: [closed]

jobs:
assign-milestone:
runs-on: ubuntu-latest
if: github.event.pull_request.merged
steps:
# Retreiving the current milestoone from API instead of github context,
# so up-to-date information is used when running after being queued or for reruns
# Otherwise, the information should be available using
# ${{ github.event.pull_request.milestone.title }}
- name: Get current milestone title
id: current-milestone
run: |
echo "milestone<<EOF" >> "${GITHUB_OUTPUT}"
gh pr view ${{ github.event.pull_request.html_url }} --json milestone \
--jq .milestone.title >> "${GITHUB_OUTPUT}"
echo 'EOF' >> "${GITHUB_OUTPUT}"
env:
GH_TOKEN: ${{ github.token }}
GH_REPO: ${{ github.repository }}
- name: PR already has a milestone
run: echo "PR already has a milestone"
if: ${{ steps.current-milestone.outputs.milestone }}
- name: PR does not have a milestone
run: echo "PR does not have a milestone"
if: ${{ !steps.current-milestone.outputs.milestone }}
- name: Get VERSION file
if: ${{ !steps.current-milestone.outputs.milestone }}
id: version-file
run: |
echo "version<<EOF" >> "${GITHUB_OUTPUT}"
gh api \
-H "Accept: application/vnd.github.raw" \
-H "X-GitHub-Api-Version: 2022-11-28" \
"/repos/{owner}/{repo}/contents/include/VERSION?ref=${{ github.sha }}" >> "${GITHUB_OUTPUT}"
echo "EOF" >> "${GITHUB_OUTPUT}"
env:
GH_TOKEN: ${{ github.token }}
GH_REPO: ${{ github.repository }}
- name: Show version file
if: ${{ !steps.current-milestone.outputs.milestone }}
run: echo "${VERSIONFILE}"
env:
VERSIONFILE: ${{ steps.version-file.outputs.version }}
- name: Get milestone title from VERSION file
if: ${{ !steps.current-milestone.outputs.milestone }}
id: milestone
run: |
version=$(echo "$VERSIONFILE" | head -n 3 | xargs | sed 's/ /./g; s/\(RC[0-9]*\|dev\)//g')
echo "title=$version" >> "${GITHUB_OUTPUT}"
env:
VERSIONFILE: ${{ steps.version-file.outputs.version }}
- name: Show milestone title
if: ${{ !steps.current-milestone.outputs.milestone }}
run: echo "${MILESTONE}"
env:
MILESTONE: ${{ steps.milestone.outputs.title }}
- name: Set PR milestone
if: ${{ !steps.current-milestone.outputs.milestone }}
run: gh pr edit ${{ github.event.pull_request.html_url }} --milestone "${MILESTONE}"
env:
GH_TOKEN: ${{ github.token }}
GH_REPO: ${{ github.repository }}
MILESTONE: ${{ steps.milestone.outputs.title }}
11 changes: 9 additions & 2 deletions .github/workflows/pytest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,18 +83,25 @@ jobs:
run: |
export PYTHONPATH=`grass --config python_path`:$PYTHONPATH
export LD_LIBRARY_PATH=$(grass --config path)/lib:$LD_LIBRARY_PATH
export INITIAL_GISBASE="$(grass --config path)"
export INITIAL_PWD="${PWD}"
pytest --verbose --color=yes --durations=0 --durations-min=0.5 \
--numprocesses auto -ra . \
--numprocesses auto \
--cov \
--cov-context=test \
-ra . \
-m 'not needs_solo_run'
- name: Run pytest with a single worker (for tests marked with needs_solo_run)
run: |
export PYTHONPATH=`grass --config python_path`:$PYTHONPATH
export LD_LIBRARY_PATH=$(grass --config path)/lib:$LD_LIBRARY_PATH
export INITIAL_GISBASE="$(grass --config path)"
INITIAL_PWD="${PWD}" pytest --verbose --color=yes --durations=0 --durations-min=0.5 \
export INITIAL_PWD="${PWD}"
pytest --verbose --color=yes --durations=0 --durations-min=0.5 \
--cov \
--cov-context=test \
--cov-append \
-ra . \
-m 'needs_solo_run'
- name: Fix non-standard installed script paths in coverage data
Expand Down
4 changes: 2 additions & 2 deletions .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.7.10"
# renovate: datasource=pypi depName=ruff
RUFF_VERSION: "0.6.9"
RUFF_VERSION: "0.7.0"

runs-on: ${{ matrix.os }}
permissions:
Expand Down Expand Up @@ -135,7 +135,7 @@ jobs:
path: bandit.sarif

- name: Upload SARIF File into Security Tab
uses: github/codeql-action/upload-sarif@c36620d31ac7c881962c3d9dd939c40ec9434f2b # v3.26.12
uses: github/codeql-action/upload-sarif@f779452ac5af1c261dce0346a8f964149f49322b # v3.26.13
with:
sarif_file: bandit.sarif

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.6.9
rev: v0.7.0
hooks:
# Run the linter.
- id: ruff
Expand Down
2 changes: 2 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
pytest
];

LOCALE_ARCHIVE = "${pkgs.glibcLocales}/lib/locale/locale-archive";

shellHook = ''
function dev-help {
echo -e "\nWelcome to a GRASS development environment !"
Expand Down
3 changes: 2 additions & 1 deletion gui/wxpython/core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import re
import inspect
import operator
from string import digits

from grass.script import core as grass
from grass.script import task as gtask
Expand Down Expand Up @@ -936,7 +937,7 @@ def SetAddOnPath(addonPath=None, key="PATH"):


def color_resolve(color):
if len(color) > 0 and color[0] in "0123456789":
if len(color) > 0 and color[0] in digits:
rgb = tuple(map(int, color.split(":")))
label = color
else:
Expand Down
2 changes: 1 addition & 1 deletion gui/wxpython/gmodeler/g.gui.gmodeler.html
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ <h2>SEE ALSO</h2>

<p>
See also selected user models available from
<a href="https://grass.osgeo.org/grass78/manuals/addons/">GRASS Addons repository</a>.
<a href="https://grass.osgeo.org/grass8/manuals/addons/">GRASS Addons repository</a>.

<p>
See also
Expand Down
3 changes: 2 additions & 1 deletion gui/wxpython/gui_core/goutput.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"""

import textwrap
from string import digits

import wx
from wx import stc
Expand Down Expand Up @@ -624,7 +625,7 @@ def AddStyledMessage(self, message, style=None):
self.linePos = self.GetCurrentPos()
if c != " ":
last_c = c
if last_c not in ("0123456789"):
if last_c not in (digits):
self.AddTextWrapped("\n", wrap=None)
self.linePos = -1
else:
Expand Down
6 changes: 3 additions & 3 deletions gui/wxpython/lmgr/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -1135,7 +1135,7 @@ def GetMenuCmd(self, event):
layer = self.GetLayerTree().layer_selected
name = self.GetLayerTree().GetLayerInfo(layer, key="maplayer").name
type = self.GetLayerTree().GetLayerInfo(layer, key="type")
except AttributeError:
except (AttributeError, TypeError):
layer = None

if layer and len(cmdlist) == 1: # only if no parameters given
Expand Down Expand Up @@ -1183,7 +1183,7 @@ def OnVDigit(self, event):
# available only for vector map layers
try:
mapLayer = tree.GetLayerInfo(layer, key="maplayer")
except AttributeError:
except (AttributeError, TypeError):
mapLayer = None

if not mapLayer or mapLayer.GetType() != "vector":
Expand Down Expand Up @@ -1860,7 +1860,7 @@ def OnShowAttributeTable(self, event, selection=None):
# available only for vector map layers
try:
maptype = tree.GetLayerInfo(layer, key="maplayer").type
except AttributeError:
except (AttributeError, TypeError):
maptype = None

if not maptype or maptype != "vector":
Expand Down
4 changes: 3 additions & 1 deletion gui/wxpython/lmgr/giface.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ def __init__(self, tree):
self._tree = tree

def __len__(self):
return len(list(self))
# The list constructor calls __len__ as an optimization if available,
# causing a RecursionError
return len([layer for layer in self]) # noqa: C416

def __iter__(self):
"""Iterates over the contents of the list."""
Expand Down
4 changes: 2 additions & 2 deletions gui/wxpython/lmgr/layertree.py
Original file line number Diff line number Diff line change
Expand Up @@ -1758,7 +1758,7 @@ def OnDeleteLayer(self, event):
try:
if self.GetLayerInfo(item, key="type") != "group":
self.Map.DeleteLayer(self.GetLayerInfo(item, key="maplayer"))
except AttributeError:
except (AttributeError, TypeError):
pass

# redraw map if auto-rendering is enabled
Expand Down Expand Up @@ -2399,7 +2399,7 @@ def __FindSubItemByName(self, item, value):
while item and item.IsOk():
try:
itemLayer = self.GetLayerInfo(item, key="maplayer")
except KeyError:
except (KeyError, TypeError):
return None

if itemLayer and value == itemLayer.GetName():
Expand Down
20 changes: 14 additions & 6 deletions gui/wxpython/lmgr/workspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -519,12 +519,20 @@ def CreateRecentFilesMenu(self, menu=None):
:return None
"""
if menu:
file_menu = menu.GetMenu(
menuIndex=menu.FindMenu(title=_("File")),
)
workspace_item = file_menu.FindItem(
id=file_menu.FindItem(itemString=_("Workspace")),
)[0]
menu_index = menu.FindMenu(_("File"))
if menu_index == wx.NOT_FOUND:
# try untranslated version
menu_index = menu.FindMenu("File")
if menu_index == wx.NOT_FOUND:
return
file_menu = menu.GetMenu(menu_index)
workspace_index = file_menu.FindItem(_("Workspace"))
if workspace_index == wx.NOT_FOUND:
workspace_index = file_menu.FindItem("Workspace")
if workspace_index == wx.NOT_FOUND:
return
workspace_item = file_menu.FindItemById(workspace_index)

self._recent_files = RecentFilesMenu(
app_name="main",
parent_menu=workspace_item.GetSubMenu(),
Expand Down
11 changes: 7 additions & 4 deletions gui/wxpython/location_wizard/wizard.py
Original file line number Diff line number Diff line change
Expand Up @@ -1604,9 +1604,12 @@ def __init__(self, wizard, parent):
self, data=None, columns=[_("Code"), _("Description"), _("Parameters")]
)

# epsg.io hyperlink
# A hyperlink to a CRS database (PROJ related)
self.tlink = HyperlinkCtrl(
self, id=wx.ID_ANY, label="epsg.io", url="https://epsg.io/"
self,
id=wx.ID_ANY,
label="spatialreference.org",
url="https://spatialreference.org/",
)
self.tlink.SetNormalColour(wx.SystemSettings.GetColour(wx.SYS_COLOUR_GRAYTEXT))
self.tlink.SetVisitedColour(wx.SystemSettings.GetColour(wx.SYS_COLOUR_GRAYTEXT))
Expand Down Expand Up @@ -1688,14 +1691,14 @@ def EnableNext(self, enable=True):
def OnTextChange(self, event):
value = self.searchb.GetValue()
if value == "":
self.tlink.SetURL("https://epsg.io/")
self.tlink.SetURL("https://spatialreference.org/")
self.epsgcode = None
self.epsgdesc = self.epsgparams = ""
self.searchb.ChangeValue("")
self.OnBrowseCodes(None)
self.EnableNext(False)
else:
self.tlink.SetURL(str("https://epsg.io/?q={0}".format(value)))
self.tlink.SetURL(f"https://spatialreference.org/ref/?&search={value}")
data = self.epsglist.Search(index=[0, 1, 2], pattern=value, firstOnly=False)
if data:
index = 0
Expand Down
1 change: 0 additions & 1 deletion gui/wxpython/modules/histogram.py
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,6 @@ def SaveToFile(self, event):

def PrintMenu(self, event):
"""Print options and output menu"""
point = wx.GetMousePosition()
printmenu = Menu()
# Add items to the menu
setup = wx.MenuItem(printmenu, id=wx.ID_ANY, text=_("Page setup"))
Expand Down
Loading

0 comments on commit 84dc11d

Please sign in to comment.