Skip to content

Commit

Permalink
pythonlib: Remove star imports (OSGeo#1546)
Browse files Browse the repository at this point in the history
Replaces star import (from x import *) by regular imports (from x import y).

Enables the relevant Flake8 warnings.

Adds the warning to per-file ignores for init files where we expect and allow
using star imports (unfortunately some init files contain actual code suffers
from these warning being disabled, but that's a different issue).
  • Loading branch information
a0x8o committed Sep 5, 2024
1 parent 975e253 commit f32db83
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 0 deletions.
6 changes: 6 additions & 0 deletions python/grass/.flake8
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ ignore =
<<<<<<< HEAD
<<<<<<< HEAD
<<<<<<< HEAD
<<<<<<< HEAD
=======
>>>>>>> main
=======
Expand Down Expand Up @@ -327,6 +328,11 @@ ignore =
>>>>>>> f4b9197871 (pythonlib: Remove star imports (#1546))
=======
>>>>>>> 460748a7fb (g.proj: fix reading input WKT (#1582))
=======
=======
E722, # do not use bare 'except'
>>>>>>> 7e8f036e2d (pythonlib: Remove star imports (#1546))
>>>>>>> 3ced907ea6 (pythonlib: Remove star imports (#1546))

per-file-ignores =
# C wrappers call libgis.G_gisinit before importing other modules.
Expand Down
6 changes: 6 additions & 0 deletions python/grass/exceptions/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ def __init__(self, module, code, returncode, errors=None):
<<<<<<< HEAD
<<<<<<< HEAD
<<<<<<< HEAD
<<<<<<< HEAD
=======
<<<<<<< HEAD
>>>>>>> 3fce2ed438 (pythonlib: Remove star imports (#1546))
Expand Down Expand Up @@ -178,6 +179,11 @@ def __init__(self, module, code, returncode, errors=None):
=======
>>>>>>> 3fce2ed438 (pythonlib: Remove star imports (#1546))
>>>>>>> f4b9197871 (pythonlib: Remove star imports (#1546))
=======
>>>>>>> 3fce2ed438 (pythonlib: Remove star imports (#1546))
=======
>>>>>>> 7e8f036e2d (pythonlib: Remove star imports (#1546))
>>>>>>> 3ced907ea6 (pythonlib: Remove star imports (#1546))
if not module or module in code:
# No need to include module name if it is directly in code
# of if it is not set.
Expand Down
15 changes: 15 additions & 0 deletions python/grass/gunittest/invoker.py
Original file line number Diff line number Diff line change
Expand Up @@ -899,8 +899,14 @@ def _run_test_module(self, module, results_dir, gisdbase, location, timeout):
returncode = p.returncode
encodings = [_get_encoding(), "utf8", "latin-1", "ascii"]
<<<<<<< HEAD
>>>>>>> 3fce2ed438 (pythonlib: Remove star imports (#1546))
<<<<<<< HEAD
>>>>>>> f4b9197871 (pythonlib: Remove star imports (#1546))
=======
=======
>>>>>>> 7e8f036e2d (pythonlib: Remove star imports (#1546))
>>>>>>> 3ced907ea6 (pythonlib: Remove star imports (#1546))
def try_decode(data, encodings):
"""Try to decode data (bytes) using one of encodings

Expand Down Expand Up @@ -939,6 +945,7 @@ def try_decode(data, encodings):
<<<<<<< HEAD
<<<<<<< HEAD
<<<<<<< HEAD
<<<<<<< HEAD
=======
>>>>>>> main
=======
Expand Down Expand Up @@ -1092,6 +1099,8 @@ def try_decode(data, encodings):
=======
>>>>>>> 4fa4b4b8fe (pythonlib: Remove star imports (#1546))
=======
>>>>>>> 3ced907ea6 (pythonlib: Remove star imports (#1546))
=======
>>>>>>> 3ced907ea6 (pythonlib: Remove star imports (#1546))
return decode(data, encoding=encoding)
=======
Expand All @@ -1101,6 +1110,7 @@ def try_decode(data, encodings):
<<<<<<< HEAD
<<<<<<< HEAD
<<<<<<< HEAD
<<<<<<< HEAD
>>>>>>> 0bd7d818a8 (pythonlib: Remove star imports (#1546))
=======
=======
Expand Down Expand Up @@ -1198,6 +1208,11 @@ def try_decode(data, encodings):
return decode(stdout, encoding=encoding)
>>>>>>> 3fce2ed438 (pythonlib: Remove star imports (#1546))
>>>>>>> f4b9197871 (pythonlib: Remove star imports (#1546))
=======
=======
return decode(stdout, encoding=encoding)
>>>>>>> 7e8f036e2d (pythonlib: Remove star imports (#1546))
>>>>>>> 3ced907ea6 (pythonlib: Remove star imports (#1546))
except UnicodeError:
pass
if isinstance(data, bytes):
Expand Down
6 changes: 6 additions & 0 deletions python/grass/script/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
<<<<<<< HEAD
<<<<<<< HEAD
<<<<<<< HEAD
<<<<<<< HEAD
=======
<<<<<<< HEAD
>>>>>>> 3fce2ed438 (pythonlib: Remove star imports (#1546))
Expand Down Expand Up @@ -125,6 +126,11 @@
=======
>>>>>>> 3fce2ed438 (pythonlib: Remove star imports (#1546))
>>>>>>> f4b9197871 (pythonlib: Remove star imports (#1546))
=======
>>>>>>> 3fce2ed438 (pythonlib: Remove star imports (#1546))
=======
>>>>>>> 7e8f036e2d (pythonlib: Remove star imports (#1546))
>>>>>>> 3ced907ea6 (pythonlib: Remove star imports (#1546))

import os
from .core import (
Expand Down
6 changes: 6 additions & 0 deletions python/grass/script/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
<<<<<<< HEAD
<<<<<<< HEAD
<<<<<<< HEAD
<<<<<<< HEAD
=======
<<<<<<< HEAD
=======
Expand Down Expand Up @@ -65,6 +66,8 @@
>>>>>>> osgeo-main
=======
>>>>>>> 3ced907ea6 (pythonlib: Remove star imports (#1546))
=======
>>>>>>> 3ced907ea6 (pythonlib: Remove star imports (#1546))

=======
>>>>>>> 3fce2ed438 (pythonlib: Remove star imports (#1546))
Expand All @@ -82,6 +85,7 @@
<<<<<<< HEAD
<<<<<<< HEAD
<<<<<<< HEAD
<<<<<<< HEAD
=======
<<<<<<< HEAD
>>>>>>> main
Expand Down Expand Up @@ -139,6 +143,8 @@
=======
>>>>>>> 3fce2ed438 (pythonlib: Remove star imports (#1546))
>>>>>>> f4b9197871 (pythonlib: Remove star imports (#1546))
=======
>>>>>>> 3ced907ea6 (pythonlib: Remove star imports (#1546))
import os
import re
import sys
Expand Down
7 changes: 7 additions & 0 deletions python/grass/script/vector.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
<<<<<<< HEAD
<<<<<<< HEAD
<<<<<<< HEAD
<<<<<<< HEAD

from grass.exceptions import CalledModuleError, ScriptError
=======
Expand Down Expand Up @@ -84,6 +85,9 @@
=======
>>>>>>> 3ced907ea6 (pythonlib: Remove star imports (#1546))
=======
=======
>>>>>>> 3ced907ea6 (pythonlib: Remove star imports (#1546))
=======

from grass.exceptions import CalledModuleError, ScriptError
>>>>>>> 7e8f036e2d (pythonlib: Remove star imports (#1546))
Expand All @@ -92,6 +96,7 @@
<<<<<<< HEAD
<<<<<<< HEAD
<<<<<<< HEAD
<<<<<<< HEAD
>>>>>>> 5fb05831cc (pythonlib: Remove star imports (#1546))
=======
>>>>>>> osgeo-main
Expand Down Expand Up @@ -143,6 +148,8 @@
=======
=======
>>>>>>> f4b9197871 (pythonlib: Remove star imports (#1546))
=======
>>>>>>> 3ced907ea6 (pythonlib: Remove star imports (#1546))

from grass.exceptions import CalledModuleError, ScriptError
>>>>>>> 3fce2ed438 (pythonlib: Remove star imports (#1546))
Expand Down
16 changes: 16 additions & 0 deletions python/grass/temporal/c_libraries_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
<<<<<<< HEAD
<<<<<<< HEAD
<<<<<<< HEAD
<<<<<<< HEAD
=======
>>>>>>> main
=======
Expand Down Expand Up @@ -441,22 +442,34 @@
from ctypes import CFUNCTYPE, POINTER, byref, c_int, c_void_p, cast
=======
>>>>>>> f4b9197871 (pythonlib: Remove star imports (#1546))
=======
import sys
from ctypes import CFUNCTYPE, POINTER, byref, c_int, c_void_p, cast
=======
=======
>>>>>>> 56010eb999 (pythonlib: Remove star imports (#1546))
>>>>>>> 3ced907ea6 (pythonlib: Remove star imports (#1546))
<<<<<<< HEAD
from ctypes import byref, cast, c_int, c_void_p, CFUNCTYPE, POINTER
=======
from ctypes import byref, cast, c_char_p, c_int, c_void_p, CFUNCTYPE, POINTER
>>>>>>> 3fce2ed438 (pythonlib: Remove star imports (#1546))
<<<<<<< HEAD
<<<<<<< HEAD
<<<<<<< HEAD
>>>>>>> bdc1a9eff8 (pythonlib: Remove star imports (#1546))
<<<<<<< HEAD
>>>>>>> f4b9197871 (pythonlib: Remove star imports (#1546))
=======
=======
>>>>>>> bdc1a9eff8 (pythonlib: Remove star imports (#1546))
>>>>>>> 3ced907ea6 (pythonlib: Remove star imports (#1546))
=======
=======
from ctypes import byref, cast, c_char_p, c_int, c_void_p, CFUNCTYPE, POINTER
>>>>>>> 7e8f036e2d (pythonlib: Remove star imports (#1546))
<<<<<<< HEAD
<<<<<<< HEAD
>>>>>>> 56010eb999 (pythonlib: Remove star imports (#1546))
<<<<<<< HEAD
>>>>>>> 3ced907ea6 (pythonlib: Remove star imports (#1546))
Expand Down Expand Up @@ -491,6 +504,9 @@
=======
>>>>>>> bdc1a9eff8 (pythonlib: Remove star imports (#1546))
>>>>>>> f4b9197871 (pythonlib: Remove star imports (#1546))
=======
>>>>>>> 56010eb999 (pythonlib: Remove star imports (#1546))
>>>>>>> 3ced907ea6 (pythonlib: Remove star imports (#1546))
from datetime import datetime
from multiprocessing import Lock, Pipe, Process

Expand Down
5 changes: 5 additions & 0 deletions python/grass/temporal/temporal_granularity.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
<<<<<<< HEAD
<<<<<<< HEAD
<<<<<<< HEAD
<<<<<<< HEAD
=======
<<<<<<< HEAD
>>>>>>> 3fce2ed438 (pythonlib: Remove star imports (#1546))
Expand Down Expand Up @@ -176,7 +177,11 @@
>>>>>>> bdc1a9eff8 (pythonlib: Remove star imports (#1546))
>>>>>>> f4b9197871 (pythonlib: Remove star imports (#1546))
=======
=======
>>>>>>> 3ced907ea6 (pythonlib: Remove star imports (#1546))
>>>>>>> 3fce2ed438 (pythonlib: Remove star imports (#1546))
=======
>>>>>>> 7e8f036e2d (pythonlib: Remove star imports (#1546))
from functools import reduce
from collections import OrderedDict
>>>>>>> bdc1a9eff8 (pythonlib: Remove star imports (#1546))
Expand Down

0 comments on commit f32db83

Please sign in to comment.