From 49ce436fa4eca16d758278a99939af2946ce2ede Mon Sep 17 00:00:00 2001 From: Andreas Kloeckner Date: Mon, 5 Dec 2016 19:24:15 -0600 Subject: [PATCH 1/2] Run Flake8 during CI --- .gitlab-ci.yml | 9 +++++++++ accounts/__init__.py | 2 +- accounts/apps.py | 2 +- accounts/tests.py | 2 +- accounts/views.py | 2 +- course/__init__.py | 2 +- course/apps.py | 2 +- course/constants.py | 2 +- course/enrollment.py | 2 +- course/flow.py | 2 +- course/page/base.py | 24 ++++++++++++------------ course/page/inline.py | 15 ++++++++------- course/templatetags/coursetags.py | 2 ++ course/tests.py | 2 +- relate/utils.py | 2 +- setup.cfg | 1 + 16 files changed, 43 insertions(+), 30 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 75085bf0..a18a715b 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -33,3 +33,12 @@ Mypy: - python3.5 except: - tags + +Flake8: + script: + - curl -L -O -k https://gitlab.tiker.net/inducer/ci-support/raw/master/prepare-and-run-flake8.sh + - ". ./prepare-and-run-flake8.sh relate course account test bin" + tags: + - python3.5 + except: + - tags diff --git a/accounts/__init__.py b/accounts/__init__.py index d409344b..83198231 100644 --- a/accounts/__init__.py +++ b/accounts/__init__.py @@ -1 +1 @@ -default_app_config = 'accounts.apps.AccountsConfig' \ No newline at end of file +default_app_config = 'accounts.apps.AccountsConfig' diff --git a/accounts/apps.py b/accounts/apps.py index fcad9b4f..b5b68ddd 100644 --- a/accounts/apps.py +++ b/accounts/apps.py @@ -5,4 +5,4 @@ from django.utils.translation import ugettext_lazy as _ class AccountsConfig(AppConfig): name = 'accounts' # for translation of the name of "Accounts" app displayed in admin. - verbose_name = _("Accounts") \ No newline at end of file + verbose_name = _("Accounts") diff --git a/accounts/tests.py b/accounts/tests.py index 7ce503c2..9a30df3b 100644 --- a/accounts/tests.py +++ b/accounts/tests.py @@ -1,3 +1,3 @@ -from django.test import TestCase +from django.test import TestCase # noqa # Create your tests here. diff --git a/accounts/views.py b/accounts/views.py index 91ea44a2..6100593b 100644 --- a/accounts/views.py +++ b/accounts/views.py @@ -1,3 +1,3 @@ -from django.shortcuts import render +from django.shortcuts import render # noqa # Create your views here. diff --git a/course/__init__.py b/course/__init__.py index 1dab58eb..10308e50 100644 --- a/course/__init__.py +++ b/course/__init__.py @@ -1 +1 @@ -default_app_config = 'course.apps.CourseConfig' \ No newline at end of file +default_app_config = 'course.apps.CourseConfig' diff --git a/course/apps.py b/course/apps.py index 02031fe5..58f78b14 100644 --- a/course/apps.py +++ b/course/apps.py @@ -8,4 +8,4 @@ class CourseConfig(AppConfig): verbose_name = _("Course module") def ready(self): - import course.receivers \ No newline at end of file + import course.receivers # noqa diff --git a/course/constants.py b/course/constants.py index f17cd17e..063ab3dd 100644 --- a/course/constants.py +++ b/course/constants.py @@ -73,7 +73,7 @@ PARTICIPATION_STATUS_CHOICES = ( # {{{ participation permission -class participation_permission: +class participation_permission: # noqa edit_course = "edit_course" use_admin_interface = "use_admin_interface" diff --git a/course/enrollment.py b/course/enrollment.py index 6e738655..460dc215 100644 --- a/course/enrollment.py +++ b/course/enrollment.py @@ -67,7 +67,7 @@ from course.utils import course_view, render_course_page from relate.utils import StyledForm, StyledModelForm -from pytools.lex import RE as REBase +from pytools.lex import RE as REBase # noqa # {{{ for mypy diff --git a/course/flow.py b/course/flow.py index 74d6cac8..dfa2b1bf 100644 --- a/course/flow.py +++ b/course/flow.py @@ -2281,7 +2281,7 @@ class FlowPageInteractionEmailForm(StyledForm): self.fields["message"] = forms.CharField( required=True, widget=forms.Textarea, - help_text= string_concat( + help_text=string_concat( _("Your questions about page %s . ") % review_uri, _("Notice that only questions " "for that page will be answered."), diff --git a/course/page/base.py b/course/page/base.py index 741ca898..a5742323 100644 --- a/course/page/base.py +++ b/course/page/base.py @@ -995,20 +995,20 @@ class PageBaseWithHumanTextFeedback(PageBase): msg.send() if (grading_form.cleaned_data["notes"] - and grading_form.cleaned_data["notify_instructor"] - and page_context.flow_session): + and grading_form.cleaned_data["notify_instructor"] + and page_context.flow_session): with translation.override(settings.RELATE_ADMIN_EMAIL_LOCALE): from django.template.loader import render_to_string - from django.urls import reverse - message = render_to_string("course/grade-internal-notes-notify.txt", { - "page_title": self.title(page_context, page_data), - "course": page_context.course, - "participation": page_context.flow_session.participation, - "notes_text": grade_data["notes"], - "flow_session": page_context.flow_session, - "review_uri": page_context.page_uri, - "sender": request.user - }) + message = render_to_string("course/grade-internal-notes-notify.txt", + { + "page_title": self.title(page_context, page_data), + "course": page_context.course, + "participation": page_context.flow_session.participation, + "notes_text": grade_data["notes"], + "flow_session": page_context.flow_session, + "review_uri": page_context.page_uri, + "sender": request.user + }) from django.core.mail import EmailMessage msg = EmailMessage( diff --git a/course/page/inline.py b/course/page/inline.py index caa856ca..d1fb92b3 100644 --- a/course/page/inline.py +++ b/course/page/inline.py @@ -43,7 +43,7 @@ import re # {{{ multiple text question -from crispy_forms.layout import Layout, Field, HTML +from crispy_forms.layout import Layout, HTML from crispy_forms.bootstrap import PrependedAppendedText @@ -459,11 +459,12 @@ class ChoicesAnswer(AnswerBase): def get_correct_answer_text(self, page_context): corr_idx = self.correct_indices()[0] return ("%s%s%s" - % (getattr(self.answers_desc, "prepended_text", "").strip(), - self.process_choice_string( - page_context, self.answers_desc.choices[corr_idx]).lstrip(), - getattr(self.answers_desc, "appended_text", "").strip()) - ) + % ( + getattr(self.answers_desc, "prepended_text", "").strip(), + self.process_choice_string( + page_context, self.answers_desc.choices[corr_idx]).lstrip(), + getattr(self.answers_desc, "appended_text", "").strip()) + ) def get_max_correct_answer_len(self, page_context): return max([len(answer) for answer in @@ -821,7 +822,7 @@ class InlineMultiQuestion(TextQuestionBase, PageBaseWithValue): correctness_list.append(answer_instance.get_correctness( answer[answer_instance.name])) - # The answer doesn't exist for newly added question + # The answer doesn't exist for newly added question # for pages which have been submitted. except KeyError: correctness_list.append(1) diff --git a/course/templatetags/coursetags.py b/course/templatetags/coursetags.py index bda5a5ac..c48bf73d 100644 --- a/course/templatetags/coursetags.py +++ b/course/templatetags/coursetags.py @@ -30,6 +30,7 @@ register = Library() # {{{ get language_code in JS traditional naming format + class GetCurrentLanguageJsFmtNode(Node): def __init__(self, variable): self.variable = variable @@ -39,6 +40,7 @@ class GetCurrentLanguageJsFmtNode(Node): context[self.variable] = js_lang_name return '' + @register.tag("get_current_js_lang_name") def do_get_current_js_lang_name(parser, token): """ diff --git a/course/tests.py b/course/tests.py index 7ce503c2..9a30df3b 100644 --- a/course/tests.py +++ b/course/tests.py @@ -1,3 +1,3 @@ -from django.test import TestCase +from django.test import TestCase # noqa # Create your tests here. diff --git a/relate/utils.py b/relate/utils.py index 52ad19b9..54e15f78 100644 --- a/relate/utils.py +++ b/relate/utils.py @@ -267,7 +267,7 @@ def retry_transaction(f, args, kwargs={}, max_tries=None, serializable=None): sleep(uniform(0.05, 0.2)) -class retry_transaction_decorator(object): +class retry_transaction_decorator(object): # noqa def __init__(self, max_tries=None, serializable=None): # type: (Optional[int], Optional[bool]) -> None self.max_tries = max_tries diff --git a/setup.cfg b/setup.cfg index 77f81d3b..4670a3c1 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,3 +1,4 @@ [flake8] ignore = E126,E127,E128,E123,E226,E241,E242,E265,E402,W503 max-line-length=85 +exclude=course/migrations,accounts/migrations,static,components,course/mdx_mathjax.py -- GitLab From a568b1bc592e5e4a561ad3d6519e7aaa6f82f53d Mon Sep 17 00:00:00 2001 From: Andreas Kloeckner Date: Mon, 5 Dec 2016 19:29:36 -0600 Subject: [PATCH 2/2] Fix flake8 invocation --- .gitlab-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index a18a715b..9406b9af 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -37,7 +37,7 @@ Mypy: Flake8: script: - curl -L -O -k https://gitlab.tiker.net/inducer/ci-support/raw/master/prepare-and-run-flake8.sh - - ". ./prepare-and-run-flake8.sh relate course account test bin" + - ". ./prepare-and-run-flake8.sh relate course accounts test bin" tags: - python3.5 except: -- GitLab