Skip to content

Commit

Permalink
Upgrade interpreters, tool, dependencies (#183)
Browse files Browse the repository at this point in the history
* Upgrade python interpreters
* Put ruff into place
* Put pylint and pylint django into place
* Update locale
  • Loading branch information
Pierre-Sassoulas authored Dec 19, 2023
1 parent 41837bc commit 090d6eb
Show file tree
Hide file tree
Showing 35 changed files with 218 additions and 211 deletions.
8 changes: 0 additions & 8 deletions .flake8

This file was deleted.

9 changes: 5 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.8, 3.9, "3.10", "3.11"]
python-version: [3.8, 3.9, "3.10", "3.11", "3.12"]
steps:
- uses: actions/checkout@v2
- name: Python ${{ matrix.python-version }}
Expand All @@ -20,12 +20,10 @@ jobs:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -yqq texlive-latex-base gettext texlive-pictures texlive-latex-extra
sudo apt-get install -yqq texlive-xetex libblas-dev liblapack-dev libatlas-base-dev gfortran
pip3 install -e ".[dev]"
- name: Lint
run: |
pre-commit run --all-files
- name: Test
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand All @@ -34,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
2 changes: 1 addition & 1 deletion .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:
- published

env:
DEFAULT_PYTHON: 3.9
DEFAULT_PYTHON: 3.11

jobs:
release-pypi:
Expand Down
6 changes: 0 additions & 6 deletions .isort.cfg

This file was deleted.

54 changes: 26 additions & 28 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,50 +1,48 @@
#ci:
# skip: [pylint]
ci:
skip: [pylint]

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]
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
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ python manage.py runserver
# Then go to http://localhost:8000/rosetta to translate
python manage.py makemessages --no-obsolete --no-wrap --ignore venv --locale de \
--locale es --locale fr --locale id --locale ja --locale nl --locale pl \
--locale pt --locale ru --locale tr --locale zh
--locale pt --locale ru --locale tr --locale zh --locale gr
git add survey/locale/
...
```
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)
55 changes: 53 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ classifiers = [
"Intended Audience :: Developers",
"License :: OSI Approved :: GNU Affero General Public License v3",
"Operating System :: OS Independent",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Framework :: Django"
]
dynamic = ["dependencies"]
Expand All @@ -50,7 +50,7 @@ dev = [
"coveralls",
"colorama",
"pylint",
"flake8",
"pylint-django",
"pre-commit"
]
sankey = [
Expand All @@ -59,3 +59,54 @@ 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
]

[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
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
15 changes: 6 additions & 9 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 Expand Up @@ -96,19 +97,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
14 changes: 7 additions & 7 deletions survey/locale/de/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2023-03-07 14:14+0000\n"
"POT-Creation-Date: 2023-12-19 14:50+0000\n"
"PO-Revision-Date: 2021-01-23 11:53+0000\n"
"Last-Translator: b' <>'\n"
"Language-Team: LANGUAGE <[email protected]>\n"
Expand Down Expand Up @@ -121,28 +121,28 @@ msgstr "rechts"
msgid "Cannot generate PDF, we need 'xelatex' to be installed."
msgstr "Kann PDF nicht exportieren, denn 'xelatex' muss installiert sein!"

#: survey/exporter/tex/survey2tex.py:79
#: survey/exporter/tex/survey2tex.py:80
msgid "We could not render a chart because the type"
msgstr "Wir konnten eine Grafik nicht erstellen, weil der Typ"

#: survey/exporter/tex/survey2tex.py:82
#: survey/exporter/tex/survey2tex.py:83
msgid "is not a standard type nor the path to an importable valid Question2Tex child class. Choose between 'raw', 'sankey', 'pie', 'cloud', 'square', 'polar' or 'package.path.MyQuestion2TexCustomClass'"
msgstr "kein Standard Typ und auch kein Pfad zu einer importierbaren Question2Tex child class ist. Wähle zwischen 'raw', 'sankey', 'pie', 'cloud', 'square', 'polar' oder 'package.path.MyQuestion2TexCustomClass'"

#: survey/exporter/tex/survey2tex.py:156
#: survey/exporter/tex/survey2tex.py:153
msgid "No questions to display in this survey."
msgstr "In dieser Umfrage sind keine Fragen die angezeigt werden können."

#: survey/exporter/tex/survey2tex.py:186
#: survey/exporter/tex/survey2tex.py:183
msgid "Cannot export multiple PDF, choose only one."
msgstr "Kann nicht mehrere PDFs exportieren. Es kann nur eins ausgewählt werden."

#: survey/exporter/tex/survey2tex.py:195
#: survey/exporter/tex/survey2tex.py:192
#, python-format
msgid "Error during PDF generation: %s"
msgstr "Fehler beim erstellen des PDFs: %s"

#: survey/exporter/tex/survey2tex.py:202
#: survey/exporter/tex/survey2tex.py:199
msgid "Export to PDF"
msgstr "Exportiere als PDF"

Expand Down
Loading

0 comments on commit 090d6eb

Please sign in to comment.