Skip to content

Commit

Permalink
Put pylint and pylint django into place
Browse files Browse the repository at this point in the history
  • Loading branch information
Pierre-Sassoulas committed Dec 19, 2023
1 parent 511f52b commit 3bfd866
Show file tree
Hide file tree
Showing 11 changed files with 77 additions and 51 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,6 @@ jobs:
coverage run --source=survey --omit=survey/migrations/* ./manage.py test
coverage html
coveralls debug --service=github
- name: pylint
run: |
pre-commit run pylint --all-files
21 changes: 19 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ci:
# skip: [pylint]
ci:
skip: [pylint]

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
Expand Down Expand Up @@ -29,3 +29,20 @@ repos:
- id: prettier
args: [--prose-wrap=always, --print-width=88]
exclude: "survey/static/|dev/templates/|survey/templates/|survey/locale/|survey/tests/"
- repo: local
hooks:
- id: pylint
name: pylint
entry: pylint
language: system
types: [python]
args:
[
"-rn",
"-sn",
"--rcfile=pyproject.toml",
"--django-settings-module=settings",
"--load-plugins=pylint_django",
"--fail-on=I",
]
exclude: "survey/migrations/"
22 changes: 0 additions & 22 deletions .pylintrc
Original file line number Diff line number Diff line change
@@ -1,22 +0,0 @@
[MASTER]
# Python code to execute, usually for sys.path manipulation such as pygtk.require().
init-hook=import sys; sys.path.insert(0, 'survey');sys.path.insert(0, 'venv/lib/python3.7/site-packages/');

[MESSAGES CONTROL]
# I0011 Warning locally suppressed using disable-msg
disable=
I0011,
no-member,
missing-docstring, # We don't want docstring everywhere
C0330, # black handle this
too-few-public-methods, # More harmful than beneficial in django project
too-many-arguments,

ignore=migrations

[BASIC]
# Good variable names which should always be accepted, separated by a comma.
good-names=i,j,k,ex,Run,_,f,e,maxDiff

[FORMAT]
max-line-length=120
36 changes: 34 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ dev = [
"coveralls",
"colorama",
"pylint",
"pylint-django",
"pre-commit"
]
sankey = [
Expand All @@ -59,8 +60,6 @@ sankey = [
[tool.setuptools.dynamic]
dependencies = {file = "requirements.txt"}



[tool.ruff]

line-length = 120
Expand All @@ -78,3 +77,36 @@ select = [
ignore = [
"RUF012", # mutable default values in class attributes
]

[tool.pylint.main]
load-plugins ="pylint_django"

disable=[
# I0011 Warning locally suppressed using disable-msg
"I0011",
"no-member",
"missing-docstring", # We don't want docstring everywhere
"too-few-public-methods", # More harmful than beneficial in django project
"too-many-arguments",
"too-many-instance-attributes",
# TODO Fix
"unspecified-encoding",
"inconsistent-return-statements",
"consider-using-with",
"fixme",
"no-else-return",
"imported-auth-user",
"unused-argument",
"arguments-differ",
"consider-using-f-string",
"too-many-branches",
"redefined-builtin",
"superfluous-parens",
"useless-parent-delegation",
"unused-private-member",
"duplicate-code",
"attribute-defined-outside-init",
]
ignore="migrations"
good-names="i,j,k,ex,Run,_,f,e,maxDiff"
max-line-length = 120
1 change: 1 addition & 0 deletions survey/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

def set_default_settings():
try:
# pylint: disable=import-outside-toplevel
from django.conf import settings

from . import settings as app_settings
Expand Down
1 change: 1 addition & 0 deletions survey/exporter/tex/survey2tex.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ def _additional_analysis(self, survey, latex_file):
latex_file.text += function_(survey)

def treat_question(self, question):
# pylint: disable=too-many-locals
LOGGER.info("Treating, %s %s", question.pk, question.text)
options = self.tconf.get(survey_name=self.survey.name, question_text=question.text)
multiple_charts = options.get("multiple_charts")
Expand Down
9 changes: 3 additions & 6 deletions survey/models/question.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,7 @@ def sorted_answers_cardinality(
The ordering is reversed for same cardinality value so we have aa
before zz."""
# pylint: disable=too-many-locals
cardinality = self.answers_cardinality(
min_cardinality, group_together, group_by_letter_case, group_by_slugify, filter, other_question
)
Expand Down Expand Up @@ -344,20 +345,16 @@ def __add_user_cardinality(
filter,
standardized_filter,
):
found_answer = False
values = [_(settings.USER_DID_NOT_ANSWER)]
for other_answer in other_question.answers.all():
if user is None:
break
if other_answer.response.user == user:
# We suppose there is only a response per user
# Why would you want this info if it is
# possible to answer multiple time ?
found_answer = True
values = other_answer.values
break
if found_answer:
values = other_answer.values
else:
values = [_(settings.USER_DID_NOT_ANSWER)]
for other_value in values:
other_value = self.__get_cardinality_value(
other_value, group_by_letter_case, group_by_slugify, group_together
Expand Down
8 changes: 4 additions & 4 deletions survey/models/response.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
from django.conf import settings

if settings.AUTH_USER_MODEL:
user_model = settings.AUTH_USER_MODEL
UserModel = settings.AUTH_USER_MODEL
else:
user_model = User
UserModel = User
except (ImportError, AttributeError):
user_model = User
UserModel = User


class Response(models.Model):
Expand All @@ -25,7 +25,7 @@ class Response(models.Model):
created = models.DateTimeField(_("Creation date"), auto_now_add=True)
updated = models.DateTimeField(_("Update date"), auto_now=True)
survey = models.ForeignKey(Survey, on_delete=models.CASCADE, verbose_name=_("Survey"), related_name="responses")
user = models.ForeignKey(user_model, on_delete=models.SET_NULL, verbose_name=_("User"), null=True, blank=True)
user = models.ForeignKey(UserModel, on_delete=models.SET_NULL, verbose_name=_("User"), null=True, blank=True)
interview_uuid = models.CharField(_("Interview unique identifier"), max_length=36)

class Meta:
Expand Down
2 changes: 1 addition & 1 deletion survey/tests/base_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def login(self):
"""Log the user in."""
is_logged = self.client.login(username=settings.DEBUG_ADMIN_NAME, password=settings.DEBUG_ADMIN_PASSWORD)
if not is_logged: # pragma: no cover
raise Exception("Login failed for test user! Tests won't work.")
raise ValueError("Login failed for test user! Tests won't work.")

def logout(self):
"""Log the user out."""
Expand Down
23 changes: 10 additions & 13 deletions survey/tests/exporter/tex/test_question2tex_sankey.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,13 @@ def test_other_question_type(self):
q2s = Question2TexSankey(question, other_question=other_question)
self.assertIsNotNone(q2s.tex())


"""
def test_big_ranking_survey(self):
# Creating a big ranking survey with user takes a long time
self.create_big_ranking_survey(with_user=True)
qtext = "How much do you like question {} ?"
from survey.models import Question
q4 = Question.objects.get(text=qtext.format(4))
q5 = Question.objects.get(text=qtext.format(5))
q2tex_sankey = Question2TexSankey(q4, filter=["1"], other_question=q5, group_together={"A": ["2", "3"]})
q2tex_sankey.tex()
"""
# def test_big_ranking_survey(self):
# # Creating a big ranking survey with user takes a long time
# self.create_big_ranking_survey(with_user=True)
# qtext = "How much do you like question {} ?"
# from survey.models import Question
#
# q4 = Question.objects.get(text=qtext.format(4))
# q5 = Question.objects.get(text=qtext.format(5))
# q2tex_sankey = Question2TexSankey(q4, filter=["1"], other_question=q5, group_together={"A": ["2", "3"]})
# q2tex_sankey.tex()
2 changes: 1 addition & 1 deletion survey/views/survey_detail.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def get(self, request, *args, **kwargs):

asset_context = {
# If any of the widgets of the current form has a "date" class, flatpickr will be loaded into the template
"flatpickr": any([field.widget.attrs.get("class") == "date" for _, field in form.fields.items()])
"flatpickr": any(field.widget.attrs.get("class") == "date" for _, field in form.fields.items())
}
context = {
"response_form": form,
Expand Down

0 comments on commit 3bfd866

Please sign in to comment.