From fe469148e155024efa98821f5abd01fdd81ef4d4 Mon Sep 17 00:00:00 2001
From: janmax <j.michal@stud.uni-goettingen.de>
Date: Wed, 13 Dec 2017 23:31:30 +0100
Subject: [PATCH] The previously introduced methods do not comply with pep8

* removing prospector as it is not compatible with latest version of flake8
* introducting a new CI job that runs flake8 and actually fails if there are any errors
---
 .gitlab-ci.yml                   |  4 ++--
 .pre-commit-config.yaml          |  7 -------
 core/grady_speak.py              | 23 -----------------------
 core/models.py                   | 25 +++++++++++++------------
 pre-commit-scripts/prospector.sh |  8 --------
 requirements.dev.txt             |  2 +-
 6 files changed, 16 insertions(+), 53 deletions(-)
 delete mode 100644 core/grady_speak.py
 delete mode 100755 pre-commit-scripts/prospector.sh

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 3ed4bc5b..663ce9c1 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -34,10 +34,10 @@ test_pytest:
                 paths:
                         - .coverage
 
-test_prospector:
+test_flake8:
         <<: *test_definition_backend
         script:
-                - prospector --uses django || exit 0
+                - flake8 --exclude=migrations --ignore=N802 core
 
 # ----------------------------- Frontend subsection -------------------------- #
 .test_template_frontend: &test_definition_frontend
diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
index e63378ac..053bd657 100644
--- a/.pre-commit-config.yaml
+++ b/.pre-commit-config.yaml
@@ -12,10 +12,3 @@
     args:
     - requirements.txt
     - requirements.dev.txt
-- repo: local
-  hooks:
-  - id: prospector
-    name: prospector
-    entry: ./pre-commit-scripts/prospector.sh
-    language: script
-    types: [python]
diff --git a/core/grady_speak.py b/core/grady_speak.py
deleted file mode 100644
index 08b6242f..00000000
--- a/core/grady_speak.py
+++ /dev/null
@@ -1,23 +0,0 @@
-grady_says = [
-    "Now let's see if we can improve this with a little water, sir.",
-    "Won't keep you a moment, sir.",
-    "Grady, sir. Delbert Grady.",
-    "Yes, sir.",
-    "That's right, sir.",
-    "Why no, sir. I don't believe so.",
-    "Ah ha, it's coming off now, sir.",
-    "Why no, sir. I don't believe so.",
-    "Yes, sir.  I have a wife and two daughters, sir.",
-    "Oh, they're somewhere around.  I'm not quite sure at the moment, sir.",
-    "That's strange, sir.  I don't have any recollection of that at all.",
-    "I'm sorry to differ with you, sir, but you are the caretaker.",
-    "You have always been the caretaker, I should know, sir.",
-    "I've always been here.",
-    "Indeed, he is, Mr. Torrance. Avery willful boy. ",
-    "A rather naughty boy, if I may be so bold, sir.",
-    "Perhaps they need a good talking to, if you don't mind my saying so. Perhaps a bit more.",
-    "My girls, sir, they didn't care for the Overlook at first.",
-    "One of them actually stole a packet of matches and tried to burn it down.",
-    "But I corrected them, sir.",
-    "And when my wife tried to prevent me from doing my duty... I corrected her.",
-]
diff --git a/core/models.py b/core/models.py
index 30a240f2..966b647d 100644
--- a/core/models.py
+++ b/core/models.py
@@ -13,9 +13,8 @@ from typing import Dict, Union
 from django.contrib.auth import get_user_model
 from django.contrib.auth.models import AbstractUser
 from django.db import models
-from django.db.models import Value as V
 from django.db.models import (BooleanField, Case, Count, F, IntegerField, Q,
-                              QuerySet, Sum, When)
+                              QuerySet, Sum, Value, When)
 from django.db.models.functions import Coalesce
 
 
@@ -125,7 +124,7 @@ class SubmissionType(models.Model):
                         When(
                             Q(submissions__feedback__isnull=False) &
                             Q(submissions__feedback__status=Feedback.ACCEPTED),
-                            then=V(1)), output_field=IntegerField(),
+                            then=Value(1)), output_field=IntegerField(),
                     )
                 )
             ).annotate(
@@ -230,11 +229,12 @@ class Student(models.Model):
             the annotated QuerySet as described above.
         """
         return cls.objects.annotate(
-            overall_score=Coalesce(Sum('submissions__feedback__score'), V(0)),
+            overall_score=Coalesce(Sum('submissions__feedback__score'),
+                                   Value(0)),
         ).annotate(
             done=Case(
-                When(exam__pass_score__lt=F('overall_score'), then=V(1)),
-                default=V(0),
+                When(exam__pass_score__lt=F('overall_score'), then=Value(1)),
+                default=Value(0),
                 output_field=BooleanField()
             )
         )
@@ -362,12 +362,12 @@ class Submission(models.Model):
 
         candidates = cls.objects.filter(
             (
-                Q(feedback__isnull=True)
-                | Q(feedback__origin=Feedback.DID_NOT_COMPILE)
-                | Q(feedback__origin=Feedback.COULD_NOT_LINK)
-                | Q(feedback__origin=Feedback.FAILED_UNIT_TESTS)
-            )
-            & ~Q(feedback__of_tutor=tutor)
+                Q(feedback__isnull=True) |
+                Q(feedback__origin=Feedback.DID_NOT_COMPILE) |
+                Q(feedback__origin=Feedback.COULD_NOT_LINK) |
+                Q(feedback__origin=Feedback.FAILED_UNIT_TESTS)
+            ) &
+            ~Q(feedback__of_tutor=tutor)
         )
 
         # we want a submission of a specific type
@@ -542,6 +542,7 @@ class Feedback(models.Model):
         )
         return tutor_feedback[0] if tutor_feedback else None
 
+    @classmethod
     def tutor_assigned_feedback(cls, user: Union[Tutor, Reviewer]):
         """Gets all feedback that is assigned to the tutor including
         all status cases.
diff --git a/pre-commit-scripts/prospector.sh b/pre-commit-scripts/prospector.sh
deleted file mode 100755
index f6d218ff..00000000
--- a/pre-commit-scripts/prospector.sh
+++ /dev/null
@@ -1,8 +0,0 @@
-#!/bin/bash
-
-diff_files="$(git diff  --cached --name-only --relative --diff-filter=AM)"
-if [ -n "$diff_files" ]; then
-	prospector --uses django $diff_files
-else
-	exit 0
-fi
diff --git a/requirements.dev.txt b/requirements.dev.txt
index 63b69b7d..eaa909a4 100644
--- a/requirements.dev.txt
+++ b/requirements.dev.txt
@@ -1,4 +1,4 @@
+flake8~=3.5.0
 pre-commit~=1.4.1
-prospector~=0.12.7
 pytest-cov~=2.5.1
 pytest-django~=3.1.2
-- 
GitLab