Introduce flake8 checking - #58

This introduces flake8 and fixes a bunch of flake8 errors.

flake8 is run with: ./venv/bin/flake8 plinth
if you're using a python3 venv.

We can eventually further integrate this with gitlab ci.

https://salsa.debian.org/freedombox-team/plinth/issues/58

Reviewed-by: Sunil Mohan Adapa <sunil@medhas.org>
This commit is contained in:
Nikolas Nyby 2019-07-23 21:43:16 -04:00 committed by Sunil Mohan Adapa
parent d2e987ef3c
commit ace339eabf
No known key found for this signature in database
GPG Key ID: 43EA1CFF0AA7C5F2
16 changed files with 26 additions and 25 deletions

1
debian/control vendored
View File

@ -29,6 +29,7 @@ Build-Depends:
python3-django-axes (>= 3.0.3),
python3-django-captcha,
python3-django-stronghold (>= 0.3.0),
python3-flake8,
python3-gi,
python3-paramiko,
python3-psutil,

View File

@ -66,7 +66,7 @@ def run_setup_and_exit(module_list, allow_install=True):
error_code = 0
try:
setup.run_setup_on_modules(module_list, allow_install)
except Exception as exception:
except Exception:
error_code = 1
sys.exit(error_code)

View File

@ -26,4 +26,5 @@ class AppConfig(apps.AppConfig):
def ready(self):
# Signals must be loaded for axes to get the login_failed signals
# flake8: noqa
from axes import signals # isort:skip pylint: disable=unused-import

View File

@ -22,7 +22,6 @@ import collections
import django
import importlib
import logging
import os
import pathlib
import re
@ -157,7 +156,8 @@ def get_modules_to_load():
# './setup.py install' has not been executed yet. Pickup files to load
# from local module directories.
directory = pathlib.Path(__file__).parent
files = list(directory.glob('modules/*/data/etc/plinth/modules-enabled/*'))
files = list(directory.glob(
'modules/*/data/etc/plinth/modules-enabled/*'))
# Omit hidden files
files = [

View File

@ -28,7 +28,7 @@ def delete_tmp_backup_file(function):
def wrap(request, *args, **kwargs):
path = request.session.get(SESSION_PATH_VARIABLE, None)
if path:
if path:
if os.path.isfile(path):
os.remove(path)
del request.session[SESSION_PATH_VARIABLE]

View File

@ -19,10 +19,8 @@ Forms for backups module.
"""
import logging
import os
import re
import subprocess
import tempfile
from django import forms
from django.core.exceptions import ValidationError
@ -204,9 +202,10 @@ class VerifySshHostkeyForm(forms.Form):
stderr=subprocess.DEVNULL)
keys = keyscan.stdout.decode().splitlines()
# Generate user-friendly fingerprints of public keys
keygen = subprocess.run(['ssh-keygen', '-l', '-f', '-'],
input=keyscan.stdout,
stdout=subprocess.PIPE)
keygen = subprocess.run(
['ssh-keygen', '-l', '-f', '-'],
input=keyscan.stdout,
stdout=subprocess.PIPE)
fingerprints = keygen.stdout.decode().splitlines()
return zip(keys, fingerprints)

View File

@ -23,8 +23,6 @@ from unittest.mock import MagicMock, call, patch
import pytest
from django.core.files.uploadedfile import SimpleUploadedFile
from plinth import cfg, module_loader
from .. import ROOT_REPOSITORY, api, forms
# pylint: disable=protected-access

View File

@ -21,18 +21,14 @@ Tests for SSH remotes for backups.
import datetime
import os
import pwd
import shutil
import subprocess
import tempfile
import pytest
from django.forms import ValidationError
from django.urls import reverse
from plinth.modules.backups import network_storage
from plinth.utils import generate_password, random_string
from .. import forms, views
from .. import forms
pytestmark = [
pytest.mark.usefixtures('needs_root', 'load_cfg', 'has_ssh_key'),

View File

@ -57,7 +57,7 @@ class CoquelicotAppView(views.AppView):
'coquelicot', ['set-upload-password'],
input=form_data['upload_password'].encode())
messages.success(self.request, _('Upload password updated'))
except ActionError as e:
except ActionError:
messages.error(self.request,
_('Failed to update upload password'))
@ -68,7 +68,7 @@ class CoquelicotAppView(views.AppView):
'coquelicot', ['set-max-file-size',
str(max_file_size)])
messages.success(self.request, _('Maximum file size updated'))
except ActionError as e:
except ActionError:
messages.error(self.request,
_('Failed to update maximum file size'))

View File

@ -97,7 +97,7 @@ def setup(helper, old_version=None):
def get_enabled_services(domain_name):
"""Get enabled services for the domain name."""
if domain_name != None and domain_name != '':
if domain_name is not None and domain_name != '':
try:
domainname_services = firewall.get_enabled_services(
zone='external')

View File

@ -38,7 +38,8 @@ urlpatterns = [
url(r'^sys/networks/add/ethernet/$', views.add_ethernet,
name='add_ethernet'),
url(r'^sys/networks/add/pppoe/$', views.add_pppoe, name='add_pppoe'),
url(r'^sys/networks/add/wifi/(?:(?P<ssid>[^/]+)/(?P<interface_name>[^/]+)/)?$',
url(r'^sys/networks/add/wifi/(?:(?P<ssid>[^/]+)/'
r'(?P<interface_name>[^/]+)/)?$',
views.add_wifi, name='add_wifi'),
url(r'^sys/networks/(?P<uuid>[\w.@+-]+)/delete/$', views.delete,
name='delete'),

View File

@ -25,7 +25,6 @@ from django.utils.translation import ugettext_lazy as _
from plinth import action_utils, actions
from plinth import app as app_module
from plinth import frontpage, menu
from plinth.daemon import Daemon
from plinth.modules.apache.components import Uwsgi, Webserver
from plinth.modules.firewall.components import Firewall
from plinth.modules.users import register_group

View File

@ -423,7 +423,8 @@ class ForceUpgrader():
"""Raised when upgrade fails but can be tried again immediately."""
class PermanentFailure(Exception):
"""Raised when upgrade fails and there is nothing more we wish to do."""
"""Raised when upgrade fails and there is nothing more we wish to do.
"""
def __init__(self):
"""Initialize the force upgrader."""

View File

@ -28,6 +28,7 @@ from plinth import cfg
from plinth import context_processors as cp
from plinth import menu as menu_module
@pytest.fixture(name='menu', autouse=True)
def fixture_menu():
"""Initialized menu module."""

View File

@ -83,6 +83,7 @@ pppoe_settings = {
},
}
@pytest.fixture(name='network')
def fixture_network(needs_root):
"""Return the network module. Load it conservatively."""
@ -116,7 +117,6 @@ def fixture_pppoe_uuid(network):
yield from _connection(network, pppoe_settings)
@pytest.mark.usefixtures('ethernet_uuid', 'wifi_uuid', 'pppoe_uuid')
def test_get_connection_list(network):
"""Check that we can get a list of available connections."""
@ -127,7 +127,6 @@ def test_get_connection_list(network):
assert 'plinth_test_pppoe' in [x['name'] for x in connections]
def test_get_connection(network, ethernet_uuid, wifi_uuid):
"""Check that we can get a connection by name."""
connection = network.get_connection(ethernet_uuid)

View File

@ -268,7 +268,12 @@ setuptools.setup(
'requests',
'ruamel.yaml',
],
tests_require=['pytest', 'pytest-cov', 'pytest-django'],
tests_require=[
'pytest',
'pytest-cov',
'pytest-django',
'flake8',
],
package_data={
'': ['templates/*', 'static/*', 'locale/*/LC_MESSAGES/*.[pm]o']
},