From 5c4992e5510d98f267efe20ec9f684ccbcfa4a2e Mon Sep 17 00:00:00 2001 From: Etienne Trimaille Date: Sun, 19 Dec 2021 17:20:54 +0100 Subject: [PATCH] GH Action - Review the CI action about some python flake --- .github/workflows/test.yaml | 37 +++++++--- REQUIREMENTS-dev.txt | 1 + qgis-app/custom_haystack_urls.py | 1 + qgis-app/middleware.py | 1 - qgis-app/plugins/utils/plugin_upload.py | 81 ---------------------- qgis-app/plugins/validator.py | 6 +- setup.cfg | 90 ++++++++++++++++++++++++- 7 files changed, 119 insertions(+), 98 deletions(-) create mode 100644 REQUIREMENTS-dev.txt delete mode 100755 qgis-app/plugins/utils/plugin_upload.py diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 8a48239b..87a2f092 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -12,34 +12,48 @@ jobs: strategy: matrix: python-version: - - 3.7 + - '3.7' steps: - - uses: actions/checkout@v2 - name: Set up Python ${{ matrix.python-version }} uses: actions/setup-python@v2 + with: + python-version: ${{ matrix.python-version }} + architecture: x64 - - name: Test installing development dependencies - run: | - python -m pip install --upgrade pip - pip install flake8 + - name: Checkout + uses: actions/checkout@master + + - uses: actions/cache@v2 + with: + path: ~/.cache/pip + key: ${{ runner.os }}-pip-${{ hashFiles('REQUIREMENTS-dev.txt') }} + restore-keys: | + ${{ runner.os }}-pip- + + - name: Install Python requirements + run: pip install -r REQUIREMENTS-dev.txt + + - name: Run flake8 + run: flake8 --config setup.cfg - - name: Run Flake8 test - run: flake8 . test: runs-on: ubuntu-latest needs: - lint + defaults: + run: + working-directory: dockerize steps: - uses: actions/checkout@v2 + - name: Run docker-compose build - working-directory: dockerize run: docker-compose build + - name: Run the containers - working-directory: dockerize run: docker-compose up -d db devweb + - name: Run Coverage test - working-directory: dockerize run: | cat << EOF | docker-compose exec -T devweb bash pip install coverage @@ -48,6 +62,7 @@ jobs: coverage run manage.py test coverage xml EOF + - name: Upload coverage to codecov uses: codecov/codecov-action@v2 with: diff --git a/REQUIREMENTS-dev.txt b/REQUIREMENTS-dev.txt new file mode 100644 index 00000000..39304807 --- /dev/null +++ b/REQUIREMENTS-dev.txt @@ -0,0 +1 @@ +flake8 diff --git a/qgis-app/custom_haystack_urls.py b/qgis-app/custom_haystack_urls.py index 30fffc32..3d5da176 100755 --- a/qgis-app/custom_haystack_urls.py +++ b/qgis-app/custom_haystack_urls.py @@ -4,6 +4,7 @@ from haystack.query import SearchQuerySet from django.conf.urls import include, url + class SearchWithRequest(SearchView): __qualname__ = 'SearchWithRequest' diff --git a/qgis-app/middleware.py b/qgis-app/middleware.py index 616ac61c..0bb8be3f 100644 --- a/qgis-app/middleware.py +++ b/qgis-app/middleware.py @@ -28,4 +28,3 @@ def middleware(request): return response return middleware - diff --git a/qgis-app/plugins/utils/plugin_upload.py b/qgis-app/plugins/utils/plugin_upload.py deleted file mode 100755 index 0079ed9b..00000000 --- a/qgis-app/plugins/utils/plugin_upload.py +++ /dev/null @@ -1,81 +0,0 @@ -#!/usr/bin/env python -# This script uploads a plugin package on the server -# -# Author: A. Pasotti, V. Picavet - -import xmlrpclib, sys, os -import getpass -from optparse import OptionParser - -# Default Configuration -PROTOCOL='http' -SERVER='plugins.qgis.org' -PORT='80' -ENDPOINT='/plugins/RPC2/' -VERBOSE=False - -def main(options, args): - address = "%s://%s:%s@%s:%s%s" % (PROTOCOL, options.username, options.password, - options.server, options.port, ENDPOINT) - print "Connecting to: %s" % hidepassword(address) - - server = xmlrpclib.ServerProxy(address, verbose=VERBOSE) - - try: - plugin_id, version_id = server.plugin.upload(xmlrpclib.Binary(open(args[0]).read())) - print "Plugin ID: %s" % plugin_id - print "Version ID: %s" % version_id - except xmlrpclib.ProtocolError as err: - print "A protocol error occurred" - print "URL: %s" % hidepassword(err.url, 0) - print "HTTP/HTTPS headers: %s" % err.headers - print "Error code: %d" % err.errcode - print "Error message: %s" % err.errmsg - except xmlrpclib.Fault as err: - print "A fault occurred" - print "Fault code: %d" % err.faultCode - print "Fault string: %s" % err.faultString - except Exception as err: - print "Error occourred" - print "Error message: %s" % err - - -def hidepassword(url, start = 6): - """Returns the http url "with" password part replaced with '*'.""" - passdeb = url.find(':', start) + 1 - passend = url.find('@') - return "%s%s%s" % (url[:passdeb], '*' * (passend - passdeb), url[passend:]) - - -if __name__ == "__main__": - parser = OptionParser(usage="%prog [options] plugin.zip") - parser.add_option("-w", "--password", dest="password", - help="Password for plugin site", metavar="******") - parser.add_option("-u", "--username", dest="username", - help="Username of plugin site", metavar="user") - parser.add_option("-p", "--port", dest="port", - help="Server port to connect to", metavar="80") - parser.add_option("-s", "--server", dest="server", - help="Specify server name", metavar="plugins.qgis.org") - (options, args) = parser.parse_args() - if len(args) != 1: - print "Please specify zip file.\n" - parser.print_help() - sys.exit(1) - if not options.server: - options.server = SERVER - if not options.port: - options.port = PORT - if not options.username: - # interactive mode - username = getpass.getuser() - print "Please enter user name [%s] :"%username, - res = raw_input() - if res != "": - options.username = res - else: - options.username = username - if not options.password: - # interactive mode - options.password = getpass.getpass() - main(options, args) diff --git a/qgis-app/plugins/validator.py b/qgis-app/plugins/validator.py index dde39f16..533cb553 100644 --- a/qgis-app/plugins/validator.py +++ b/qgis-app/plugins/validator.py @@ -50,7 +50,7 @@ def _check_required_metadata(metadata): Checks if required metadata are in place, raise ValidationError if not found """ for md in PLUGIN_REQUIRED_METADATA: - if not md in dict(metadata) or not dict(metadata)[md]: + if md not in dict(metadata) or not dict(metadata)[md]: raise ValidationError(_('Cannot find metadata %s in metadata source %s.
For further informations about metadata, please see: metadata documentation') % (md, dict(metadata).get('metadata_source'))) @@ -154,11 +154,11 @@ def validator(package): package_name = package_name[:-1] initname = package_name + '/__init__.py' metadataname = package_name + '/metadata.txt' - if not initname in namelist and not metadataname in namelist: + if initname not in namelist and metadataname not in namelist: raise ValidationError(_('Cannot find __init__.py or metadata.txt in the compressed package: this does not seems a valid plugin (I searched for %s and %s)') % (initname, metadataname)) # Checks for __init__.py presence - if not initname in namelist: + if initname not in namelist: raise ValidationError(_("Cannot find __init__.py in plugin package.")) # Checks metadata diff --git a/setup.cfg b/setup.cfg index 4303604e..fae25c68 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,4 +1,90 @@ [flake8] -exclude = .git,*migrations* -ignore = E203,E121,E122,E123,E124,E125,E126,E127,E128,E402,W503 +exclude = + .git, + .venv/, + ./.venv/, + vagrant_assets, + qgis-app/*/migrations/, + qgis-app/plugins/tests/HelloWorld/, + +ignore = + # indentation is not a multiple of 4 + E111, + E114, + # closing bracket + E121, + E122, + E123, + E124, + E125, + E126, + E127, + E128, + E129, + # continuation line unaligned for hanging indent + E131, + # missing whitespace + E201, + E202, + E203, + E211, + E221, + E222, + E225, + E226, + E231, + # multiple whitespace + E241, + # unexpected spaces around keyword + E251, + # inline comment + E261, + E262, + # block comment + E265, + # too many leading # for block comment + E266, + # multiple spaces after keyword + E271, + # expected 2 blank lines, found 1 + E301, + E302, + E303, + E305, + # multiple imports + E401, + # module not at top of file + E402, + # line too long + E501, + # bare except + E722, + # ambiguous variable name + E741, + # import not used + F401, + # shadowed by loop variable + F402, + # star imports + F403, + F404, + F405, + # dictionary key 'created_by' repeated with different values + F601, + # redefinition + F811, + # local variable not used + F841, + # trailing whitespace + W291, + # no newline at end of file + W292, + # blank line at end of file + W391, + # line break before binary operator + W503, + W504, + # invalid escape sequence + W605, + max-line-length = 79