Skip to content

Commit

Permalink
Merge branch 'main' into utils-pyrefact-contextmanager
Browse files Browse the repository at this point in the history
  • Loading branch information
echoix committed Jan 4, 2025
2 parents 7a45fcb + 3f98304 commit d1455f5
Show file tree
Hide file tree
Showing 82 changed files with 498 additions and 589 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.5"
RUFF_VERSION: "0.8.6"

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.5
rev: v0.8.6
hooks:
# Run the linter.
- id: ruff
Expand Down
4 changes: 1 addition & 3 deletions gui/wxpython/animation/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,9 +240,7 @@ def _computeRegions(self, count, startRegion, endRegion=None, zoomValue=None):
del region["projection"]
if "zone" in region:
del region["zone"]
regions = []
for i in range(self._mapCount):
regions.append(copy.copy(region))
regions = [copy.copy(region) for i in range(self._mapCount)]
self._regions = regions
if not (endRegion or zoomValue):
return
Expand Down
4 changes: 1 addition & 3 deletions gui/wxpython/animation/nviztask.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,7 @@ def _processSurface(self, surface, mapName):
self._setMultiTaskParam(mode2, value)

# position
pos = []
for coor in ("x", "y", "z"):
pos.append(str(surface["position"][coor]))
pos = [str(surface["position"][coor]) for coor in ("x", "y", "z")]
value = ",".join(pos)
self._setMultiTaskParam("surface_position", value)

Expand Down
18 changes: 9 additions & 9 deletions gui/wxpython/animation/temporal_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,7 @@ def _setTemporalState(self):

# check for units for relative type
if relative:
units = set()
units.update(infoDict["unit"] for infoDict in self.timeseriesInfo.values())
units = {infoDict["unit"] for infoDict in self.timeseriesInfo.values()}
if len(units) > 1:
message = _(
"It is not allowed to display data with different units (%s)."
Expand Down Expand Up @@ -162,10 +161,11 @@ def GetGranularity(self):
return self._getCommonGranularity()

def _getCommonGranularity(self):
allMaps = []
for dataset in self.timeseriesList:
maps = self.timeseriesInfo[dataset]["maps"]
allMaps.extend(maps)
allMaps = [
a
for dataset in self.timeseriesList
for a in self.timeseriesInfo[dataset]["maps"]
]

if self.temporalType == TemporalType.ABSOLUTE:
gran = tgis.compute_absolute_time_granularity(allMaps)
Expand Down Expand Up @@ -210,9 +210,9 @@ def GetLabelsAndMaps(self):
newMapList[i : i + len(mapList)] = mapList
newMapLists.append(newMapList)

mapDict = {}
for i, dataset in enumerate(self.timeseriesList):
mapDict[dataset] = newMapLists[i]
mapDict = {
dataset: newMapLists[i] for i, dataset in enumerate(self.timeseriesList)
}

if self.temporalType == TemporalType.ABSOLUTE:
# ('1996-01-01 00:00:00', '1997-01-01 00:00:00', 'year'),
Expand Down
5 changes: 1 addition & 4 deletions gui/wxpython/animation/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,7 @@ def checkSeriesCompatibility(mapSeriesList=None, timeseriesList=None):
)

if mapSeriesList:
count = set()
count.update(len(mapSeries) for mapSeries in mapSeriesList)
count = {len(mapSeries) for mapSeries in mapSeriesList}
if len(count) > 1:
raise GException(
_(
Expand All @@ -240,11 +239,9 @@ def ComputeScaledRect(sourceSize, destSize):
"""Fits source rectangle into destination rectangle
by scaling and centering.
>>> ComputeScaledRect(sourceSize = (10, 40), destSize = (100, 50))
{'height': 50, 'scale': 1.25, 'width': 13, 'x': 44, 'y': 0}
:param sourceSize: size of source rectangle
:param destSize: size of destination rectangle
"""
Expand Down
6 changes: 1 addition & 5 deletions gui/wxpython/core/layerlist.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,7 @@ def GetLayersByTypes(self, mapTypes):
:param mapTypes: list of types
"""
layers = []
for layer in self._list:
if layer.mapType in mapTypes:
layers.append(layer)
return layers
return [layer for layer in self._list if layer.mapType in mapTypes]

def AddNewLayer(
self,
Expand Down
16 changes: 4 additions & 12 deletions gui/wxpython/core/render.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,7 @@ def __init__(
self.name = name

if self.type == "command":
self.cmd = []
for c in cmd:
self.cmd.append(cmdlist_to_tuple(c))
self.cmd = [] + [cmdlist_to_tuple(c) for c in cmd]
else:
self.cmd = cmdlist_to_tuple(cmd)

Expand Down Expand Up @@ -326,9 +324,7 @@ def SetOpacity(self, value):
def SetCmd(self, cmd):
"""Set new command for layer"""
if self.type == "command":
self.cmd = []
for c in cmd:
self.cmd.append(cmdlist_to_tuple(c))
self.cmd = [] + [cmdlist_to_tuple(c) for c in cmd]
else:
self.cmd = cmdlist_to_tuple(cmd)
Debug.msg(3, "Layer.SetCmd(): cmd='%s'" % self.GetCmd(string=True))
Expand Down Expand Up @@ -1055,8 +1051,7 @@ def GetRegion(
env["GISRC"] = self.gisrc

# do not update & shell style output
cmd = {}
cmd["flags"] = "ugpc"
cmd = {"flags": "ugpc"}

if default:
cmd["flags"] += "d"
Expand Down Expand Up @@ -1656,10 +1651,7 @@ def GetOverlay(self, id, list=False):
:return: overlay (list=False)
:return: None (list=False) if no overlay or more overlays found
"""
ovl = []
for overlay in self.overlays:
if overlay.id == id:
ovl.append(overlay)
ovl = [overlay for overlay in self.overlays if overlay.id == id]

if not list:
if len(ovl) != 1:
Expand Down
9 changes: 5 additions & 4 deletions gui/wxpython/core/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -1230,12 +1230,13 @@ def GetDisplayVectSettings():
% UserSettings.Get(group="vectorLayer", key="point", subkey="size"),
)
)
types = []
for ftype in ["point", "line", "boundary", "centroid", "area", "face"]:
types = [
ftype
for ftype in ["point", "line", "boundary", "centroid", "area", "face"]
if UserSettings.Get(
group="vectorLayer", key="showType", subkey=[ftype, "enabled"]
):
types.append(ftype)
)
]
settings.append("type=%s" % ",".join(types))

if UserSettings.Get(group="vectorLayer", key="randomColors", subkey="enabled"):
Expand Down
9 changes: 3 additions & 6 deletions gui/wxpython/core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -918,9 +918,8 @@ def SetAddOnPath(addonPath=None, key="PATH"):
"white": (255, 255, 255),
"yellow": (255, 255, 0),
}
rgb2str = {}
for s, r in str2rgb.items():
rgb2str[r] = s

rgb2str = {r: s for s, r in str2rgb.items()}
# ensure that gray value has 'gray' string and not 'grey'
rgb2str[str2rgb["gray"]] = "gray"
# purple is defined as nickname for violet in lib/gis
Expand Down Expand Up @@ -974,9 +973,7 @@ def color_resolve(color):
"d.polar": "polar",
"d.legend.vect": "vectleg",
}
ltype2command = {}
for cmd, ltype in command2ltype.items():
ltype2command[ltype] = cmd
ltype2command = {ltype: cmd for cmd, ltype in command2ltype.items()}


def GetGEventAttribsForHandler(method, event):
Expand Down
2 changes: 1 addition & 1 deletion gui/wxpython/core/workspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -1461,7 +1461,7 @@ def __writeNvizVector(self, data):
self.indent -= 4

def __writeNvizState(self, view, iview, light, constants):
""" "Save Nviz properties (view, light) to workspace
"""Save Nviz properties (view, light) to workspace
:param view: Nviz view properties
:param iview: Nviz internal view properties
Expand Down
4 changes: 1 addition & 3 deletions gui/wxpython/dbmgr/vinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,7 @@ def SelectByPoint(self, queryCoords, qdist):
return None

# process attributes
ret = {}
for key in ["Category", "Layer", "Table", "Id"]:
ret[key] = []
ret = {key: [] for key in ["Category", "Layer", "Table", "Id"]}

for record in data:
if "Table" not in record:
Expand Down
14 changes: 7 additions & 7 deletions gui/wxpython/gcp/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -1000,10 +1000,11 @@ def GetWebServiceLayers(self, ltype=("wms"), name=None):
}
:return: None when web service map layer name doesn't exist
"""
layers = {}
for layer in self.parent._giface.GetLayerList():
if layer.type in ltype:
layers[str(layer)] = {"type": layer.type, "cmd": layer.cmd}
layers = {
str(layer): {"type": layer.type, "cmd": layer.cmd}
for layer in self.parent._giface.GetLayerList()
if layer.type in ltype
}
if name:
return layers.get(name)
return layers
Expand Down Expand Up @@ -1407,9 +1408,8 @@ def SetSettings(self):
font = self.GetFont()
font.SetPointSize(int(spx) + 2)

textProp = {}
textProp["active"] = True
textProp["font"] = font
textProp = {"active": True, "font": font}

self.pointsToDrawSrc.SetPropertyVal("text", textProp)
self.pointsToDrawTgt.SetPropertyVal("text", copy(textProp))

Expand Down
4 changes: 1 addition & 3 deletions gui/wxpython/gmodeler/dialogs.py
Original file line number Diff line number Diff line change
Expand Up @@ -978,9 +978,7 @@ def Populate(self, data):
bId = action.GetBlockId()
bId = _("No") if not bId else _("Yes")
options = action.GetParameterizedParams()
params = []
for f in options["flags"]:
params.append("-{0}".format(f["name"]))
params = ["-{0}".format(f["name"]) for f in options["flags"]]
for p in options["params"]:
params.append(p["name"])

Expand Down
51 changes: 13 additions & 38 deletions gui/wxpython/gmodeler/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,7 @@ def GetItems(self, objType=None):
if not objType:
return self.items

result = []
for item in self.items:
if isinstance(item, objType):
result.append(item)

return result
return [item for item in self.items if isinstance(item, objType)]

def GetItem(self, aId, objType=None):
"""Get item of given id
Expand Down Expand Up @@ -683,11 +678,12 @@ def Run(self, log, onDone, parent=None):
GError(parent=parent, message="\n".join(err))
return

err = []
for key, item in params.items():
for p in item["params"]:
if p.get("value", "") == "":
err.append((key, p.get("name", ""), p.get("description", "")))
err = [
(key, p.get("name", ""), p.get("description", ""))
for key, item in params.items()
for p in item["params"]
if p.get("value", "") == ""
]
if err:
GError(
parent=parent,
Expand Down Expand Up @@ -990,11 +986,7 @@ def GetBlockId(self):
:return: list of ids
"""
ret = []
for mo in self.inBlock:
ret.append(mo.GetId())

return ret
return [mo.GetId() for mo in self.inBlock]


class ModelAction(ModelObject, ogl.DividedShape):
Expand Down Expand Up @@ -1409,20 +1401,14 @@ def OnDraw(self, dc):

def GetLog(self, string=True):
"""Get logging info"""
name = []
for rel in self.GetRelations():
name.append(rel.GetLabel())
name = [rel.GetLabel() for rel in self.GetRelations()]
if name:
return "/".join(name) + "=" + self.value + " (" + self.prompt + ")"
return self.value + " (" + self.prompt + ")"

def GetLabel(self):
"""Get list of names"""
name = []
for rel in self.GetRelations():
name.append(rel.GetLabel())

return name
return [rel.GetLabel() for rel in self.GetRelations()]

def GetPrompt(self):
"""Get prompt"""
Expand Down Expand Up @@ -1528,9 +1514,7 @@ def _setPen(self):
def SetLabel(self):
"""Update text"""
self.ClearText()
name = []
for rel in self.GetRelations():
name.append(rel.GetLabel())
name = [rel.GetLabel() for rel in self.GetRelations()]
self.AddText("/".join(name))
if self.value:
self.AddText(self.value)
Expand Down Expand Up @@ -1795,12 +1779,7 @@ def Update(self):

def GetItems(self, items):
"""Get sorted items by id"""
result = []
for item in items:
if item.GetId() in self.itemIds:
result.append(item)

return result
return [item for item in items if item.GetId() in self.itemIds]

def SetItems(self, items):
"""Set items (id)"""
Expand Down Expand Up @@ -3731,11 +3710,7 @@ def _createPage(self, name, params):

def GetErrors(self):
"""Check for errors, get list of messages"""
errList = []
for task in self.tasks:
errList += task.get_cmd_error()

return errList
return [task.get_cmd_error() for task in self.tasks]

def DeleteIntermediateData(self) -> bool:
"""Check if to delete intermediate data"""
Expand Down
Loading

0 comments on commit d1455f5

Please sign in to comment.