Skip to content

Commit

Permalink
Merge pull request #498 from digitalfabrik/feature/add_pylint
Browse files Browse the repository at this point in the history
Add pylint, black & sort imports
  • Loading branch information
MizukiTemma committed Oct 4, 2023
2 parents 1b290b4 + 425fed2 commit 18e1685
Show file tree
Hide file tree
Showing 72 changed files with 371 additions and 330 deletions.
13 changes: 13 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,16 @@ jobs:
paths:
- lunes_cms/locale/de/LC_MESSAGES/django.mo
- lunes_cms/locale/de/LC_MESSAGES/djangojs.mo
pylint:
docker:
- image: "cimg/python:3.9"
steps:
- checkout
- attach_workspace:
at: .
- run:
name: Run pylint
command: ./tools/pylint.sh
setup-test-reporter:
docker:
- image: cimg/base:stable
Expand Down Expand Up @@ -355,6 +365,9 @@ workflows:
filters:
branches:
ignore: main
- pylint:
requires:
- install
- test:
requires:
- compile-translations
Expand Down
3 changes: 2 additions & 1 deletion .circleci/scripts/create_release.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#!/usr/bin/env python3

import os
import argparse
import mimetypes
import os

import requests


Expand Down
4 changes: 2 additions & 2 deletions .circleci/scripts/get_access_token.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#!/usr/bin/env python3

import os
from base64 import b64decode
from datetime import datetime, timedelta

import os
import requests
import jwt
import requests


def main():
Expand Down
99 changes: 15 additions & 84 deletions .pylintrc
Original file line number Diff line number Diff line change
@@ -1,87 +1,18 @@
[MASTER]

disable=print-statement,
parameter-unpacking,
unpacking-in-except,
old-raise-syntax,
backtick,
long-suffix,
old-ne-operator,
old-octal-literal,
import-star-module-level,
non-ascii-bytes-literal,
raw-checker-failed,
bad-inline-option,
locally-disabled,
file-ignored,
suppressed-message,
useless-suppression,
deprecated-pragma,
use-symbolic-message-instead,
apply-builtin,
basestring-builtin,
buffer-builtin,
cmp-builtin,
coerce-builtin,
execfile-builtin,
file-builtin,
long-builtin,
raw_input-builtin,
reduce-builtin,
standarderror-builtin,
unicode-builtin,
xrange-builtin,
coerce-method,
delslice-method,
getslice-method,
setslice-method,
no-absolute-import,
old-division,
dict-iter-method,
dict-view-method,
next-method-called,
metaclass-assignment,
indexing-exception,
raising-string,
reload-builtin,
oct-method,
hex-method,
nonzero-method,
cmp-method,
input-builtin,
round-builtin,
intern-builtin,
unichr-builtin,
map-builtin-not-iterating,
zip-builtin-not-iterating,
range-builtin-not-iterating,
filter-builtin-not-iterating,
using-cmp-argument,
eq-without-hash,
div-method,
idiv-method,
rdiv-method,
exception-message-attribute,
invalid-str-codec,
sys-max-int,
bad-python3-import,
deprecated-string-function,
deprecated-str-translate-call,
deprecated-itertools-function,
deprecated-types-field,
next-method-defined,
dict-items-not-iterating,
dict-keys-not-iterating,
dict-values-not-iterating,
deprecated-operator-function,
deprecated-urllib-function,
xreadlines-attribute,
deprecated-sys-function,
exception-escape,
comprehension-escape,
missing-module-docstring,
disable=missing-module-docstring,
invalid-name,
fixme,
similarities,
format,
no-member
no-member,
line-too-long,
unused-argument,
too-few-public-methods,
too-many-ancestors,
duplicate-code,
missing-function-docstring,
consider-using-with,
arguments-differ,
empty-docstring,
raise-missing-from,
property-with-parameters

enable = useless-suppression
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
[![PyPi](https://img.shields.io/pypi/v/lunes-cms.svg)](https://pypi.org/project/lunes-cms/)
[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
[![Pylint](https://img.shields.io/badge/pylint-10.00-brightgreen)](https://www.pylint.org/)

# Lunes CMS
[![Logo](.github/logo.png) Lunes - Vocabulary for your profession.](https://www.lunes.app)
Expand Down
10 changes: 8 additions & 2 deletions docs/src/code-style-guidelines.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,20 @@ We use the `black <https://github.com/psf/black>`_ coding style, a flavour of `P
We use a `pre-commit-hook <https://pre-commit.com/>`_ to apply this style before committing, so you don't have to bother about formatting.
Just code how you feel comfortable and let the tool do the work for you (see :ref:`pre-commit-hooks`).

Run black manually by starting the virtual environment and then:
If you want to apply the formatting without committing, use our developer tool :github-source:`tools/black.sh`::

black .
./tools/black.sh


.. _pylint:

Linting
-------

In addition to black, we use pylint to check the code for semantic correctness.
Run pylint with our developer tool :github-source:`tools/pylint.sh`::

./tools/pylint.sh

When you think a warning is a false positive, add a comment before the specific line::

Expand Down
7 changes: 3 additions & 4 deletions docs/src/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,19 @@

# -- Path setup --------------------------------------------------------------

import importlib
import inspect

# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
#
import os
import sys
import inspect
import importlib

from datetime import date

from django import VERSION as django_version


# Append project source directory to path environment variable
sys.path.append(os.path.abspath(".."))
# Append sphinx source directory to path environment variable to allow documentation for this file
Expand Down
5 changes: 5 additions & 0 deletions docs/src/continous-integration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@ black

This job executes ``black --check .``, which checks whether the code matches the :ref:`black-code-style` code style.

pylint
------

This job executes ``pylint_runner``, which checks whether the :ref:`pylint` throws any errors or warnings.

shellcheck/check
----------------

Expand Down
1 change: 1 addition & 0 deletions lunes_cms/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
[![Documentation Status](https://readthedocs.org/projects/lunes-cms/badge/?version=latest)](https://lunes-cms.readthedocs.io/en/latest/?badge=latest)
[![License](https://img.shields.io/github/license/digitalfabrik/lunes-cms)](https://opensource.org/licenses/Apache-2.0)
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
[![Pylint](https://img.shields.io/badge/pylint-10.00-brightgreen)](https://www.pylint.org/)

# Lunes CMS

Expand Down
10 changes: 4 additions & 6 deletions lunes_cms/api/permissions.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
from django.core.exceptions import PermissionDenied
from django.db.models import Q
from django.utils.timezone import now

from rest_framework import permissions

from ..cms.models import GroupAPIKey
from .utils import get_key


class VerifyGroupKey(permissions.AllowAny):
"""Simple permissions class that blocks
"""
Simple permissions class that blocks
requests if no valid API-Token is delivered.
Inherits from `permissions.AllowAny`.
"""

def has_permission(self, request, view):
"""Checks whether a valid API-Key is send
"""
Checks whether a valid API-Key is send
by the user in the authorization header
:param request: http request
Expand Down
1 change: 0 additions & 1 deletion lunes_cms/api/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"""
from django.urls import include, path


#: The namespace for this URL config (see :attr:`django.urls.ResolverMatch.app_name`)
app_name = "api"

Expand Down
3 changes: 1 addition & 2 deletions lunes_cms/api/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

from django.core.exceptions import PermissionDenied
from django.db.models import Count, Q

from rest_framework import routers

from ..cms.models import Discipline, GroupAPIKey
Expand Down Expand Up @@ -38,7 +37,7 @@ def get_key(request, keyword="Api-Key"):
if not authorization:
return None
try:
_, key = authorization.split("{} ".format(keyword))
_, key = authorization.split(f"{keyword} ")
except ValueError:
key = None
return key
Expand Down
2 changes: 1 addition & 1 deletion lunes_cms/api/v1/serializers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@
from .document_serializer import DocumentSerializer
from .feedback_serializer import FeedbackSerializer
from .group_serializer import GroupSerializer
from .training_set_serializer import TrainingSetSerializer
from .sponsor_serializer import SponsorSerializer
from .training_set_serializer import TrainingSetSerializer
11 changes: 10 additions & 1 deletion lunes_cms/api/v1/serializers/document_image_list_serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@ class DocumentImageListSerializer(serializers.ListSerializer):
`serializers.ListSerializer`.
"""

def update(self, instance, validated_data):
raise NotImplementedError(
"Serializers with many=True do not support multiple update by "
"default, only multiple create. For updates it is unclear how to "
"deal with insertions and deletions. If you need to support "
"multiple update, use a `ListSerializer` class and override "
"`.update()` so you can specify the behavior exactly."
)

def to_representation(self, data):
"""
Overwrite django built-in function to only deliver
Expand All @@ -18,4 +27,4 @@ def to_representation(self, data):
:rtype: dict
"""
data = data.filter(confirmed=True)
return super(DocumentImageListSerializer, self).to_representation(data)
return super().to_representation(data)
2 changes: 1 addition & 1 deletion lunes_cms/api/v1/serializers/feedback_serializer.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from rest_framework import serializers
from django.contrib.contenttypes.models import ContentType
from django.utils.translation import ugettext_lazy as _
from rest_framework import serializers

from ....cms.models import Feedback

Expand Down
7 changes: 1 addition & 6 deletions lunes_cms/api/v1/urls.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
"""
URL patterns for the first version of the Lunes API
"""
from django.urls import include, path, re_path

from rest_framework import permissions
from rest_framework.versioning import NamespaceVersioning

from django.urls import include, path
from drf_spectacular.views import SpectacularAPIView, SpectacularSwaggerView

from ..utils import OptionalSlashRouter
from . import views


#: The namespace for this URL config (see :attr:`django.urls.ResolverMatch.app_name`)
app_name = "v1"

Expand Down
6 changes: 3 additions & 3 deletions lunes_cms/api/v1/views/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
from .discipline_viewset import DisciplineViewSet
from .document_by_id_viewset import DocumentByIdViewSet
from .document_viewset import DocumentViewSet
from .feedback_viewset import CreateFeedbackViewSet
from .group_viewset import GroupViewSet
from .training_set_viewset import TrainingSetViewSet
from .sponsors_viewset import SponsorsViewSet
from .training_set_by_id_viewset import TrainingSetByIdViewSet
from .training_set_viewset import TrainingSetViewSet
from .word_viewset import WordViewSet
from .feedback_viewset import CreateFeedbackViewSet
from .sponsors_viewset import SponsorsViewSet
4 changes: 2 additions & 2 deletions lunes_cms/api/v1/views/discipline_filtered_viewset.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

from ....cms.models import Discipline
from ...utils import (
get_filtered_discipline_queryset,
check_group_object_permissions,
get_discipline_by_group_queryset,
get_filtered_discipline_queryset,
get_overview_discipline_queryset,
check_group_object_permissions,
)
from ..serializers import DisciplineSerializer

Expand Down
4 changes: 1 addition & 3 deletions lunes_cms/api/v1/views/discipline_viewset.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
from django.core.exceptions import PermissionDenied
from django.db.models import Q, Count

from django.db.models import Count, Q
from rest_framework import viewsets

from ....cms.models import Discipline, GroupAPIKey
Expand Down
3 changes: 1 addition & 2 deletions lunes_cms/api/v1/views/document_by_id_viewset.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from rest_framework import viewsets
from rest_framework.authentication import SessionAuthentication, BasicAuthentication
from rest_framework.authentication import BasicAuthentication, SessionAuthentication
from rest_framework.permissions import IsAuthenticated

from ....cms.models import Document
Expand Down Expand Up @@ -30,6 +30,5 @@ def get_queryset(self):
"""
if getattr(self, "swagger_fake_view", False):
return Document.objects.none()
user = self.request.user
queryset = Document.objects.filter(id=self.kwargs["document_id"])
return queryset

0 comments on commit 18e1685

Please sign in to comment.