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: address flake8 e402 warning in the codebase #3354

Closed
wants to merge 6 commits into from
Closed
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
16 changes: 9 additions & 7 deletions gui/wxpython/core/gcmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,31 +25,33 @@
@author Martin Landa <landa.martin gmail.com>
"""

import errno
import locale
import os
import signal
import subprocess
import sys
import time
import errno
import signal
import traceback
import locale
import subprocess
from threading import Thread
import wx

import wx
from core.debug import Debug
from core.globalvar import SCT_EXT

from grass.script import core as grass
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even if that's not from this PR, this doesn't sound right, and quite ambiguous (the alias's name)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've noticed that across our codebase, there is a consistent use of the alias grass for the core module. Given that this pattern is present in around 51 files, it might be worth discussing whether we want to maintain this convention or consider a more descriptive alias.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm pretty sure this was introduced when transitioning form a single-file package called grass(.script?) to multiple files (modules). Functions in original grass or something like that were moved core and grass or grass.script got new functions. grass.script.core then became what grass once was. These imports were the least intrusive change, so it was implemented that way. This was in the pre-v7-times on Subversion trunk, but it was propagated sufficiently through the code base at the time of v7 release that it became a standard for v7. We came up with grass.script as gs as a better practice, but didn't go back (yet) to replace all occurrences of core as grass.

from grass.script.utils import decode, encode

is_mswindows = sys.platform == "win32"

if is_mswindows:
import msvcrt

from win32file import ReadFile, WriteFile
from win32pipe import PeekNamedPipe
import msvcrt
else:
import select
import fcntl
import select


def DecodeString(string):
Expand Down
6 changes: 1 addition & 5 deletions gui/wxpython/core/watchdog.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

import os
import time

from pathlib import Path

import wx
Expand All @@ -29,11 +28,8 @@

watchdog_used = True
try:
from watchdog.events import FileSystemEventHandler, PatternMatchingEventHandler
from watchdog.observers import Observer
from watchdog.events import (
PatternMatchingEventHandler,
FileSystemEventHandler,
)
except ImportError:
watchdog_used = False
PatternMatchingEventHandler = object
Expand Down
4 changes: 1 addition & 3 deletions gui/wxpython/gmodeler/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,10 @@
import os

import wx

from core import globalvar
from gui_core.menu import Menu as Menubar

from gmodeler.menudata import ModelerMenuData
from gmodeler.panels import ModelerPanel
from gui_core.menu import Menu as Menubar


class ModelerFrame(wx.Frame):
Expand Down
17 changes: 8 additions & 9 deletions gui/wxpython/startup/locdownload.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,27 @@
"""

import os
import sys
import shutil
import sys
import textwrap
import time

import wx
from wx.lib.newevent import NewEvent

from grass.script.utils import try_rmdir, legalize_vector_name
from grass.utils.download import download_and_extract, name_from_url, DownloadError
from grass.grassdb.checks import is_location_valid
from grass.script.setup import set_gui_path

set_gui_path()

# flake8: noqa: E402
from core.debug import Debug
from core.gthread import gThread
from gui_core.wrap import Button, StaticText

# flakes8: qa
from wx.lib.newevent import NewEvent

from grass.grassdb.checks import is_location_valid
from grass.script.setup import set_gui_path
from grass.script.utils import legalize_vector_name, try_rmdir
from grass.utils.download import DownloadError, download_and_extract, name_from_url

set_gui_path()

# TODO: labels (and descriptions) translatable?
LOCATIONS = [
Expand Down
36 changes: 11 additions & 25 deletions gui/wxpython/web_services/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,39 +16,20 @@
@author Stepan Turek <stepan.turek seznam.cz>
"""

import re
import os
import sys
import re
import shutil

import sys
from copy import deepcopy
from core import globalvar

from xml.etree.ElementTree import ParseError

import wx

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
import wx.lib.colourselect as csel

from core import globalvar
from core.debug import Debug
from core.gcmd import GMessage
from core.gconsole import CmdThread, GStderr, EVT_CMD_DONE, EVT_CMD_OUTPUT

from web_services.cap_interface import (
WMSCapabilities,
WMTSCapabilities,
OnEarthCapabilities,
)

from gui_core.widgets import GNotebook
from gui_core.widgets import ManageSettingsWidget
from core.gconsole import EVT_CMD_DONE, EVT_CMD_OUTPUT, CmdThread, GStderr
from gui_core.widgets import GNotebook, ManageSettingsWidget
from gui_core.wrap import (
Button,
ScrolledPanel,
Expand All @@ -58,6 +39,11 @@
TextCtrl,
TreeCtrl,
)
from web_services.cap_interface import (
OnEarthCapabilities,
WMSCapabilities,
WMTSCapabilities,
)

import grass.script as gs
from grass.pydispatch.signal import Signal
Expand All @@ -66,8 +52,8 @@
if rinwms_path not in sys.path:
sys.path.append(rinwms_path)

from wms_base import WMSDriversInfo # noqa:E402
from srs import Srs # noqa:E402
from wms_base import WMSDriversInfo # noqa:E402


class WSPanel(wx.Panel):
Expand Down
4 changes: 2 additions & 2 deletions python/grass/docs/conf.py
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file I'm ok with.

Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
# All configuration values have a default; values that are commented out
# serve to show the default.

import sys
import os
from datetime import date
import string
import sys
from datetime import date
from shutil import copy

# If extensions (or modules to document with autodoc) are in another directory,
Expand Down
1 change: 0 additions & 1 deletion python/grass/pygrass/raster/__init__.py
echoix marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#
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
Expand Down
16 changes: 7 additions & 9 deletions python/grass/pygrass/vector/__init__.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,20 @@
from os.path import join, exists
import grass.lib.gis as libgis
import ctypes
from os.path import exists, join

import grass.lib.gis as libgis

# flake8: noqa: E402
libgis.G_gisinit("")

import grass.lib.vector as libvect
from grass.pygrass.vector.vector_type import VTYPE
from grass.pygrass.errors import GrassError, must_be_open
from grass.pygrass.gis import Location
from grass.pygrass.vector.geometry import (
GEOOBJ as _GEOOBJ,
read_line,
read_next_line,
Area as _Area,
)
from grass.pygrass.vector.abstract import Info
from grass.pygrass.vector.basic import Bbox, Cats, Ilist
from grass.pygrass.vector.geometry import GEOOBJ as _GEOOBJ
from grass.pygrass.vector.geometry import Area as _Area
from grass.pygrass.vector.geometry import read_line, read_next_line
from grass.pygrass.vector.vector_type import VTYPE

# flake8: qa

Expand Down Expand Up @@ -972,6 +969,7 @@ def areas_to_wkb_list(self, bbox=None, field=1):

if __name__ == "__main__":
import doctest

from grass.pygrass import utils

utils.create_test_vector_map(test_vector_name)
Expand Down
20 changes: 9 additions & 11 deletions scripts/r.in.wms/wms_drv.py
echoix marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,16 @@
"""

import socket
from http.client import HTTPException
from math import floor, pi
from time import sleep
from urllib.error import HTTPError
from xml.etree.ElementTree import ParseError

import numpy as np
from srs import Srs
from wms_base import GetEpsg, GetSRSParamVal, WMSBase
from wms_cap_parsers import OnEarthCapabilitiesTree, WMTSCapabilitiesTree

import grass.script as gs

Expand All @@ -32,17 +41,6 @@
)
)

from http.client import HTTPException
from math import floor, pi
from urllib.error import HTTPError
from xml.etree.ElementTree import ParseError

import numpy as np

from srs import Srs
from wms_base import GetEpsg, GetSRSParamVal, WMSBase
from wms_cap_parsers import OnEarthCapabilitiesTree, WMTSCapabilitiesTree


class WMSDrv(WMSBase):
def _download(self):
Expand Down
Loading