Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

style: Fix os-getcwd (PTH109) by replacing os.getcwd() calls with Path.cwd() #4413

Merged
merged 1 commit into from
Sep 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions gui/wxpython/animation/dialogs.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
import wx
import copy
import datetime

from pathlib import Path

import wx.lib.filebrowsebutton as filebrowse
import wx.lib.scrolledpanel as SP
import wx.lib.colourselect as csel
Expand Down Expand Up @@ -488,7 +491,7 @@ def _create3DPanel(self, parent):
labelText=_("Workspace file:"),
dialogTitle=_("Choose workspace file to import 3D view parameters"),
buttonText=_("Browse"),
startDirectory=os.getcwd(),
startDirectory=str(Path.cwd()),
fileMode=0,
fileMask="GRASS Workspace File (*.gxw)|*.gxw",
)
Expand Down Expand Up @@ -1089,7 +1092,7 @@ def _createDecorationsProperties(self, panel):
labelText=_("Image file:"),
dialogTitle=_("Choose image file"),
buttonText=_("Browse"),
startDirectory=os.getcwd(),
startDirectory=str(Path.cwd()),
fileMode=wx.FD_OPEN,
changeCallback=self.OnSetImage,
)
Expand Down Expand Up @@ -1191,7 +1194,7 @@ def _createExportFormatPanel(self, notebook):
labelText=_("Directory:"),
dialogTitle=_("Choose directory for export"),
buttonText=_("Browse"),
startDirectory=os.getcwd(),
startDirectory=str(Path.cwd()),
)

dirGridSizer = wx.GridBagSizer(hgap=5, vgap=5)
Expand Down Expand Up @@ -1219,7 +1222,7 @@ def _createExportFormatPanel(self, notebook):
labelText=_("GIF file:"),
dialogTitle=_("Choose file to save animation"),
buttonText=_("Browse"),
startDirectory=os.getcwd(),
startDirectory=str(Path.cwd()),
fileMode=wx.FD_SAVE,
)
gifGridSizer = wx.GridBagSizer(hgap=5, vgap=5)
Expand All @@ -1242,7 +1245,7 @@ def _createExportFormatPanel(self, notebook):
labelText=_("SWF file:"),
dialogTitle=_("Choose file to save animation"),
buttonText=_("Browse"),
startDirectory=os.getcwd(),
startDirectory=str(Path.cwd()),
fileMode=wx.FD_SAVE,
)
swfGridSizer = wx.GridBagSizer(hgap=5, vgap=5)
Expand Down Expand Up @@ -1273,7 +1276,7 @@ def _createExportFormatPanel(self, notebook):
labelText=_("AVI file:"),
dialogTitle=_("Choose file to save animation"),
buttonText=_("Browse"),
startDirectory=os.getcwd(),
startDirectory=str(Path.cwd()),
fileMode=wx.FD_SAVE,
)
encodingLabel = StaticText(
Expand Down
7 changes: 6 additions & 1 deletion gui/wxpython/datacatalog/catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
import wx
import os

from pathlib import Path

from core.debug import Debug
from datacatalog.tree import DataCatalogTree
from datacatalog.toolbars import DataCatalogToolbar, DataCatalogSearch
Expand Down Expand Up @@ -200,7 +202,10 @@ def OnReloadCurrentMapset(self, event):
def OnAddGrassDB(self, event):
"""Add grass database"""
dlg = wx.DirDialog(
self, _("Choose GRASS data directory:"), os.getcwd(), wx.DD_DEFAULT_STYLE
self,
_("Choose GRASS data directory:"),
str(Path.cwd()),
wx.DD_DEFAULT_STYLE,
)
if dlg.ShowModal() == wx.ID_OK:
grassdatabase = dlg.GetPath()
Expand Down
8 changes: 5 additions & 3 deletions gui/wxpython/gmodeler/panels.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
import random
import math

from pathlib import Path

import wx

from wx.lib import ogl
Expand Down Expand Up @@ -834,7 +836,7 @@ def OnModelOpen(self, event):
dlg = wx.FileDialog(
parent=self,
message=_("Choose model file"),
defaultDir=os.getcwd(),
defaultDir=str(Path.cwd()),
wildcard=_("GRASS Model File (*.gxm)|*.gxm"),
)
if dlg.ShowModal() == wx.ID_OK:
Expand Down Expand Up @@ -892,7 +894,7 @@ def OnModelSaveAs(self, event=None):
dlg = wx.FileDialog(
parent=self,
message=_("Choose file to save current model"),
defaultDir=os.getcwd(),
defaultDir=str(Path.cwd()),
wildcard=_("GRASS Model File (*.gxm)|*.gxm"),
style=wx.FD_SAVE,
)
Expand Down Expand Up @@ -1740,7 +1742,7 @@ def SaveAs(self, force=False):
parent=self,
message=_("Choose file to save"),
defaultFile=os.path.basename(self.parent.GetModelFile(ext=False)),
defaultDir=os.getcwd(),
defaultDir=str(Path.cwd()),
wildcard=fn_wildcard,
style=wx.FD_SAVE,
)
Expand Down
7 changes: 4 additions & 3 deletions gui/wxpython/gui_core/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
import codecs

from threading import Thread
from pathlib import Path

import wx

Expand Down Expand Up @@ -2034,7 +2035,7 @@ def __init__(self, parent, giface, task, id=wx.ID_ANY, frame=None, *args, **kwar
dialogTitle=_("Choose %s")
% p.get("description", _("file")).lower(),
buttonText=_("Browse"),
startDirectory=os.getcwd(),
startDirectory=str(Path.cwd()),
fileMode=fmode,
changeCallback=self.OnSetValue,
)
Expand Down Expand Up @@ -2145,7 +2146,7 @@ def __init__(self, parent, giface, task, id=wx.ID_ANY, frame=None, *args, **kwar
dialogTitle=_("Choose %s")
% p.get("description", _("Directory")),
buttonText=_("Browse"),
startDirectory=os.getcwd(),
startDirectory=str(Path.cwd()),
newDirectory=True,
changeCallback=self.OnSetValue,
)
Expand Down Expand Up @@ -2624,7 +2625,7 @@ def OnFileSave(self, event):
dlg = wx.FileDialog(
parent=self,
message=_("Save input as..."),
defaultDir=os.getcwd(),
defaultDir=str(Path.cwd()),
style=wx.FD_SAVE | wx.FD_OVERWRITE_PROMPT,
)

Expand Down
10 changes: 6 additions & 4 deletions gui/wxpython/gui_core/gselect.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@
import glob
import ctypes

from pathlib import Path

import wx

from core import globalvar
Expand Down Expand Up @@ -1558,7 +1560,7 @@ def __init__(
labelText=_("File:"),
dialogTitle=_("Choose file to import"),
buttonText=_("Browse"),
startDirectory=os.getcwd(),
startDirectory=str(Path.cwd()),
changeCallback=self.OnUpdate,
fileMask=fileMask,
)
Expand All @@ -1575,7 +1577,7 @@ def __init__(
labelText=_("Directory:"),
dialogTitle=_("Choose input directory"),
buttonText=_("Browse"),
startDirectory=os.getcwd(),
startDirectory=str(Path.cwd()),
changeCallback=self.OnUpdate,
)
browse.GetChildren()[1].SetName("GdalSelectDataSource")
Expand Down Expand Up @@ -1628,7 +1630,7 @@ def __init__(
labelText=_("Name:"),
dialogTitle=_("Choose file"),
buttonText=_("Browse"),
startDirectory=os.getcwd(),
startDirectory=str(Path.cwd()),
changeCallback=self.OnUpdate,
)
browse.GetChildren()[1].SetName("GdalSelectDataSource")
Expand Down Expand Up @@ -1663,7 +1665,7 @@ def __init__(
labelText=_("Directory:"),
dialogTitle=_("Choose input directory"),
buttonText=_("Browse"),
startDirectory=os.getcwd(),
startDirectory=str(Path.cwd()),
changeCallback=self.OnUpdate,
)
self.dbWidgets["dirbrowse"] = browse
Expand Down
4 changes: 2 additions & 2 deletions gui/wxpython/gui_core/pyedit.py
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ def SaveAs(self):
dlg = wx.FileDialog(
parent=self.guiparent,
message=_("Choose file to save"),
defaultDir=os.getcwd(),
defaultDir=str(Path.cwd()),
wildcard=_("Python script (*.py)|*.py"),
style=wx.FD_SAVE,
)
Expand Down Expand Up @@ -466,7 +466,7 @@ def Open(self):
dlg = wx.FileDialog(
parent=self.guiparent,
message=_("Open file"),
defaultDir=os.getcwd(),
defaultDir=str(Path.cwd()),
wildcard=_("Python script (*.py)|*.py"),
style=wx.FD_OPEN,
)
Expand Down
4 changes: 3 additions & 1 deletion gui/wxpython/image2target/ii2t_gis_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
import platform
import getpass

from pathlib import Path

from core import globalvar
import wx
import wx.lib.mixins.listctrl as listmix
Expand Down Expand Up @@ -315,7 +317,7 @@ def _set_properties(self, version, revision):
if os.path.isdir(os.getenv("HOME")):
self.gisdbase = os.getenv("HOME")
else:
self.gisdbase = os.getcwd()
self.gisdbase = str(Path.cwd())
try:
self.tgisdbase.SetValue(self.gisdbase)
except UnicodeDecodeError:
Expand Down
12 changes: 6 additions & 6 deletions gui/wxpython/lmgr/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
import platform
import re

from pathlib import Path

from core import globalvar
import wx
import wx.aui
Expand Down Expand Up @@ -848,7 +850,7 @@ def OnRunModel(self, event):
dlg = wx.FileDialog(
parent=self,
message=_("Choose model to run"),
defaultDir=os.getcwd(),
defaultDir=str(Path.cwd()),
wildcard=_("GRASS Model File (*.gxm)|*.gxm"),
)
if dlg.ShowModal() == wx.ID_OK:
Expand Down Expand Up @@ -1223,7 +1225,7 @@ def OnRunScript(self, event):
dlg = wx.FileDialog(
parent=self,
message=_("Choose script file to run"),
defaultDir=os.getcwd(),
defaultDir=str(Path.cwd()),
wildcard=_("Python script (*.py)|*.py|Bash script (*.sh)|*.sh"),
)

Expand Down Expand Up @@ -1377,9 +1379,7 @@ def write_beginning(parameter=None, command=None):
self._giface.WriteCmdLog(" ".join(command))

def write_changed():
self._giface.WriteLog(
_('Working directory changed to:\n"%s"') % os.getcwd()
)
self._giface.WriteLog(_('Working directory changed to:\n"%s"') % Path.cwd())

def write_end():
self._giface.WriteCmdLog(" ")
Expand Down Expand Up @@ -1433,7 +1433,7 @@ def write_help():
dlg = wx.DirDialog(
parent=self,
message=_("Choose a working directory"),
defaultPath=os.getcwd(),
defaultPath=str(Path.cwd()),
)

if dlg.ShowModal() == wx.ID_OK:
Expand Down
6 changes: 4 additions & 2 deletions gui/wxpython/lmgr/workspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

import xml.etree.ElementTree as ET

from pathlib import Path

import wx
import wx.aui

Expand Down Expand Up @@ -103,7 +105,7 @@ def Open(self):
dlg = wx.FileDialog(
parent=self.lmgr,
message=_("Choose workspace file"),
defaultDir=os.getcwd(),
defaultDir=str(Path.cwd()),
wildcard=_("GRASS Workspace File (*.gxw)|*.gxw"),
)

Expand Down Expand Up @@ -362,7 +364,7 @@ def SaveAs(self):
dlg = wx.FileDialog(
parent=self.lmgr,
message=_("Choose file to save current workspace"),
defaultDir=os.getcwd(),
defaultDir=str(Path.cwd()),
wildcard=_("GRASS Workspace File (*.gxw)|*.gxw"),
style=wx.FD_SAVE,
)
Expand Down
11 changes: 8 additions & 3 deletions gui/wxpython/location_wizard/wizard.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
import locale
import functools

from pathlib import Path

import wx
import wx.lib.mixins.listctrl as listmix
from core import globalvar
Expand Down Expand Up @@ -318,7 +320,10 @@ def OnChangeName(self, event):
def OnBrowse(self, event):
"""Choose GRASS data directory"""
dlg = wx.DirDialog(
self, _("Choose GRASS data directory:"), os.getcwd(), wx.DD_DEFAULT_STYLE
self,
_("Choose GRASS data directory:"),
str(Path.cwd()),
wx.DD_DEFAULT_STYLE,
)
if dlg.ShowModal() == wx.ID_OK:
self.grassdatabase = dlg.GetPath()
Expand Down Expand Up @@ -1493,7 +1498,7 @@ def OnText(self, event):
def OnBrowse(self, event):
"""Choose file"""
dlg = wx.FileDialog(
self, _("Select georeferenced file"), os.getcwd(), "", "*.*", wx.FD_OPEN
self, _("Select georeferenced file"), str(Path.cwd()), "", "*.*", wx.FD_OPEN
)
if dlg.ShowModal() == wx.ID_OK:
path = dlg.GetPath()
Expand Down Expand Up @@ -1977,7 +1982,7 @@ def OnBrowse(self, event):
"""Define path for IAU code file"""
path = os.path.dirname(self.tfile.GetValue())
if not path:
path = os.getcwd()
path = str(Path.cwd())

dlg = wx.FileDialog(
parent=self,
Expand Down
12 changes: 6 additions & 6 deletions gui/wxpython/main_window/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
import platform
import re

from pathlib import Path

from core import globalvar

try:
Expand Down Expand Up @@ -971,7 +973,7 @@ def OnRunModel(self, event):
dlg = wx.FileDialog(
parent=self,
message=_("Choose model to run"),
defaultDir=os.getcwd(),
defaultDir=str(Path.cwd()),
wildcard=_("GRASS Model File (*.gxm)|*.gxm"),
)
if dlg.ShowModal() == wx.ID_OK:
Expand Down Expand Up @@ -1374,7 +1376,7 @@ def OnRunScript(self, event):
dlg = wx.FileDialog(
parent=self,
message=_("Choose script file to run"),
defaultDir=os.getcwd(),
defaultDir=str(Path.cwd()),
wildcard=_("Python script (*.py)|*.py|Bash script (*.sh)|*.sh"),
)

Expand Down Expand Up @@ -1528,9 +1530,7 @@ def write_beginning(parameter=None, command=None):
self._giface.WriteCmdLog(" ".join(command))

def write_changed():
self._giface.WriteLog(
_('Working directory changed to:\n"%s"') % os.getcwd()
)
self._giface.WriteLog(_('Working directory changed to:\n"%s"') % Path.cwd())

def write_end():
self._giface.WriteCmdLog(" ")
Expand Down Expand Up @@ -1584,7 +1584,7 @@ def write_help():
dlg = wx.DirDialog(
parent=self,
message=_("Choose a working directory"),
defaultPath=os.getcwd(),
defaultPath=str(Path.cwd()),
)

if dlg.ShowModal() == wx.ID_OK:
Expand Down
Loading
Loading