Skip to content

Commit

Permalink
Put ruff into place
Browse files Browse the repository at this point in the history
  • Loading branch information
Pierre-Sassoulas committed Dec 19, 2023
1 parent 760cd38 commit 628959a
Show file tree
Hide file tree
Showing 13 changed files with 54 additions and 71 deletions.
8 changes: 0 additions & 8 deletions .flake8

This file was deleted.

6 changes: 0 additions & 6 deletions .isort.cfg

This file was deleted.

33 changes: 7 additions & 26 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,47 +3,28 @@

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
rev: v4.5.0
hooks:
- id: check-merge-conflict
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-json
- repo: https://github.com/myint/autoflake
rev: v2.0.1
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: "v0.1.8"
hooks:
- id: autoflake
args:
- --in-place
- --remove-all-unused-imports
- --expand-star-imports
- --remove-duplicate-keys
- --remove-unused-variables
- repo: https://github.com/asottile/pyupgrade
rev: v3.3.1
hooks:
- id: pyupgrade
args: [--py36-plus]
- id: ruff
args: ["--fix"]
- repo: https://github.com/psf/black
rev: 23.1.0
rev: 23.12.0
hooks:
- id: black
args: [--line-length, "120"]
- repo: https://github.com/Pierre-Sassoulas/black-disable-checker/
rev: v1.1.3
hooks:
- id: black-disable-checker
- repo: https://github.com/PyCQA/flake8
rev: 6.0.0
hooks:
- id: flake8
additional_dependencies: [flake8-bugbear, flake8-typing-imports==1.12.0]
- repo: https://github.com/PyCQA/isort
rev: 5.12.0
hooks:
- id: isort
- repo: https://github.com/pre-commit/mirrors-prettier
rev: v3.0.0-alpha.6
rev: v3.1.0
hooks:
- id: prettier
args: [--prose-wrap=always, --print-width=88]
Expand Down
4 changes: 2 additions & 2 deletions example_project/manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
import django

print(django.__version__)
except ImportError:
except ImportError as e:
raise ImportError(
"Couldn't import Django. Are you sure it's installed and "
"available on your PYTHONPATH environment variable? Did you "
"forget to activate a virtual environment?"
)
) from e
raise
execute_from_command_line(sys.argv)
21 changes: 20 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ dev = [
"coveralls",
"colorama",
"pylint",
"flake8",
"pre-commit"
]
sankey = [
Expand All @@ -59,3 +58,23 @@ sankey = [

[tool.setuptools.dynamic]
dependencies = {file = "requirements.txt"}



[tool.ruff]

line-length = 120

select = [
"E", # pycodestyle
"F", # pyflakes
"W", # pycodestyle
"B", # bugbear
"I", # isort
"RUF", # ruff
"UP", # pyupgrade
]

ignore = [
"RUF012", # mutable default values in class attributes
]
6 changes: 3 additions & 3 deletions survey/exporter/survey2x.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ def directory(self):
directory_name = f"{self.mime_type.upper()}_DIRECTORY"
try:
self.__directory = str(Path(getattr(settings, directory_name)).absolute())
except AttributeError:
raise ImproperlyConfigured(f"Please define a value for {directory_name} in your settings")
except AttributeError as e:
raise ImproperlyConfigured(f"Please define a value for {directory_name} in your settings") from e
return self.__directory

@property
Expand Down Expand Up @@ -101,4 +101,4 @@ def generate_file(self):
f.write(str(self))
LOGGER.info("Wrote %s in %s", self.mime_type, self.filename)
except OSError as exc:
raise OSError(f"Unable to create <{self.filename}> : {exc} ")
raise OSError(f"Unable to create <{self.filename}> : {exc} ") from exc
2 changes: 1 addition & 1 deletion survey/exporter/tex/question2tex_chart.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def get_results(self):
final_answers.append(answer)
return " {}".format(",\n ".join(final_answers))

def get_pie_options(self): # noqa: C901
def get_pie_options(self):
r"""Return the options of the pie for: \pie[options]{data}"""
options = ""
if self.pos:
Expand Down
2 changes: 1 addition & 1 deletion survey/exporter/tex/question2tex_sankey.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
warnings.warn(
"Cannot import 'sankey', please install the package using"
"the sankey extra. (pip install django-survey-and-report[sankey])"
": '{}'".format(e),
f": '{e}'",
stacklevel=2,
)
SANKEY = False
Expand Down
14 changes: 5 additions & 9 deletions survey/exporter/tex/survey2tex.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,19 +96,15 @@ def treat_question(self, question):
q2tex = q2tex_class(question, latex_label=i, **opts)
question_synthesis += q2tex.tex()
section_title = Question2Tex.html2latex(question.text)
return """
return f"""
\\clearpage{{}}
\\section{{{}}}
\\section{{{section_title}}}
\\label{{sec:{}}}
\\label{{sec:{question.pk}}}
{}
{question_synthesis}
""".format(
section_title,
question.pk,
question_synthesis,
)
"""

@property
def file_modification_time(self):
Expand Down
8 changes: 4 additions & 4 deletions survey/models/answer.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,15 @@ def check_answer_body(self, question, body):
if question.type == Question.INTEGER and body and body != "":
try:
body = int(body)
except ValueError:
except ValueError as e:
msg = "Answer is not an integer"
raise ValidationError(msg)
raise ValidationError(msg) from e
if question.type == Question.FLOAT and body and body != "":
try:
body = float(body)
except ValueError:
except ValueError as e:
msg = "Answer is not a number"
raise ValidationError(msg)
raise ValidationError(msg) from e

def check_answer_for_select(self, choices, body):
answers = []
Expand Down
6 changes: 3 additions & 3 deletions survey/tests/exporter/test_survey2x.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def test_initially_need_update(self):
self.actual_survey2x.need_update(),
"No file exported and the survey "
"contain response : we should need an update. "
"{}".format(self.get_fail_info(self.actual_survey2x)),
f"{self.get_fail_info(self.actual_survey2x)}",
)

@patch.object(Survey2Survey, "file_modification_time", RIGHT_NOW)
Expand All @@ -59,7 +59,7 @@ def test_need_update_after_generation(self):
self.actual_survey2x.need_update(),
"We exported the file and there"
" is no new response, we should not need an update. "
"{}".format(self.get_fail_info(self.actual_survey2x)),
f"{self.get_fail_info(self.actual_survey2x)}",
)

@patch.object(Survey2Survey, "file_modification_time", LONG_TIME_AGO)
Expand All @@ -69,5 +69,5 @@ def test_need_update_after_new_response(self):
self.actual_survey2x.need_update(),
"We exported the file but there"
" is a new response, we should need an update. "
"{}".format(self.get_fail_info(self.actual_survey2x)),
f"{self.get_fail_info(self.actual_survey2x)}",
)
5 changes: 4 additions & 1 deletion survey/tests/management/commands/test_exportresult.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ def test_no_options(self):
call_command("exportresult", "--pdf", survey_id="1")
call_command("exportresult", "--pdf", "--force", survey_id="1")
except XelatexNotInstalled:
warn("xelatex is not installed, some features regarding report generation in PDF were not tested!")
warn(
"xelatex is not installed, some features regarding report generation in PDF were not tested!",
stacklevel=0,
)

def test_handle(self):
"""The custom command export result create the right csv file."""
Expand Down
10 changes: 4 additions & 6 deletions survey/tests/management/test_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,13 @@ def create_big_ranking_survey(self, with_user=False):
def setUp(self):
super().setUp()
self.create_survey()
self.expected_content = """\
self.expected_content = f"""\
user,Aèbc?,Bècd?,Cède?,Dèef?
ps250112,1é,2é,3é,
pierre,,,,
{},1|1a|1b,2|2a|2b,3|3a|3b,
{},1e|1é|1ë,2e|2é|2ë,3e|3é|3ë,
Anonymous,,,,""".format(
self.username, self.other_username
)
{self.username},1|1a|1b,2|2a|2b,3|3a|3b,
{self.other_username},1e|1é|1ë,2e|2é|2ë,3e|3é|3ë,
Anonymous,,,,"""
self.expected_header = ["user", "Aèbc?", "Bècd?", "Cède?", "Dèef?"]
self.conf_dir = Path(HERE, "..", "exporter", "tex")
self.test_conf_path = Path(self.conf_dir, "test_conf.yaml")

0 comments on commit 628959a

Please sign in to comment.