Skip to content

Commit

Permalink
refactor: bring modules at high level solving flake8 E402 warning
Browse files Browse the repository at this point in the history
  • Loading branch information
Sharansrj567 committed Jan 12, 2024
1 parent c8ab468 commit 0ea796a
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 71 deletions.
21 changes: 7 additions & 14 deletions gui/wxpython/core/gcmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,20 +44,13 @@

is_mswindows = sys.platform == "win32"


def platform_specific_imports():
if is_mswindows:
global ReadFile, WriteFile, PeekNamedPipe, msvcrt
from win32file import ReadFile, WriteFile
from win32pipe import PeekNamedPipe
import msvcrt
else:
global select, fcntl
import select
import fcntl


platform_specific_imports()
if is_mswindows:
from win32file import ReadFile, WriteFile
from win32pipe import PeekNamedPipe
import msvcrt
else:
import select
import fcntl


def DecodeString(string):
Expand Down
21 changes: 7 additions & 14 deletions gui/wxpython/web_services/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,20 +47,13 @@
TreeCtrl,
)


def import_flatnotebook():
if globalvar.wxPythonPhoenix:
try:
import agw.flatnotebook as FN
except ImportError: # if it's not there locally, try the wxPython lib.
import wx.lib.agw.flatnotebook as FN
else:
import wx.lib.flatnotebook as FN
return FN


FN = import_flatnotebook()

if globalvar.wxPythonPhoenix:
try:
import agw.flatnotebook as FN
except ImportError: # if it's not there locally, try the wxPython lib.
import wx.lib.agw.flatnotebook as FN
else:
import wx.lib.flatnotebook as FN

rinwms_path = os.path.join(os.getenv("GISBASE"), "etc", "r.in.wms")
if rinwms_path not in sys.path:
Expand Down
4 changes: 2 additions & 2 deletions python/grass/docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
if not os.getenv("GISBASE"):
sys.exit("GISBASE not defined")
sys.path.insert(
0, os.path.abspath(os.path.join(os.environ["GISBASE"], "etc", "python", "grass"))
)
Expand Down Expand Up @@ -71,8 +73,6 @@
),
)

if not os.getenv("GISBASE"):
sys.exit("GISBASE not defined")

from grass.script import core

Expand Down
15 changes: 5 additions & 10 deletions python/grass/pygrass/raster/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
#
from grass.script import fatal
from grass.exceptions import OpenError
import grass.lib.gis as libgis
import grass.lib.raster as libraster
import grass.lib.rowio as librowio

libgis.G_gisinit("")

#
# import pygrass modules
Expand All @@ -24,16 +29,6 @@
from grass.pygrass.raster.rowio import RowIO


def import_grass_libs():
import grass.lib.gis as libgis
libgis.G_gisinit("")
import grass.lib.raster as libraster
import grass.lib.rowio as librowio
return libgis, libraster, librowio


libgis, libraster, librowio = import_grass_libs()

WARN_OVERWRITE = "Raster map <{0}> already exists and will be overwritten"

test_raster_name = "Raster_test_map"
Expand Down
21 changes: 9 additions & 12 deletions python/grass/pygrass/tests/benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
"""

import optparse

# import numpy as np
import time
import collections
import copy
Expand All @@ -13,19 +15,14 @@
import os
from jinja2 import Template

sys.path.append(os.getcwd())
sys.path.append("%s/.." % (os.getcwd()))

def import_grass_libs():
sys.path.append(os.getcwd())
sys.path.append("%s/.." % (os.getcwd()))
import grass.lib.gis as libgis
import grass.lib.raster as libraster
import grass.script as core
import grass.pygrass
import ctypes
return libgis, libraster, core, grass.pygrass, ctypes


libgis, libraster, core, pygrass, ctypes = import_grass_libs()
import grass.lib.gis as libgis
import grass.lib.raster as libraster
import grass.script as core
import grass.pygrass
import ctypes


def test__RasterSegment_value_access__if():
Expand Down
16 changes: 6 additions & 10 deletions python/grass/pygrass/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,16 @@
import os
from sqlite3 import OperationalError

import grass.lib.gis as libgis

libgis.G_gisinit("")
import grass.lib.raster as libraster
from grass.lib.ctypes_preamble import String
from grass.script import core as grasscore
from grass.script import utils as grassutils
from grass.pygrass.errors import GrassError


def import_grass_libs():
import grass.lib.gis as libgis
libgis.G_gisinit("")
import grass.lib.raster as libraster
from grass.lib.ctypes_preamble import String
return libgis, libraster, String

from grass.pygrass.errors import GrassError

libgis, libraster, String = import_grass_libs()

test_vector_name = "Utils_test_vector"

Expand Down
13 changes: 4 additions & 9 deletions python/grass/pygrass/vector/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
from os.path import join, exists
import grass.lib.gis as libgis
import grass.lib.vector as libvect
import ctypes

libgis.G_gisinit("")

#
# import pygrass modules
#
Expand All @@ -15,15 +19,6 @@
from grass.pygrass.vector.basic import Bbox, Cats, Ilist


def import_grass_libs():
import grass.lib.gis as libgis
libgis.G_gisinit("")
import grass.lib.vector as libvect
return libgis, libvect


libgis, libvect = import_grass_libs()

_NUMOF = {
"areas": libvect.Vect_get_num_areas,
"dblinks": libvect.Vect_get_num_dblinks,
Expand Down

0 comments on commit 0ea796a

Please sign in to comment.