Skip to content

Commit

Permalink
style: Fix unconventional-import-alias (ICN001) (consolidate `import …
Browse files Browse the repository at this point in the history
…grass.script as gs`) (OSGeo#3981)

* style: Unignore unconventional-import-alias (ICN001) ruff rule

* style: Use convention `import matplotlib as mpl`

* style: Use convention `import numpy as np`

* style: Use convention `import grass.script as gs`

* test: Remove unused grass.script in test file

* style: Add missing alias to `import grass.script as gs`

* style: Alias `import grass.script as gs` when already imported at file-level

* Remove duplicated grass.script lazy import in wxpython/gui_core/ghelp.py
  • Loading branch information
echoix authored Jul 4, 2024
1 parent 931e79a commit d880ec0
Show file tree
Hide file tree
Showing 187 changed files with 2,283 additions and 2,389 deletions.
6 changes: 3 additions & 3 deletions gui/wxpython/animation/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import wx
import wx.aui

import grass.script as gcore
import grass.script as gs
import grass.temporal as tgis
from grass.exceptions import FatalError
from core import globalvar
Expand All @@ -42,7 +42,7 @@
MAX_COUNT = 4
TMP_DIR = None

gcore.set_raise_on_error(True)
gs.set_raise_on_error(True)


class AnimationFrame(wx.Frame):
Expand Down Expand Up @@ -71,7 +71,7 @@ def __init__(
# create temporal directory and ensure it's deleted after programs ends
# (stored in MAPSET/.tmp/)
global TMP_DIR
TMP_DIR = gcore.tempdir()
TMP_DIR = gs.tempdir()

self.animations = [Animation() for i in range(MAX_COUNT)]
self.windows = []
Expand Down
6 changes: 3 additions & 3 deletions gui/wxpython/animation/g.gui.animation.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,12 @@
# % guisection: Input
# %end

import grass.script as gscript
import grass.script as gs
from grass.exceptions import FatalError


def main():
options, flags = gscript.parser()
options, flags = gs.parser()

# import wx only after running parser
# to avoid issues when only interface is needed
Expand Down Expand Up @@ -89,7 +89,7 @@ def main():
numInputs += 1

if numInputs > 1:
gscript.fatal(
gs.fatal(
_("%s=, %s=, %s= and %s= are mutually exclusive.")
% ("raster", "vector", "strds", "stvds")
)
Expand Down
124 changes: 61 additions & 63 deletions gui/wxpython/animation/temporal_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

import datetime

import grass.script as grass
import grass.script as gs
import grass.temporal as tgis
from core.gcmd import GException
from core.settings import UserSettings
Expand Down Expand Up @@ -389,7 +389,7 @@ def test():


def createAbsoluteInterval():
grass.run_command(
gs.run_command(
"g.region",
s=0,
n=80,
Expand All @@ -403,21 +403,21 @@ def createAbsoluteInterval():
quiet=True,
)

grass.mapcalc(exp="prec_1 = rand(0, 550)", overwrite=True)
grass.mapcalc(exp="prec_2 = rand(0, 450)", overwrite=True)
grass.mapcalc(exp="prec_3 = rand(0, 320)", overwrite=True)
grass.mapcalc(exp="prec_4 = rand(0, 510)", overwrite=True)
grass.mapcalc(exp="prec_5 = rand(0, 300)", overwrite=True)
grass.mapcalc(exp="prec_6 = rand(0, 650)", overwrite=True)

grass.mapcalc(exp="temp_1 = rand(0, 550)", overwrite=True)
grass.mapcalc(exp="temp_2 = rand(0, 450)", overwrite=True)
grass.mapcalc(exp="temp_3 = rand(0, 320)", overwrite=True)
grass.mapcalc(exp="temp_4 = rand(0, 510)", overwrite=True)
grass.mapcalc(exp="temp_5 = rand(0, 300)", overwrite=True)
grass.mapcalc(exp="temp_6 = rand(0, 650)", overwrite=True)

n1 = grass.read_command("g.tempfile", pid=1, flags="d").strip()
gs.mapcalc(exp="prec_1 = rand(0, 550)", overwrite=True)
gs.mapcalc(exp="prec_2 = rand(0, 450)", overwrite=True)
gs.mapcalc(exp="prec_3 = rand(0, 320)", overwrite=True)
gs.mapcalc(exp="prec_4 = rand(0, 510)", overwrite=True)
gs.mapcalc(exp="prec_5 = rand(0, 300)", overwrite=True)
gs.mapcalc(exp="prec_6 = rand(0, 650)", overwrite=True)

gs.mapcalc(exp="temp_1 = rand(0, 550)", overwrite=True)
gs.mapcalc(exp="temp_2 = rand(0, 450)", overwrite=True)
gs.mapcalc(exp="temp_3 = rand(0, 320)", overwrite=True)
gs.mapcalc(exp="temp_4 = rand(0, 510)", overwrite=True)
gs.mapcalc(exp="temp_5 = rand(0, 300)", overwrite=True)
gs.mapcalc(exp="temp_6 = rand(0, 650)", overwrite=True)

n1 = gs.read_command("g.tempfile", pid=1, flags="d").strip()
fd = open(n1, "w")
fd.write(
"prec_1|2001-01-01|2001-02-01\n"
Expand All @@ -429,7 +429,7 @@ def createAbsoluteInterval():
)
fd.close()

n2 = grass.read_command("g.tempfile", pid=2, flags="d").strip()
n2 = gs.read_command("g.tempfile", pid=2, flags="d").strip()
fd = open(n2, "w")
fd.write(
"temp_1|2000-10-01|2001-01-01\n"
Expand All @@ -442,14 +442,14 @@ def createAbsoluteInterval():
fd.close()
name1 = "absinterval1"
name2 = "absinterval2"
grass.run_command(
gs.run_command(
"t.unregister",
type="raster",
maps="prec_1,prec_2,prec_3,prec_4,prec_5,prec_6,"
"temp_1,temp_2,temp_3,temp_4,temp_5,temp_6",
)
for name, fname in zip((name1, name2), (n1, n2)):
grass.run_command(
gs.run_command(
"t.create",
overwrite=True,
type="strds",
Expand All @@ -458,15 +458,13 @@ def createAbsoluteInterval():
title="A test with input files",
descr="A test with input files",
)
grass.run_command(
"t.register", flags="i", input=name, file=fname, overwrite=True
)
gs.run_command("t.register", flags="i", input=name, file=fname, overwrite=True)

return name1, name2


def createRelativeInterval():
grass.run_command(
gs.run_command(
"g.region",
s=0,
n=80,
Expand All @@ -480,21 +478,21 @@ def createRelativeInterval():
quiet=True,
)

grass.mapcalc(exp="prec_1 = rand(0, 550)", overwrite=True)
grass.mapcalc(exp="prec_2 = rand(0, 450)", overwrite=True)
grass.mapcalc(exp="prec_3 = rand(0, 320)", overwrite=True)
grass.mapcalc(exp="prec_4 = rand(0, 510)", overwrite=True)
grass.mapcalc(exp="prec_5 = rand(0, 300)", overwrite=True)
grass.mapcalc(exp="prec_6 = rand(0, 650)", overwrite=True)

grass.mapcalc(exp="temp_1 = rand(0, 550)", overwrite=True)
grass.mapcalc(exp="temp_2 = rand(0, 450)", overwrite=True)
grass.mapcalc(exp="temp_3 = rand(0, 320)", overwrite=True)
grass.mapcalc(exp="temp_4 = rand(0, 510)", overwrite=True)
grass.mapcalc(exp="temp_5 = rand(0, 300)", overwrite=True)
grass.mapcalc(exp="temp_6 = rand(0, 650)", overwrite=True)

n1 = grass.read_command("g.tempfile", pid=1, flags="d").strip()
gs.mapcalc(exp="prec_1 = rand(0, 550)", overwrite=True)
gs.mapcalc(exp="prec_2 = rand(0, 450)", overwrite=True)
gs.mapcalc(exp="prec_3 = rand(0, 320)", overwrite=True)
gs.mapcalc(exp="prec_4 = rand(0, 510)", overwrite=True)
gs.mapcalc(exp="prec_5 = rand(0, 300)", overwrite=True)
gs.mapcalc(exp="prec_6 = rand(0, 650)", overwrite=True)

gs.mapcalc(exp="temp_1 = rand(0, 550)", overwrite=True)
gs.mapcalc(exp="temp_2 = rand(0, 450)", overwrite=True)
gs.mapcalc(exp="temp_3 = rand(0, 320)", overwrite=True)
gs.mapcalc(exp="temp_4 = rand(0, 510)", overwrite=True)
gs.mapcalc(exp="temp_5 = rand(0, 300)", overwrite=True)
gs.mapcalc(exp="temp_6 = rand(0, 650)", overwrite=True)

n1 = gs.read_command("g.tempfile", pid=1, flags="d").strip()
fd = open(n1, "w")
fd.write(
"prec_1|1|4\n"
Expand All @@ -506,7 +504,7 @@ def createRelativeInterval():
)
fd.close()

n2 = grass.read_command("g.tempfile", pid=2, flags="d").strip()
n2 = gs.read_command("g.tempfile", pid=2, flags="d").strip()
fd = open(n2, "w")
fd.write(
"temp_1|5|6\n"
Expand All @@ -519,14 +517,14 @@ def createRelativeInterval():
fd.close()
name1 = "relinterval1"
name2 = "relinterval2"
grass.run_command(
gs.run_command(
"t.unregister",
type="raster",
maps="prec_1,prec_2,prec_3,prec_4,prec_5,prec_6,"
"temp_1,temp_2,temp_3,temp_4,temp_5,temp_6",
)
for name, fname in zip((name1, name2), (n1, n2)):
grass.run_command(
gs.run_command(
"t.create",
overwrite=True,
type="strds",
Expand All @@ -535,7 +533,7 @@ def createRelativeInterval():
title="A test with input files",
descr="A test with input files",
)
grass.run_command(
gs.run_command(
"t.register",
flags="i",
input=name,
Expand All @@ -547,7 +545,7 @@ def createRelativeInterval():


def createAbsolutePoint():
grass.run_command(
gs.run_command(
"g.region",
s=0,
n=80,
Expand All @@ -561,14 +559,14 @@ def createAbsolutePoint():
quiet=True,
)

grass.mapcalc(exp="prec_1 = rand(0, 550)", overwrite=True)
grass.mapcalc(exp="prec_2 = rand(0, 450)", overwrite=True)
grass.mapcalc(exp="prec_3 = rand(0, 320)", overwrite=True)
grass.mapcalc(exp="prec_4 = rand(0, 510)", overwrite=True)
grass.mapcalc(exp="prec_5 = rand(0, 300)", overwrite=True)
grass.mapcalc(exp="prec_6 = rand(0, 650)", overwrite=True)
gs.mapcalc(exp="prec_1 = rand(0, 550)", overwrite=True)
gs.mapcalc(exp="prec_2 = rand(0, 450)", overwrite=True)
gs.mapcalc(exp="prec_3 = rand(0, 320)", overwrite=True)
gs.mapcalc(exp="prec_4 = rand(0, 510)", overwrite=True)
gs.mapcalc(exp="prec_5 = rand(0, 300)", overwrite=True)
gs.mapcalc(exp="prec_6 = rand(0, 650)", overwrite=True)

n1 = grass.read_command("g.tempfile", pid=1, flags="d").strip()
n1 = gs.read_command("g.tempfile", pid=1, flags="d").strip()
fd = open(n1, "w")
fd.write(
"prec_1|2001-01-01\n"
Expand All @@ -580,7 +578,7 @@ def createAbsolutePoint():
)
fd.close()
name = "abspoint"
grass.run_command(
gs.run_command(
"t.create",
overwrite=True,
type="strds",
Expand All @@ -590,12 +588,12 @@ def createAbsolutePoint():
descr="A test with input files",
)

grass.run_command("t.register", flags="i", input=name, file=n1, overwrite=True)
gs.run_command("t.register", flags="i", input=name, file=n1, overwrite=True)
return name


def createRelativePoint():
grass.run_command(
gs.run_command(
"g.region",
s=0,
n=80,
Expand All @@ -609,19 +607,19 @@ def createRelativePoint():
quiet=True,
)

grass.mapcalc(exp="prec_1 = rand(0, 550)", overwrite=True)
grass.mapcalc(exp="prec_2 = rand(0, 450)", overwrite=True)
grass.mapcalc(exp="prec_3 = rand(0, 320)", overwrite=True)
grass.mapcalc(exp="prec_4 = rand(0, 510)", overwrite=True)
grass.mapcalc(exp="prec_5 = rand(0, 300)", overwrite=True)
grass.mapcalc(exp="prec_6 = rand(0, 650)", overwrite=True)
gs.mapcalc(exp="prec_1 = rand(0, 550)", overwrite=True)
gs.mapcalc(exp="prec_2 = rand(0, 450)", overwrite=True)
gs.mapcalc(exp="prec_3 = rand(0, 320)", overwrite=True)
gs.mapcalc(exp="prec_4 = rand(0, 510)", overwrite=True)
gs.mapcalc(exp="prec_5 = rand(0, 300)", overwrite=True)
gs.mapcalc(exp="prec_6 = rand(0, 650)", overwrite=True)

n1 = grass.read_command("g.tempfile", pid=1, flags="d").strip()
n1 = gs.read_command("g.tempfile", pid=1, flags="d").strip()
fd = open(n1, "w")
fd.write("prec_1|1\nprec_2|3\nprec_3|5\nprec_4|7\nprec_5|11\nprec_6|13\n")
fd.close()
name = "relpoint"
grass.run_command(
gs.run_command(
"t.create",
overwrite=True,
type="strds",
Expand All @@ -631,7 +629,7 @@ def createRelativePoint():
descr="A test with input files",
)

grass.run_command("t.register", unit="day", input=name, file=n1, overwrite=True)
gs.run_command("t.register", unit="day", input=name, file=n1, overwrite=True)
return name


Expand Down
4 changes: 2 additions & 2 deletions gui/wxpython/animation/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
hasPIL = False

import grass.temporal as tgis
import grass.script as grass
import grass.script as gs
from grass.script.utils import encode
from gui_core.wrap import EmptyBitmap

Expand Down Expand Up @@ -87,7 +87,7 @@ def validateMapNames(names, etype):
Input is list of map names.
Raises GException if map doesn't exist.
"""
mapDict = grass.list_grouped(etype)
mapDict = gs.list_grouped(etype)

newNames = []
for name in names:
Expand Down
4 changes: 2 additions & 2 deletions gui/wxpython/core/debug.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import os
import sys

import grass.script as grass
import grass.script as gs


class DebugMsg:
Expand All @@ -41,7 +41,7 @@ def __init__(self):
def SetLevel(self):
"""Initialize gui debug level"""
try:
self.debuglevel = int(grass.gisenv().get("WX_DEBUG", 0))
self.debuglevel = int(gs.gisenv().get("WX_DEBUG", 0))
if self.debuglevel < 0 or self.debuglevel > 5:
raise ValueError(_("Wx debug level {0}.").format(self.debuglevel))
except ValueError as e:
Expand Down
12 changes: 6 additions & 6 deletions gui/wxpython/core/gconsole.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
import wx
from wx.lib.newevent import NewEvent

import grass.script as grass
import grass.script as gs
from grass.script import task as gtask

from grass.pydispatch.signal import Signal
Expand Down Expand Up @@ -401,7 +401,7 @@ def __init__(self, guiparent=None, giface=None, ignoredCmdPattern=None):

def Redirect(self):
"""Redirect stdout/stderr"""
if Debug.GetLevel() == 0 and grass.debug_level(force=True) == 0:
if Debug.GetLevel() == 0 and gs.debug_level(force=True) == 0:
# don't redirect when debugging is enabled
sys.stdout = self.cmdStdOut
sys.stderr = self.cmdStdErr
Expand Down Expand Up @@ -825,12 +825,12 @@ def OnCmdDone(self, event):
lnames = [p.get("value")]
for lname in lnames:
if "@" not in lname:
lname += "@" + grass.gisenv()["MAPSET"]
if grass.find_file(lname, element=p.get("element"))["fullname"]:
lname += "@" + gs.gisenv()["MAPSET"]
if gs.find_file(lname, element=p.get("element"))["fullname"]:
self.mapCreated.emit(
name=lname, ltype=prompt, add=event.addLayer
)
gisenv = grass.gisenv()
gisenv = gs.gisenv()
self._giface.grassdbChanged.emit(
grassdb=gisenv["GISDBASE"],
location=gisenv["LOCATION_NAME"],
Expand All @@ -844,7 +844,7 @@ def OnCmdDone(self, event):
for p in task.get_options()["flags"]:
if p.get("name") == "r" and p.get("value"):
action = "delete"
gisenv = grass.gisenv()
gisenv = gs.gisenv()
self._giface.grassdbChanged.emit(
grassdb=gisenv["GISDBASE"],
location=gisenv["LOCATION_NAME"],
Expand Down
Loading

0 comments on commit d880ec0

Please sign in to comment.