Skip to content

Commit

Permalink
Fix tab, indentation and membership Flake8 warnings in grass package (#…
Browse files Browse the repository at this point in the history
…540)

* Tabs in indentation or in code (Flake8 E101, W191, E242)
* Indentation is not a multiple of four (Flake8 E111)
* Wrong indentation of comments (Flake8 E114, E116)
* Multiple statements on one line (Flake8 E701, E702)
* Statement ends with a semicolon (Flake8 E703)
* Test for membership should be 'not in' (Flake8 E713)
* Reorder errors to move whitespace errors down the list.
* Completely remove commented-out traceback prints for debug messages in temporal code.
  • Loading branch information
wenzeslaus committed Apr 22, 2020
1 parent 3de1a5c commit e4fc0a9
Show file tree
Hide file tree
Showing 16 changed files with 53 additions and 55 deletions.
14 changes: 2 additions & 12 deletions lib/python/.flake8
@@ -1,24 +1,12 @@
[flake8]
ignore =
E101, # indentation contains mixed spaces and tabs
W191, # indentation contains tabs
E111, # indentation is not a multiple of four
E114, # indentation is not a multiple of four (comment)
E116, # unexpected indentation (comment)
E242, # tab after ','
E251, # unexpected spaces around keyword / parameter equals
E262, # inline comment should start with '# '
E265, # block comment should start with '# '
E266, # too many leading '#' for block comment
E402, # module level import not at top of file
E501, # line too long (183 > 150 characters)
E502, # the backslash is redundant between brackets
E701, # multiple statements on one line (colon)
E702, # multiple statements on one line (semicolon)
E703, # statement ends with a semicolon
E711, # comparison to None should be 'if cond is None:'
E712, # comparison to True should be 'if cond is True:' or 'if cond:'
E713, # test for membership should be 'not in'
E721, # do not compare types, use 'isinstance()'
E722, # do not use bare 'except'
E731, # do not assign a lambda expression, use a def
Expand Down Expand Up @@ -58,9 +46,11 @@ ignore =
E228, # missing whitespace around modulo operator
E231, # missing whitespace after ':'
E241, # multiple spaces after ','
E251, # unexpected spaces around keyword / parameter equals
E261, # at least two spaces before inline comment
E271, # multiple spaces after keyword
E272, # multiple spaces before keyword
E501, # line too long (183 > 150 characters)
E301, # expected 1 blank line, found 0
E302, # expected 2 blank lines, found 1
E303, # too many blank lines (3)
Expand Down
2 changes: 1 addition & 1 deletion lib/python/gunittest/main.py
Expand Up @@ -86,7 +86,7 @@ def test():
# cov.start()
#except ImportError:
# pass
# TODO: add some message somewhere
# TODO: add some message somewhere

# TODO: enable passing omit to exclude also gunittest or nothing
program = GrassTestProgram(module='__main__', exit_at_end=False, grass_location='all')
Expand Down
9 changes: 5 additions & 4 deletions lib/python/imaging/images2gif.py
Expand Up @@ -209,10 +209,11 @@ def getAppExt(self, loops=float('inf')):

if loops == 0 or loops == float('inf'):
loops = 2 ** 16 - 1
#bb = "" # application extension should not be used
# (the extension interprets zero loops
# to mean an infinite number of loops)
# Mmm, does not seem to work
# bb = ""
# application extension should not be used
# (the extension interprets zero loops
# to mean an infinite number of loops)
# Mmm, does not seem to work
if True:
bb = "\x21\xFF\x0B" # application extension
bb += "NETSCAPE2.0"
Expand Down
12 changes: 8 additions & 4 deletions lib/python/imaging/images2swf.py
Expand Up @@ -876,10 +876,14 @@ def _readPixels(bb, i, tagType, L1):
raise RuntimeError("Need Numpy to read an SWF file.")

# Get info
charId = bb[i:i + 2]; i += 2
format = ord(bb[i:i + 1]); i += 1
width = bitsToInt(bb[i:i + 2], 16); i += 2
height = bitsToInt(bb[i:i + 2], 16); i += 2
charId = bb[i:i + 2]
i += 2
format = ord(bb[i:i + 1])
i += 1
width = bitsToInt(bb[i:i + 2], 16)
i += 2
height = bitsToInt(bb[i:i + 2], 16)
i += 2

# If we can, get pixeldata and make nunmpy array
if format != 5:
Expand Down
2 changes: 1 addition & 1 deletion lib/python/pygrass/rpc/base.py
Expand Up @@ -168,7 +168,7 @@ def safe_receive(self, message):
try:
ret = self.client_conn.recv()
if isinstance(ret, FatalError):
raise ret
raise ret
return ret
except (EOFError, IOError, FatalError) as e:
# The pipe was closed by the checker thread because
Expand Down
4 changes: 2 additions & 2 deletions lib/python/script/core.py
Expand Up @@ -191,7 +191,7 @@ def _access_check(fn, mode):

if sys.platform == "win32":
# The current directory takes precedence on Windows.
if not os.curdir in path:
if os.curdir not in path:
path.insert(0, os.curdir)

# PATHEXT is necessary to check on Windows (force lowercase)
Expand All @@ -216,7 +216,7 @@ def _access_check(fn, mode):
seen = set()
for dir in path:
normdir = os.path.normcase(dir)
if not normdir in seen:
if normdir not in seen:
seen.add(normdir)
for thefile in files:
name = os.path.join(dir, thefile)
Expand Down
2 changes: 1 addition & 1 deletion lib/python/script/setup.py
Expand Up @@ -228,7 +228,7 @@ def clean_default_db():
if os.path.exists(database):
gcore.message(_("Cleaning up default sqlite database ..."))
gcore.start_command('db.execute', sql = 'VACUUM')
# give it some time to start
# give it some time to start
import time
time.sleep(0.1)

Expand Down
17 changes: 7 additions & 10 deletions lib/python/temporal/core.py
Expand Up @@ -563,7 +563,6 @@ def init(raise_fatal_error=False, skip_db_version_check=False):
_init_tgis_c_library_interface()
msgr = get_tgis_message_interface()
msgr.debug(1, "Initiate the temporal database")
#"\n traceback:%s"%(str(" \n".join(traceback.format_stack()))))

msgr.debug(1, ("Raise on error id: %s"%str(raise_on_error)))

Expand Down Expand Up @@ -928,7 +927,7 @@ def _create_tgis_metadata_table(content, dbif=None):
:param dbif: The database interface to be used
"""
dbif, connected = init_dbif(dbif)
statement = "CREATE TABLE tgis_metadata (key VARCHAR NOT NULL, value VARCHAR);\n";
statement = "CREATE TABLE tgis_metadata (key VARCHAR NOT NULL, value VARCHAR);\n"
dbif.execute_transaction(statement)

for key in content.keys():
Expand Down Expand Up @@ -1109,12 +1108,12 @@ def execute_transaction(self, statement, mapset=None):

def _create_mapset_error_message(self, mapset):

return("You have no permission to "
"access mapset <%(mapset)s>, or "
"mapset <%(mapset)s> has no temporal database. "
"Accessible mapsets are: <%(mapsets)s>" % \
{"mapset": decode(mapset),
"mapsets":','.join(self.tgis_mapsets.keys())})
return("You have no permission to "
"access mapset <%(mapset)s>, or "
"mapset <%(mapset)s> has no temporal database. "
"Accessible mapsets are: <%(mapsets)s>" % \
{"mapset": decode(mapset),
"mapsets":','.join(self.tgis_mapsets.keys())})

###############################################################################

Expand Down Expand Up @@ -1158,8 +1157,6 @@ def __init__(self, backend=None, dbstring=None):
self.msgr.debug(1, "DBConnection constructor:"\
"\n backend: %s"\
"\n dbstring: %s"%(backend, self.dbstring))
#"\n traceback:%s"%(backend, self.dbstring,
#str(" \n".join(traceback.format_stack()))))

def __del__(self):
if self.connected is True:
Expand Down
2 changes: 1 addition & 1 deletion lib/python/temporal/metadata.py
Expand Up @@ -429,7 +429,7 @@ def __init__(self, ident=None, datatype=None,

RasterMetadataBase.__init__(self, "raster3d_metadata", ident,
datatype, cols, rows, number_of_cells,
nsres, ewres, min, max)
nsres, ewres, min, max)

self.set_tbres(tbres)
self.set_depths(depths)
Expand Down
18 changes: 10 additions & 8 deletions lib/python/temporal/temporal_algebra.py
Expand Up @@ -683,9 +683,10 @@ def test(self,data):
print(data)
self.lexer.input(data)
while True:
tok = self.lexer.token()
if not tok: break
print(tok)
tok = self.lexer.token()
if not tok:
break
print(tok)

###############################################################################

Expand Down Expand Up @@ -836,7 +837,8 @@ def setup_common_granularity(self, expression, stdstype = 'strds', lexer = No
count = 0
while True:
tok = l.lexer.token()
if not tok: break
if not tok:
break

# Ignore map layer
tokens.append(tok.type)
Expand Down Expand Up @@ -1776,8 +1778,8 @@ def set_granularity(self,
"FINISHED"]

for topo in topolist:
if topo.upper() not in topologylist:
raise SyntaxError("Unpermitted temporal relation name '" + topo + "'")
if topo.upper() not in topologylist:
raise SyntaxError("Unpermitted temporal relation name '" + topo + "'")

# Create temporal topology for maplistA to maplistB.
tb = SpatioTemporalTopologyBuilder()
Expand Down Expand Up @@ -1929,8 +1931,8 @@ def get_temporal_func_dict(self, map):
tvardict["END_DATE"] = end.date()
tvardict["END_DATETIME"] = end
tvardict["END_TIME"] = end.time()
#core.fatal(_("The temporal functions for map <%s> only supported for absolute"\
# "time." % (str(map.get_id()))))
# core.fatal(_("The temporal functions for map <%s> only "
# "supported for absolute time." % (str(map.get_id()))))
return(tvardict)

def eval_datetime_str(self, tfuncval, comp, value):
Expand Down
4 changes: 2 additions & 2 deletions lib/python/temporal/temporal_granularity.py
Expand Up @@ -508,7 +508,7 @@ def compute_absolute_time_granularity(maps):
###############################################################################

def compute_common_relative_time_granularity(gran_list):
"""Compute the greatest common granule from a list of relative time granules
"""Compute the greatest common granule from a list of relative time granules
.. code-block:: python
Expand All @@ -524,7 +524,7 @@ def compute_common_relative_time_granularity(gran_list):
>>> tgis.compute_common_relative_time_granularity(grans)
10
"""
return gcd_list(gran_list)
return gcd_list(gran_list)

###############################################################################

Expand Down
7 changes: 4 additions & 3 deletions lib/python/temporal/temporal_operator.py
Expand Up @@ -277,9 +277,10 @@ def test(self,data):
print(data)
self.lexer.input(data)
while True:
tok = self.lexer.token()
if not tok: break
print(tok)
tok = self.lexer.token()
if not tok:
break
print(tok)

###############################################################################

Expand Down
3 changes: 2 additions & 1 deletion lib/python/temporal/temporal_raster3d_algebra.py
Expand Up @@ -47,7 +47,8 @@ def parse(self, expression, basename = None, overwrite=False):

while True:
tok = l.lexer.token()
if not tok: break
if not tok:
break

if tok.type == "STVDS" or tok.type == "STRDS" or tok.type == "STR3DS":
raise SyntaxError("Syntax error near '%s'" %(tok.type))
Expand Down
3 changes: 2 additions & 1 deletion lib/python/temporal/temporal_raster_algebra.py
Expand Up @@ -91,7 +91,8 @@ def parse(self, expression, basename = None, overwrite=False):

while True:
tok = l.lexer.token()
if not tok: break
if not tok:
break

if tok.type == "STVDS" or tok.type == "STRDS" or tok.type == "STR3DS":
raise SyntaxError("Syntax error near '%s'" %(tok.type))
Expand Down
2 changes: 1 addition & 1 deletion lib/python/temporal/temporal_raster_base_algebra.py
Expand Up @@ -1865,7 +1865,7 @@ def p_hash_operation(self, t):
mapinput = map_i.get_id()
# Create r.mapcalc expression string for the operation.
cmdstring = "(%s)" %(n_maps)
# Append module command.
# Append module command.
map_i.cmd_list = cmdstring
# Append map to result map list.
resultlist.append(map_i)
Expand Down
7 changes: 4 additions & 3 deletions lib/python/temporal/temporal_vector_algebra.py
Expand Up @@ -142,7 +142,8 @@ def parse(self, expression, basename = None, overwrite = False):

while True:
tok = l.lexer.token()
if not tok: break
if not tok:
break

if tok.type == "STVDS" or tok.type == "STRDS" or tok.type == "STR3DS":
raise SyntaxError("Syntax error near '%s'" %(tok.type))
Expand Down Expand Up @@ -204,8 +205,8 @@ def build_spatio_temporal_topology_list(self, maplistA, maplistB = None, topolis
resultdict = {}
# Check if given temporal relation are valid.
for topo in topolist:
if topo.upper() not in topologylist:
raise SyntaxError("Unpermitted temporal relation name '" + topo + "'")
if topo.upper() not in topologylist:
raise SyntaxError("Unpermitted temporal relation name '" + topo + "'")

# Create temporal topology for maplistA to maplistB.
tb = SpatioTemporalTopologyBuilder()
Expand Down

0 comments on commit e4fc0a9

Please sign in to comment.