Skip to content

Commit b7bf228

Browse files
authored
style: Fixed ruff formatting errors in wxGUI/gcp (#5082)
* added path.glob() * wrapped item.name in str * removed str wrapper
1 parent 664e689 commit b7bf228

File tree

2 files changed

+22
-45
lines changed

2 files changed

+22
-45
lines changed

gui/wxpython/gcp/manager.py

Lines changed: 22 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import shutil
3434
import sys
3535
from copy import copy
36+
from pathlib import Path
3637
from typing import TYPE_CHECKING
3738

3839
import wx
@@ -466,16 +467,12 @@ def OnLocation(self, event):
466467
self.xylocation = event.GetString()
467468

468469
# create a list of valid mapsets
469-
tmplist = os.listdir(os.path.join(self.grassdatabase, self.xylocation))
470+
location_path = Path(self.grassdatabase) / self.xylocation
470471
self.mapsetList = []
471-
for item in tmplist:
472-
if os.path.isdir(
473-
os.path.join(self.grassdatabase, self.xylocation, item)
474-
) and os.path.exists(
475-
os.path.join(self.grassdatabase, self.xylocation, item, "WIND")
476-
):
477-
if item != "PERMANENT":
478-
self.mapsetList.append(item)
472+
for item in location_path.iterdir():
473+
if item.is_dir() and (item / "WIND").exists():
474+
if item.name != "PERMANENT":
475+
self.mapsetList.append(item.name)
479476

480477
self.xymapset = "PERMANENT"
481478
utils.ListSortLower(self.mapsetList)
@@ -697,25 +694,13 @@ def OnEnterPage(self, event: WizardEvent | None = None) -> None:
697694
self.xymapset = self.parent.gisrc_dict["MAPSET"]
698695

699696
# create a list of groups in selected mapset
700-
if os.path.isdir(
701-
os.path.join(self.grassdatabase, self.xylocation, self.xymapset, "group")
702-
):
703-
tmplist = os.listdir(
704-
os.path.join(
705-
self.grassdatabase, self.xylocation, self.xymapset, "group"
706-
)
707-
)
708-
for item in tmplist:
709-
if os.path.isdir(
710-
os.path.join(
711-
self.grassdatabase,
712-
self.xylocation,
713-
self.xymapset,
714-
"group",
715-
item,
716-
)
717-
):
718-
self.groupList.append(item)
697+
group_path = (
698+
Path(self.grassdatabase) / self.xylocation / self.xymapset / "group"
699+
)
700+
if group_path.is_dir():
701+
for item in group_path.iterdir():
702+
if item.is_dir():
703+
self.groupList.append(item.name)
719704

720705
if maptype == "raster":
721706
self.btn_vgroup.Hide()
@@ -2032,8 +2017,8 @@ def RMSError(self, xygroup, order):
20322017
highest_idx = 0
20332018

20342019
for index in range(self.list.GetItemCount()):
2035-
key = self.list.GetItemData(index)
20362020
if self.list.IsItemChecked(index):
2021+
key = self.list.GetItemData(index)
20372022
fwd_err, bkw_err = errlist[GCPcount].split()
20382023
self.list.SetItem(index, 5, fwd_err)
20392024
self.list.SetItem(index, 6, bkw_err)
@@ -2620,21 +2605,14 @@ def __init__(
26202605
#
26212606
# get list of valid vector directories
26222607
#
2623-
vectlist = os.listdir(
2624-
os.path.join(self.grassdatabase, self.xylocation, self.xymapset, "vector")
2625-
)
2626-
for dir in vectlist:
2627-
if not os.path.isfile(
2628-
os.path.join(
2629-
self.grassdatabase,
2630-
self.xylocation,
2631-
self.xymapset,
2632-
"vector",
2633-
dir,
2634-
"coor",
2635-
)
2636-
):
2637-
vectlist.remove(dir)
2608+
vector_path = (
2609+
Path(self.grassdatabase) / self.xylocation / self.xymapset / "vector"
2610+
)
2611+
vectlist = [
2612+
coor_path.parent.name
2613+
for coor_path in vector_path.glob("*/coor")
2614+
if coor_path.is_file()
2615+
]
26382616

26392617
utils.ListSortLower(vectlist)
26402618

pyproject.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,6 @@ ignore = [
284284
# Other ignores:
285285
"**.py" = ["PYI066"]
286286
"*/testsuite/**.py" = ["PT009", "PT027"]
287-
"gui/wxpython/gcp/manager.py" = ["PTH208"]
288287
"gui/wxpython/gui_core/dialogs.py" = ["PTH208"]
289288
"gui/wxpython/gui_core/forms.py" = ["SIM115"]
290289
"gui/wxpython/gui_core/goutput.py" = ["SIM115"]

0 commit comments

Comments
 (0)