Skip to content
Permalink
Browse files

Merge pull request #36215 from m-kuhn/pyflakes

flake8
  • Loading branch information
m-kuhn committed May 6, 2020
2 parents ad25c24 + dd0d71a commit b1873a4e6e5cf217a18e254af8036ac49c02b523
Showing with 188 additions and 112 deletions.
  1. +3 −3 .ci/travis/scripts/ctest2travis.py
  2. +17 −0 .flake8
  3. +23 −0 .github/workflows/pyflakes.yml
  4. +2 −2 ms-windows/mxe/deploy.py
  5. +1 −1 python/core/additions/qgsfunction.py
  6. +1 −1 python/custom_widgets/qgis_customwidgets.py
  7. +7 −6 python/plugins/db_manager/db_plugins/postgis/connector.py
  8. +1 −1 python/plugins/db_manager/db_plugins/postgis/plugin_test.py
  9. +8 −0 python/plugins/processing/__init__.py
  10. +1 −1 python/plugins/processing/algs/grass7/Grass7Utils.py
  11. +1 −1 python/plugins/processing/algs/otb/OtbAlgorithm.py
  12. +4 −4 python/plugins/processing/algs/otb/OtbChoiceWidget.py
  13. +1 −1 python/plugins/processing/algs/qgis/ImportIntoSpatialite.py
  14. +0 −21 python/plugins/processing/algs/qgis/RasterCalculator.py
  15. +1 −0 python/plugins/processing/algs/qgis/RasterSampling.py
  16. +1 −1 python/plugins/processing/algs/qgis/SpatialiteExecuteSQL.py
  17. +5 −5 python/plugins/processing/algs/qgis/TilesXYZ.py
  18. +1 −1 python/plugins/processing/algs/qgis/VectorSplit.py
  19. +1 −1 python/plugins/processing/core/parameters.py
  20. +1 −1 python/plugins/processing/gui/AlgorithmExecutor.py
  21. +1 −1 python/plugins/processing/gui/ConfigDialog.py
  22. +2 −2 python/plugins/processing/preconfigured/PreconfiguredAlgorithmDialog.py
  23. +1 −1 python/plugins/processing/tests/AlgorithmsTestBase.py
  24. +45 −1 python/plugins/processing/tests/GuiTest.py
  25. +3 −2 python/plugins/processing/tests/OtbAlgorithmsTest.py
  26. +2 −2 python/qsci_apis/generate_console_pap.py
  27. +1 −1 python/utils.py
  28. +2 −2 scripts/context_help_id.py
  29. +4 −3 scripts/parse_dash_results.py
  30. +1 −1 scripts/qgis_fixes/fix_signals.py
  31. +2 −2 scripts/symbol_xml2db.py
  32. +1 −2 scripts/widgets_tree.py
  33. +1 −1 tests/code_layout/doxygen_parser.py
  34. +2 −2 tests/code_layout/test_qgsdoccoverage.py
  35. +1 −1 tests/src/python/test_authmanager_oauth2_ows.py
  36. +1 −1 tests/src/python/test_authmanager_ogr.py
  37. +1 −1 tests/src/python/test_authmanager_password_ows.py
  38. +1 −1 tests/src/python/test_authmanager_pki_ows.py
  39. +1 −1 tests/src/python/test_offline_editing_wfs.py
  40. +1 −1 tests/src/python/test_qgsappstartup.py
  41. +1 −1 tests/src/python/test_qgsprocessexecutable.py
  42. +1 −1 tests/src/python/test_qgsprocessingalgrunner.py
  43. +2 −1 tests/src/python/test_qgsrenderer.py
  44. +6 −6 tests/src/python/test_qgsserver.py
  45. +1 −1 tests/src/python/test_qgsserver_cachemanager.py
  46. +2 −2 tests/src/python/test_qgsserver_plugins.py
  47. +3 −3 tests/src/python/test_qgsserver_wfs.py
  48. +1 −1 tests/src/python/test_qgsserver_wfst.py
  49. +2 −2 tests/src/python/test_qgsserver_wms_getlegendgraphic.py
  50. +2 −2 tests/src/python/test_qgsserver_wms_getmap.py
  51. +2 −2 tests/src/python/test_qgsserver_wms_getmap_ignore_bad_layers.py
  52. +7 −7 tests/src/python/test_qgsserver_wms_getprint.py
  53. +2 −2 tests/src/python/test_qgsserver_wmts.py
  54. +1 −1 tests/src/python/utilities.py
  55. +1 −0 tests/testdata/test_plugin_path/ProcessingPluginTest/__init__.py
@@ -83,7 +83,7 @@ def start_test_fold():
end_fold() # tag=build
start_test_fold()

if re.search('\*\*\*Failed', updated_line) or re.search('\*\*\*Timeout', updated_line):
if re.search(r'\*\*\*Failed', updated_line) or re.search(r'\*\*\*Timeout', updated_line):
end_fold()
updated_line = colored(updated_line, 'red')
in_failing_test = True
@@ -97,14 +97,14 @@ def start_test_fold():
in_failure = False
else:
updated_line = colored(updated_line, 'yellow')
elif re.search('\*\*\* Segmentation fault', updated_line):
elif re.search(r'\*\*\* Segmentation fault', updated_line):
start_fold('segfault')
updated_line = colored(updated_line, 'magenta')
elif re.match(' Test failed: Segmentation fault', updated_line):
end_fold()

else:
if re.match('(FAIL|ERROR)[:\!].*', updated_line):
if re.match(r'(FAIL|ERROR)[:\!].*', updated_line):
updated_line = colored(updated_line, 'yellow')
in_failure = True

17 .flake8
@@ -0,0 +1,17 @@
[flake8]
ignore =
E501, E402, N802, N806, F401, E261, E265, N803, F841, N801, N805, N815, N816, F811, N814, N804, W503, W291, N807, N813, W504, E741, E301,
# E722: Do not use bare excepts -- A candidate to remove from this list!
E722


exclude =
# There is simply too much in here, somebody will need to check these manually
src/plugins/grass/scripts,
# Generated code, hacking allowed. Feel free to go over it
python/core/auto_additions/,
python/analysis/auto_additions/,
python/gui/auto_additions/,
python/server/auto_additions/,
# Plenty of star imports used
python/PyQt/
@@ -0,0 +1,23 @@
name: Pyflakes

on: [push, pull_request]

jobs:
flake8_py3:
runs-on: ubuntu-latest
steps:
- name: Setup Python
uses: actions/setup-python@v1
with:
python-version: 3.7.6
architecture: x64
- name: Checkout
uses: actions/checkout@master
- name: Install flake8
run: pip install flake8
- name: Run flake8
uses: suo/flake8-github-action@releases/v1
with:
checkName: 'flake8_py3' # NOTE: this needs to be the same as the job name
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
@@ -67,7 +67,7 @@ def library_install_exe(out=''):
out = run_check().splitlines()
for line in out:
# err = re.search('(err:module:import_dll (Library |Loading library)) (.*?\.dll) ', line)
err = re.search('([^ ]+\.dll) \(which', line)
err = re.search(r'([^ ]+\.dll) \(which', line)
if err is not None:

dll = err.group(1)
@@ -98,7 +98,7 @@ def library_install_objdump(path, level):

done.append(path)

command = objdump_path + " -p " + lib + " | grep -o ': .*\.dll$'"
command = objdump_path + " -p " + lib + " | grep -o ': .*\\.dll$'"
res = subprocess.getstatusoutput(command)
if (res[0] > 0):
print("Error: objdump failed with " + lib)
@@ -134,7 +134,7 @@ def handlesNull(self):


def qgsfunction(args='auto', group='custom', **kwargs):
"""
r"""
Decorator function used to define a user expression function.
:param args: Number of parameters, set to 'auto' to accept a variable length of parameters.
@@ -44,7 +44,7 @@
# return _QGISfilter


pluginType = MODULE
pluginType = MODULE # noqa


def moduleInformation():
@@ -34,6 +34,7 @@
)
from qgis.core import (
Qgis,
QgsCoordinateReferenceSystem,
QgsCredentials,
QgsVectorLayer,
QgsDataSourceUri,
@@ -69,15 +70,15 @@ def __init__(self, connection, sql=None):
self.result = None
self.cursor = 0
self.closed = False
if (self.sql != None):
if (self.sql is not None):
self._execute()

def _toStrResultSet(self, res):
newres = []
for rec in res:
newrec = []
for col in rec:
if type(col) == type(QVariant(None)):
if type(col) == type(QVariant(None)): # noqa
if (str(col) == 'NULL'):
col = None
else:
@@ -87,11 +88,11 @@ def _toStrResultSet(self, res):
return newres

def _execute(self, sql=None):
if self.sql == sql and self.result != None:
if self.sql == sql and self.result is not None:
return
if (sql != None):
if (sql is not None):
self.sql = sql
if (self.sql == None):
if (self.sql is None):
return
self._debug("execute called with sql " + self.sql)
try:
@@ -1155,7 +1156,7 @@ def connection_error_types(self):
return psycopg2.InterfaceError, psycopg2.OperationalError

def _execute(self, cursor, sql):
if cursor != None:
if cursor is not None:
cursor._execute(sql)
return cursor
return CursorAdapter(self.core_connection, sql)
@@ -45,7 +45,7 @@ def setUpClass(self):
self.old_pgdatabase_env = os.environ.get('PGDATABASE')
# QGIS_PGTEST_DB contains the full connection string and not only the DB name!
QGIS_PGTEST_DB = os.environ.get('QGIS_PGTEST_DB')
if not QGIS_PGTEST_DB is None:
if QGIS_PGTEST_DB is not None:
test_uri = QgsDataSourceUri(QGIS_PGTEST_DB)
self.testdb = test_uri.database()
else:
@@ -22,7 +22,15 @@
__copyright__ = '(C) 2012, Victor Olaya'

from processing.tools.dataobjects import * # NOQA
from processing.tools.dataobjects import createContext
from processing.tools.general import * # NOQA
from processing.tools.general import (
algorithmHelp,
run,
runAndLoadResults,
createAlgorithmDialog,
execAlgorithmDialog
)
from processing.tools.vector import * # NOQA
from processing.tools.raster import * # NOQA
from processing.tools.system import * # NOQA
@@ -189,7 +189,7 @@ def searchFolder(folder):

if command:
Grass7Utils.command = command
if path is '':
if path == '':
Grass7Utils.path = os.path.dirname(command)

return command
@@ -190,7 +190,7 @@ def preprocessParameters(self, parameters):
#- metadata with 'group_key' and 'group_key' is a valid parameter and it's value == metadata()['group_value']
if 'group_key' in param.metadata() and not param.metadata()['group_key'] in parameters:
valid_params[k] = v
elif not 'group_key' in param.metadata() or parameters[param.metadata()['group_key']] == param.metadata()['group_value']:
elif 'group_key' not in param.metadata() or parameters[param.metadata()['group_key']] == param.metadata()['group_value']:
valid_params[k] = v

return valid_params
@@ -96,7 +96,7 @@ def __setWrapperVisibility(self, wrapper, v):

def updateAllParameters(self, current_value):
for parameter in self.get_algorithm().parameterDefinitions():
if not 'group_key' in parameter.metadata() or parameter.metadata()['group_key'] != self.param.name():
if 'group_key' not in parameter.metadata() or parameter.metadata()['group_key'] != self.param.name():
continue
name = parameter.name()
choice_key = parameter.metadata()['group_key']
@@ -105,7 +105,7 @@ def updateAllParameters(self, current_value):
if current_value is None:
current_value = choice_param.defaultValue()
pattern = "{}.{}.".format(choice_key, choice_param.getValueAsText(current_value))
if not pattern in name:
if pattern not in name:
flags = self.get_algorithm().parameterDefinition(name).flags()
if not flags & QgsProcessingParameterDefinition.FlagOptional:
self.flagsModified[name] = True
@@ -131,7 +131,7 @@ def postInitialize(self, wrappers):
# return
self.updateAllParameters(current_value=None)
for parameter in self.get_algorithm().parameterDefinitions():
if not 'group_key' in parameter.metadata() or parameter.metadata()['group_key'] != self.param.name():
if 'group_key' not in parameter.metadata() or parameter.metadata()['group_key'] != self.param.name():
continue
for wrapper in wrappers:
if wrapper.param.name() == parameter.name():
@@ -162,7 +162,7 @@ def __init__(self, name='', description='', options=[], default=None, isSource=F
self.value = self.default

def getValueAsText(self, value):
if not value in self.options:
if value not in self.options:
value = self.options[int(value)]
return value

@@ -103,7 +103,7 @@ def processAlgorithm(self, parameters, context, feedback):

databaseuri = database.dataProvider().dataSourceUri()
uri = QgsDataSourceUri(databaseuri)
if uri.database() is '':
if uri.database() == '':
if '|layername' in databaseuri:
databaseuri = databaseuri[:databaseuri.find('|layername')]
elif '|layerid' in databaseuri:
@@ -191,27 +191,6 @@ def _cellsize(layer):

return {self.OUTPUT: output}

def processBeforeAddingToModeler(self, algorithm, model):
values = []
expression = algorithm.params[self.EXPRESSION]
for i in list(model.inputs.values()):
param = i.param
if isinstance(param, QgsProcessingParameterRasterLayer) and "{}@".format(param.name) in expression:
values.append(ValueFromInput(param.name()))

if algorithm.name:
dependent = model.getDependentAlgorithms(algorithm.name)
else:
dependent = []
for alg in list(model.algs.values()):
if alg.modeler_name not in dependent:
for out in alg.algorithm.outputs:
if (isinstance(out, QgsProcessingOutputRasterLayer) and
"{}:{}@".format(alg.modeler_name, out.name) in expression):
values.append(ValueFromOutput(alg.modeler_name, out.name))

algorithm.params[self.LAYERS] = values

def mappedNameToLayer(self, lyr, expression, layersDict, context):
'''Try to identify if a real layer is mapped in the expression with a symbolic name.'''

@@ -29,6 +29,7 @@

from qgis.core import (NULL,
QgsApplication,
QgsCsException,
QgsField,
QgsFeatureSink,
QgsRaster,
@@ -67,7 +67,7 @@ def processAlgorithm(self, parameters, context, feedback):
database = self.parameterAsVectorLayer(parameters, self.DATABASE, context)
databaseuri = database.dataProvider().dataSourceUri()
uri = QgsDataSourceUri(databaseuri)
if uri.database() is '':
if uri.database() == '':
if '|layername' in databaseuri:
databaseuri = databaseuri[:databaseuri.find('|layername')]
elif '|layerid' in databaseuri:
@@ -219,10 +219,10 @@ def renderSingleMetatile(self, metatile):
job.renderSynchronously()
painter.end()

## For analysing metatiles (labels, etc.)
## metatile_dir = os.path.join(output_dir, str(zoom))
## os.makedirs(metatile_dir, exist_ok=True)
## image.save(os.path.join(metatile_dir, 'metatile_%s.png' % i))
# For analysing metatiles (labels, etc.)
# metatile_dir = os.path.join(output_dir, str(zoom))
# os.makedirs(metatile_dir, exist_ok=True)
# image.save(os.path.join(metatile_dir, 'metatile_%s.png' % i))

for r, c, tile in metatile.tiles:
tileImage = image.copy(self.tile_width * r, self.tile_height * c, self.tile_width, self.tile_height)
@@ -270,7 +270,7 @@ def generate(self, writer, parameters, context, feedback):
if self.tile_format == 'PNG':
self.settingsDictionary[thread].setBackgroundColor(self.color)

## disable partial labels (they would be cut at the edge of tiles)
# disable partial labels (they would be cut at the edge of tiles)
labeling_engine_settings = self.settingsDictionary[thread].labelingEngineSettings()
labeling_engine_settings.setFlag(QgsLabelingEngineSettings.UsePartialCandidates, False)
self.settingsDictionary[thread].setLabelingEngineSettings(labeling_engine_settings)
@@ -89,7 +89,7 @@ def processAlgorithm(self, parameters, context, feedback):
directory = self.parameterAsString(parameters, self.OUTPUT, context)

output_format = context.preferredVectorFormat()
if not output_format in QgsVectorFileWriter.supportedFormatExtensions():
if output_format not in QgsVectorFileWriter.supportedFormatExtensions():
# fallback to gpkg if preferred format is not available
output_format = 'gpkg'

@@ -153,7 +153,7 @@ def getParameterFromString(s, context=''):
params[3] = True if params[3].lower() == 'true' else False
if len(params) > 4:
# For multiple values; default value is a list of int
if params[3] == True:
if params[3] is True:
params[4] = [int(v) for v in params[4].split(',')] if params[4] is not None else None
else:
params[4] = int(params[4]) if params[4] is not None else None
@@ -291,7 +291,7 @@ def execute_in_place(alg, parameters, context=None, feedback=None):
if context is None:
context = dataobjects.createContext(feedback)

if not 'INPUT' in parameters or not parameters['INPUT']:
if 'INPUT' not in parameters or not parameters['INPUT']:
parameters['INPUT'] = iface.activeLayer()
ok, results = execute_in_place_run(alg, parameters, context=context, feedback=feedback)
if ok:
@@ -190,7 +190,7 @@ def fillTreeUsingProviders(self):
emptyItem.setEditable(False)

rootItem.insertRow(0, [groupItem, emptyItem])
if not group in settings:
if group not in settings:
continue

# add menu item only if it has any search matches
@@ -33,7 +33,7 @@
from qgis.PyQt.QtWidgets import QMessageBox, QVBoxLayout, QLabel, QLineEdit, QWidget
from qgis.PyQt.QtGui import QPalette, QColor

from qgis.core import QgsApplication
from qgis.core import QgsApplication, Qgis
from qgis.gui import QgsMessageBar


@@ -71,7 +71,7 @@ def accept(self):
QgsApplication.processingRegistry().providerById('preconfigured').refreshAlgorithms()
except AlgorithmDialogBase.InvalidParameterValue as e:
try:
self.buttonBox().accepted.connect(lambda: e.widget.setPalette(QPalette()))
self.buttonBox().accepted.connect(lambda: e.widget.setPalette(QPalette())) # noqa do not ask me why
palette = e.widget.palette()
palette.setColor(QPalette.Base, QColor(255, 255, 0))
e.widget.setPalette(palette)
@@ -113,7 +113,7 @@ def check_algorithm(self, name, defs):
parameters[k] = p

for r, p in list(defs['results'].items()):
if not 'in_place_result' in p or not p['in_place_result']:
if 'in_place_result' not in p or not p['in_place_result']:
parameters[r] = self.load_result_param(p)

expectFailure = False

0 comments on commit b1873a4

Please sign in to comment.
You can’t perform that action at this time.