mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-09-19 04:59:01 +00:00
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:
parent
d2e987ef3c
commit
ace339eabf
1
debian/control
vendored
1
debian/control
vendored
@ -29,6 +29,7 @@ Build-Depends:
|
|||||||
python3-django-axes (>= 3.0.3),
|
python3-django-axes (>= 3.0.3),
|
||||||
python3-django-captcha,
|
python3-django-captcha,
|
||||||
python3-django-stronghold (>= 0.3.0),
|
python3-django-stronghold (>= 0.3.0),
|
||||||
|
python3-flake8,
|
||||||
python3-gi,
|
python3-gi,
|
||||||
python3-paramiko,
|
python3-paramiko,
|
||||||
python3-psutil,
|
python3-psutil,
|
||||||
|
|||||||
@ -66,7 +66,7 @@ def run_setup_and_exit(module_list, allow_install=True):
|
|||||||
error_code = 0
|
error_code = 0
|
||||||
try:
|
try:
|
||||||
setup.run_setup_on_modules(module_list, allow_install)
|
setup.run_setup_on_modules(module_list, allow_install)
|
||||||
except Exception as exception:
|
except Exception:
|
||||||
error_code = 1
|
error_code = 1
|
||||||
|
|
||||||
sys.exit(error_code)
|
sys.exit(error_code)
|
||||||
|
|||||||
@ -26,4 +26,5 @@ class AppConfig(apps.AppConfig):
|
|||||||
|
|
||||||
def ready(self):
|
def ready(self):
|
||||||
# Signals must be loaded for axes to get the login_failed signals
|
# Signals must be loaded for axes to get the login_failed signals
|
||||||
|
# flake8: noqa
|
||||||
from axes import signals # isort:skip pylint: disable=unused-import
|
from axes import signals # isort:skip pylint: disable=unused-import
|
||||||
|
|||||||
@ -22,7 +22,6 @@ import collections
|
|||||||
import django
|
import django
|
||||||
import importlib
|
import importlib
|
||||||
import logging
|
import logging
|
||||||
import os
|
|
||||||
import pathlib
|
import pathlib
|
||||||
import re
|
import re
|
||||||
|
|
||||||
@ -157,7 +156,8 @@ def get_modules_to_load():
|
|||||||
# './setup.py install' has not been executed yet. Pickup files to load
|
# './setup.py install' has not been executed yet. Pickup files to load
|
||||||
# from local module directories.
|
# from local module directories.
|
||||||
directory = pathlib.Path(__file__).parent
|
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
|
# Omit hidden files
|
||||||
files = [
|
files = [
|
||||||
|
|||||||
@ -28,7 +28,7 @@ def delete_tmp_backup_file(function):
|
|||||||
|
|
||||||
def wrap(request, *args, **kwargs):
|
def wrap(request, *args, **kwargs):
|
||||||
path = request.session.get(SESSION_PATH_VARIABLE, None)
|
path = request.session.get(SESSION_PATH_VARIABLE, None)
|
||||||
if path:
|
if path:
|
||||||
if os.path.isfile(path):
|
if os.path.isfile(path):
|
||||||
os.remove(path)
|
os.remove(path)
|
||||||
del request.session[SESSION_PATH_VARIABLE]
|
del request.session[SESSION_PATH_VARIABLE]
|
||||||
|
|||||||
@ -19,10 +19,8 @@ Forms for backups module.
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
import os
|
|
||||||
import re
|
import re
|
||||||
import subprocess
|
import subprocess
|
||||||
import tempfile
|
|
||||||
|
|
||||||
from django import forms
|
from django import forms
|
||||||
from django.core.exceptions import ValidationError
|
from django.core.exceptions import ValidationError
|
||||||
@ -204,9 +202,10 @@ class VerifySshHostkeyForm(forms.Form):
|
|||||||
stderr=subprocess.DEVNULL)
|
stderr=subprocess.DEVNULL)
|
||||||
keys = keyscan.stdout.decode().splitlines()
|
keys = keyscan.stdout.decode().splitlines()
|
||||||
# Generate user-friendly fingerprints of public keys
|
# Generate user-friendly fingerprints of public keys
|
||||||
keygen = subprocess.run(['ssh-keygen', '-l', '-f', '-'],
|
keygen = subprocess.run(
|
||||||
input=keyscan.stdout,
|
['ssh-keygen', '-l', '-f', '-'],
|
||||||
stdout=subprocess.PIPE)
|
input=keyscan.stdout,
|
||||||
|
stdout=subprocess.PIPE)
|
||||||
fingerprints = keygen.stdout.decode().splitlines()
|
fingerprints = keygen.stdout.decode().splitlines()
|
||||||
|
|
||||||
return zip(keys, fingerprints)
|
return zip(keys, fingerprints)
|
||||||
|
|||||||
@ -23,8 +23,6 @@ from unittest.mock import MagicMock, call, patch
|
|||||||
import pytest
|
import pytest
|
||||||
from django.core.files.uploadedfile import SimpleUploadedFile
|
from django.core.files.uploadedfile import SimpleUploadedFile
|
||||||
|
|
||||||
from plinth import cfg, module_loader
|
|
||||||
|
|
||||||
from .. import ROOT_REPOSITORY, api, forms
|
from .. import ROOT_REPOSITORY, api, forms
|
||||||
|
|
||||||
# pylint: disable=protected-access
|
# pylint: disable=protected-access
|
||||||
|
|||||||
@ -21,18 +21,14 @@ Tests for SSH remotes for backups.
|
|||||||
import datetime
|
import datetime
|
||||||
import os
|
import os
|
||||||
import pwd
|
import pwd
|
||||||
import shutil
|
|
||||||
import subprocess
|
import subprocess
|
||||||
import tempfile
|
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
from django.forms import ValidationError
|
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 plinth.utils import generate_password, random_string
|
||||||
|
|
||||||
from .. import forms, views
|
from .. import forms
|
||||||
|
|
||||||
pytestmark = [
|
pytestmark = [
|
||||||
pytest.mark.usefixtures('needs_root', 'load_cfg', 'has_ssh_key'),
|
pytest.mark.usefixtures('needs_root', 'load_cfg', 'has_ssh_key'),
|
||||||
|
|||||||
@ -57,7 +57,7 @@ class CoquelicotAppView(views.AppView):
|
|||||||
'coquelicot', ['set-upload-password'],
|
'coquelicot', ['set-upload-password'],
|
||||||
input=form_data['upload_password'].encode())
|
input=form_data['upload_password'].encode())
|
||||||
messages.success(self.request, _('Upload password updated'))
|
messages.success(self.request, _('Upload password updated'))
|
||||||
except ActionError as e:
|
except ActionError:
|
||||||
messages.error(self.request,
|
messages.error(self.request,
|
||||||
_('Failed to update upload password'))
|
_('Failed to update upload password'))
|
||||||
|
|
||||||
@ -68,7 +68,7 @@ class CoquelicotAppView(views.AppView):
|
|||||||
'coquelicot', ['set-max-file-size',
|
'coquelicot', ['set-max-file-size',
|
||||||
str(max_file_size)])
|
str(max_file_size)])
|
||||||
messages.success(self.request, _('Maximum file size updated'))
|
messages.success(self.request, _('Maximum file size updated'))
|
||||||
except ActionError as e:
|
except ActionError:
|
||||||
messages.error(self.request,
|
messages.error(self.request,
|
||||||
_('Failed to update maximum file size'))
|
_('Failed to update maximum file size'))
|
||||||
|
|
||||||
|
|||||||
@ -97,7 +97,7 @@ def setup(helper, old_version=None):
|
|||||||
|
|
||||||
def get_enabled_services(domain_name):
|
def get_enabled_services(domain_name):
|
||||||
"""Get enabled services for the 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:
|
try:
|
||||||
domainname_services = firewall.get_enabled_services(
|
domainname_services = firewall.get_enabled_services(
|
||||||
zone='external')
|
zone='external')
|
||||||
|
|||||||
@ -38,7 +38,8 @@ urlpatterns = [
|
|||||||
url(r'^sys/networks/add/ethernet/$', views.add_ethernet,
|
url(r'^sys/networks/add/ethernet/$', views.add_ethernet,
|
||||||
name='add_ethernet'),
|
name='add_ethernet'),
|
||||||
url(r'^sys/networks/add/pppoe/$', views.add_pppoe, name='add_pppoe'),
|
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'),
|
views.add_wifi, name='add_wifi'),
|
||||||
url(r'^sys/networks/(?P<uuid>[\w.@+-]+)/delete/$', views.delete,
|
url(r'^sys/networks/(?P<uuid>[\w.@+-]+)/delete/$', views.delete,
|
||||||
name='delete'),
|
name='delete'),
|
||||||
|
|||||||
@ -25,7 +25,6 @@ from django.utils.translation import ugettext_lazy as _
|
|||||||
from plinth import action_utils, actions
|
from plinth import action_utils, actions
|
||||||
from plinth import app as app_module
|
from plinth import app as app_module
|
||||||
from plinth import frontpage, menu
|
from plinth import frontpage, menu
|
||||||
from plinth.daemon import Daemon
|
|
||||||
from plinth.modules.apache.components import Uwsgi, Webserver
|
from plinth.modules.apache.components import Uwsgi, Webserver
|
||||||
from plinth.modules.firewall.components import Firewall
|
from plinth.modules.firewall.components import Firewall
|
||||||
from plinth.modules.users import register_group
|
from plinth.modules.users import register_group
|
||||||
|
|||||||
@ -423,7 +423,8 @@ class ForceUpgrader():
|
|||||||
"""Raised when upgrade fails but can be tried again immediately."""
|
"""Raised when upgrade fails but can be tried again immediately."""
|
||||||
|
|
||||||
class PermanentFailure(Exception):
|
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):
|
def __init__(self):
|
||||||
"""Initialize the force upgrader."""
|
"""Initialize the force upgrader."""
|
||||||
|
|||||||
@ -28,6 +28,7 @@ from plinth import cfg
|
|||||||
from plinth import context_processors as cp
|
from plinth import context_processors as cp
|
||||||
from plinth import menu as menu_module
|
from plinth import menu as menu_module
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(name='menu', autouse=True)
|
@pytest.fixture(name='menu', autouse=True)
|
||||||
def fixture_menu():
|
def fixture_menu():
|
||||||
"""Initialized menu module."""
|
"""Initialized menu module."""
|
||||||
|
|||||||
@ -83,6 +83,7 @@ pppoe_settings = {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(name='network')
|
@pytest.fixture(name='network')
|
||||||
def fixture_network(needs_root):
|
def fixture_network(needs_root):
|
||||||
"""Return the network module. Load it conservatively."""
|
"""Return the network module. Load it conservatively."""
|
||||||
@ -116,7 +117,6 @@ def fixture_pppoe_uuid(network):
|
|||||||
yield from _connection(network, pppoe_settings)
|
yield from _connection(network, pppoe_settings)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.usefixtures('ethernet_uuid', 'wifi_uuid', 'pppoe_uuid')
|
@pytest.mark.usefixtures('ethernet_uuid', 'wifi_uuid', 'pppoe_uuid')
|
||||||
def test_get_connection_list(network):
|
def test_get_connection_list(network):
|
||||||
"""Check that we can get a list of available connections."""
|
"""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]
|
assert 'plinth_test_pppoe' in [x['name'] for x in connections]
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def test_get_connection(network, ethernet_uuid, wifi_uuid):
|
def test_get_connection(network, ethernet_uuid, wifi_uuid):
|
||||||
"""Check that we can get a connection by name."""
|
"""Check that we can get a connection by name."""
|
||||||
connection = network.get_connection(ethernet_uuid)
|
connection = network.get_connection(ethernet_uuid)
|
||||||
|
|||||||
7
setup.py
7
setup.py
@ -268,7 +268,12 @@ setuptools.setup(
|
|||||||
'requests',
|
'requests',
|
||||||
'ruamel.yaml',
|
'ruamel.yaml',
|
||||||
],
|
],
|
||||||
tests_require=['pytest', 'pytest-cov', 'pytest-django'],
|
tests_require=[
|
||||||
|
'pytest',
|
||||||
|
'pytest-cov',
|
||||||
|
'pytest-django',
|
||||||
|
'flake8',
|
||||||
|
],
|
||||||
package_data={
|
package_data={
|
||||||
'': ['templates/*', 'static/*', 'locale/*/LC_MESSAGES/*.[pm]o']
|
'': ['templates/*', 'static/*', 'locale/*/LC_MESSAGES/*.[pm]o']
|
||||||
},
|
},
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user