Skip to content

Commit

Permalink
Switching from pylint to ruff.
Browse files Browse the repository at this point in the history
  • Loading branch information
cyface committed Jul 28, 2023
1 parent 6a94353 commit e66401e
Show file tree
Hide file tree
Showing 17 changed files with 533 additions and 617 deletions.
1 change: 1 addition & 0 deletions .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ jobs:
poetry install
- name: Test
run: |
poetry run ruff .
poetry run coverage run manage.py test
poetry run coverage xml
- name: codecov-umbrella
Expand Down
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
build/*
local_settings.py
nosetests.xml
pylint.txt
reports
settings_local.py
settings_local_test.py
Expand Down
1,039 changes: 482 additions & 557 deletions poetry.lock

Large diffs are not rendered by default.

35 changes: 34 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,41 @@ Django = ">2.2"
black = "^23.3"
coverage = {extras = ["toml"], version = "^7.2"}
poetry = "^1.5.1"
pylint = "^2.17.5"
ruff = "^0.0.280"

[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"

[tool.ruff]
extend-exclude = ["migrations"]
ignore = [
"B904",
"DJ001",
"DJ008",
"DJ012",
"E501",
"E722",
"F403",
"F405",
"N806",
"N815",
]
line-length = 88
select = [
"B",
"B9",
"C",
"DJ",
"DTZ",
"E",
"F",
"N",
"UP",
"W",
]
[tool.ruff.isort]
forced-separate = ["django"]

[tool.ruff.mccabe]
max-complexity = 25
2 changes: 0 additions & 2 deletions termsandconditions/admin.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
"""Django Admin Site configuration"""

# pylint: disable=R0904

from django.contrib import admin
from django.utils.translation import gettext as _
from .models import TermsAndConditions, UserTermsAndConditions
Expand Down
4 changes: 1 addition & 3 deletions termsandconditions/apps.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
"""Django Apps Config"""

# pylint: disable=C1001,E0202,W0613

from django.apps import AppConfig
from django.utils.translation import gettext_lazy as _
import logging
Expand All @@ -16,4 +14,4 @@ class TermsAndConditionsConfig(AppConfig):
verbose_name = _("Terms and Conditions")

def ready(self):
import termsandconditions.signals
import termsandconditions.signals # noqa F401
2 changes: 0 additions & 2 deletions termsandconditions/forms.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
"""Django forms for the termsandconditions application"""

# pylint: disable=E1120,W0613

from django import forms
from django.db.models import QuerySet

Expand Down
7 changes: 3 additions & 4 deletions termsandconditions/models.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""Django Models for TermsAndConditions App"""

# pylint: disable=C1001,E0202,W0613
from collections import OrderedDict

from django.db import models
Expand Down Expand Up @@ -53,7 +52,7 @@ class Meta:
)

def __str__(self): # pragma: nocover
return "{0}:{1}-{2:.2f}".format(
return "{}:{}-{:.2f}".format(
self.user.get_username(), self.terms.slug, self.terms.version_number
)

Expand Down Expand Up @@ -99,12 +98,12 @@ class Meta:
verbose_name_plural = _("Terms and Conditions")

def __str__(self): # pragma: nocover
return "{0}-{1:.2f}".format(self.slug, self.version_number)
return f"{self.slug}-{self.version_number:.2f}"

def get_absolute_url(self):
return reverse(
"tc_view_specific_version_page", args=[self.slug, self.version_number]
) # pylint: disable=E1101
)

@staticmethod
def get_active(slug=DEFAULT_TERMS_SLUG):
Expand Down
1 change: 0 additions & 1 deletion termsandconditions/pipeline.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""This file contains functions used as part of a user creation pipeline, such as django-social-auth."""

# pylint: disable=W0613
from urllib.parse import urlunparse, urlparse

from .models import TermsAndConditions
Expand Down
2 changes: 0 additions & 2 deletions termsandconditions/signals.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
""" Signals for Django """

# pylint: disable=C1001,E0202,W0613

import logging
from django.core.cache import cache
from django.dispatch import receiver
Expand Down
18 changes: 8 additions & 10 deletions termsandconditions/tests.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
"""Unit Tests for the termsandconditions module"""

# pylint: disable=R0904, C0103
import time
from importlib import import_module
import logging

Expand Down Expand Up @@ -145,24 +143,24 @@ def test_terms_and_conditions_models(self):
UserTermsAndConditions.objects.create(user=self.user1, terms=self.terms1)
UserTermsAndConditions.objects.create(user=self.user2, terms=self.terms3)

self.assertEquals(1.0, self.user1.userterms.get().terms.version_number)
self.assertEquals(1.5, self.user2.userterms.get().terms.version_number)
self.assertEqual(1.0, self.user1.userterms.get().terms.version_number)
self.assertEqual(1.5, self.user2.userterms.get().terms.version_number)

self.assertEquals("user1", self.terms1.users.all()[0].get_username())
self.assertEqual("user1", self.terms1.users.all()[0].get_username())

# Testing the get_active static method of TermsAndConditions
self.assertEquals(
self.assertEqual(
2.0, TermsAndConditions.get_active(slug="site-terms").version_number
)
self.assertEquals(
self.assertEqual(
1.5, TermsAndConditions.get_active(slug="contrib-terms").version_number
)

# Testing the unicode method of TermsAndConditions
self.assertEquals(
self.assertEqual(
"site-terms-2.00", str(TermsAndConditions.get_active(slug="site-terms"))
)
self.assertEquals(
self.assertEqual(
"contrib-terms-1.50",
str(TermsAndConditions.get_active(slug="contrib-terms")),
)
Expand Down Expand Up @@ -526,7 +524,7 @@ def setUp(self):

def _make_context(self, url):
"""Build Up Context - Used in many tests"""
context = dict()
context = {}
context["request"] = RequestFactory()
context["request"].user = self.user1
context["request"].META = {"PATH_INFO": url}
Expand Down
2 changes: 0 additions & 2 deletions termsandconditions/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
pass-offs to sub-modules, who will have their own urls.py defining actions within.
"""

# pylint: disable=W0401, W0614, E1120

from django.contrib import admin
from django.urls import path, register_converter
from django.views.decorators.cache import never_cache
Expand Down
8 changes: 3 additions & 5 deletions termsandconditions/views.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
"""Django Views for the termsandconditions module"""
from urllib.parse import urlparse

# pylint: disable=E1120,R0901,R0904
from django.contrib.auth.models import User
from django.db import IntegrityError

Expand All @@ -10,7 +8,7 @@
from django.conf import settings
from django.core.mail import send_mail
from django.contrib import messages
from django.http import HttpResponseRedirect, Http404
from django.http import HttpResponseRedirect
from django.utils.translation import gettext as _
from django.views.generic import DetailView, CreateView, FormView
from django.template.loader import get_template
Expand All @@ -23,7 +21,7 @@
DEFAULT_TERMS_IP_HEADER_NAME = "REMOTE_ADDR"


class GetTermsViewMixin(object):
class GetTermsViewMixin:
"""Checks URL parameters for slug and/or version to pull the right TermsAndConditions object"""

def get_terms(self, kwargs):
Expand Down Expand Up @@ -52,7 +50,7 @@ def get_return_to(self, from_dict):
# Django recommends to use this together with the helper above
return iri_to_uri(return_to)

LOGGER.debug("Unsafe URL found: {}".format(return_to))
LOGGER.debug(f"Unsafe URL found: {return_to}")
return "/"

def is_safe_url(self, url):
Expand Down
20 changes: 0 additions & 20 deletions termsandconditions_demo/run_tests.py

This file was deleted.

2 changes: 0 additions & 2 deletions termsandconditions_demo/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,8 @@
local_settings.py, once created, should never be checked into source control
It is ignored by default by .gitignore, so if you don't mess with that, you should be fine.
"""
# pylint: disable=R0801, W0611
import os
import logging
from django import VERSION

# Set the root path of the project so it's not hard coded
PROJECT_ROOT = os.path.abspath(os.path.dirname(__file__))
Expand Down
4 changes: 1 addition & 3 deletions termsandconditions_demo/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
pass-offs to sub-modules, who will have their own paths.py defining actions within.
"""

# pylint: disable=E1120

from django.contrib import admin
from django.conf import settings
from django.urls import path, include
Expand All @@ -29,7 +27,7 @@
# Secure Page
path(
"secure/",
never_cache((login_required(SecureView.as_view()))),
never_cache(login_required(SecureView.as_view())),
name="tc_demo_secure_page",
),
# Secure Page Too
Expand Down
2 changes: 0 additions & 2 deletions termsandconditions_demo/wsgi.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
"""WSGI File that enables Apache/GUnicorn to run Django"""

# pylint: disable=C0103

import os
import sys
from django.core.wsgi import get_wsgi_application
Expand Down

0 comments on commit e66401e

Please sign in to comment.