Bump dependencies, upgrade python fix warnings and apply pre-commit

This commit is contained in:
Gabriel Augendre 2021-12-19 20:40:51 +01:00
parent 4c32917242
commit a064a8f695
11 changed files with 47 additions and 104 deletions

7
.flake8 Normal file
View file

@ -0,0 +1,7 @@
[flake8]
ignore =
# ignore long lines
E501,
# deprecated rule
W503,
A003,

View file

@ -1,19 +1,18 @@
exclude: \.min\.(js|css)(\.map)?$
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.4.0
rev: v4.0.1
hooks:
- id: check-ast
types: [python]
# - id: check-json
# types: [json]
- id: check-json
- id: check-toml
types: [toml]
- id: check-xml
- id: check-yaml
types: [yaml]
args: [--allow-multiple-documents]
# - id: check-xml
# types: [xml]
- id: end-of-file-fixer
- id: check-merge-conflict
- id: debug-statements
- id: detect-private-key
- id: pretty-format-json
args:
- --autofix
@ -22,19 +21,26 @@ repos:
args:
- --markdown-linebreak-ext=md
- repo: https://github.com/timothycrosley/isort
rev: 5.7.0
rev: 5.10.1
hooks:
- id: isort
types: [python]
- repo: https://github.com/psf/black
rev: 20.8b1
rev: 21.12b0
hooks:
- id: black
types: [python]
# - repo: https://gitlab.com/devopshq/gitlab-ci-linter
# rev: v1.0.1
# hooks:
# - id: gitlab-ci-linter
# args:
# - --server
# - https://gitlab.com
- repo: https://github.com/asottile/pyupgrade
rev: v2.29.1
hooks:
- id: pyupgrade
args:
- --py310-plus
- repo: https://github.com/pycqa/flake8
rev: 4.0.1
hooks:
- id: flake8
additional_dependencies:
- flake8-noqa
- flake8-bugbear
- flake8-builtins
- flake8-comprehensions
- flake8-eradicate

View file

@ -1,5 +1,5 @@
## Build venv
FROM python:3.8.8-buster AS venv
FROM python:3.10.1-bullseye AS venv
# https://python-poetry.org/docs/#installation
ENV POETRY_VERSION=1.1.4
@ -31,7 +31,7 @@ RUN git rev-parse HEAD | tee /version
## Beginning of runtime image
FROM python:3.8.8-slim-buster as prod
FROM python:3.10.1-slim-bullseye as prod
RUN echo "Europe/Paris" > /etc/timezone \
&& mkdir /db

View file

@ -138,7 +138,7 @@ class Article(models.Model):
):
related_articles.update(tag.published_articles)
sample_size = min([len(related_articles), 3])
return random.sample(related_articles, sample_size)
return random.sample(list(related_articles), sample_size)
@cached_property
def keywords(self):
@ -151,6 +151,6 @@ class Article(models.Model):
def get_admin_url(self):
content_type = ContentType.objects.get_for_model(self.__class__)
return reverse(
"admin:%s_%s_change" % (content_type.app_label, content_type.model),
f"admin:{content_type.app_label}_{content_type.model}_change",
args=(self.id,),
)

View file

@ -1,4 +1,3 @@
import os
import uuid
import pytest

View file

@ -1,5 +1,4 @@
import pytest
from django.template import Context, Template
from django.test import Client
from django.urls import reverse
from model_bakery import baker

View file

@ -1,6 +1,5 @@
import operator
from functools import reduce
from typing import Dict
from django.conf import settings
from django.contrib.auth.mixins import LoginRequiredMixin
@ -33,10 +32,10 @@ class BaseArticleListView(generic.ListView):
context["previous_page_querystring"] = querystring
return context
def get_additional_querystring_params(self) -> Dict[str, str]:
return dict()
def get_additional_querystring_params(self) -> dict[str, str]:
return {}
def build_querystring(self, initial_queryparams: Dict[str, str]) -> str:
def build_querystring(self, initial_queryparams: dict[str, str]) -> str:
querystring = {
**initial_queryparams,
**self.get_additional_querystring_params(),
@ -84,7 +83,7 @@ class SearchArticlesListView(PublicArticleListView):
)
).distinct()
def get_additional_querystring_params(self) -> Dict[str, str]:
def get_additional_querystring_params(self) -> dict[str, str]:
search_expression = self.request.GET.get("s")
if search_expression:
return {"s": search_expression}

View file

@ -52,7 +52,7 @@ class Attachment(models.Model):
try:
Image.open(self.original_file.path)
except IOError:
except OSError:
return
# Submit job to shortpixel

View file

@ -228,3 +228,5 @@ CSP_MANIFEST_SRC = ("'self'",)
CSP_FONT_SRC = ("'self'",)
CSP_BASE_URI = ("'none'",)
CSP_FORM_ACTION = ("'self'",)
DEFAULT_AUTO_FIELD = "django.db.models.AutoField"

73
poetry.lock generated
View file

@ -43,17 +43,6 @@ python-versions = ">=2.7"
docs = ["sphinx", "jaraco.packaging (>=8.2)", "rst.linker (>=1.9)"]
testing = ["pytest", "pytest-flake8", "pytest-cov", "pytest-black (>=0.3.7)", "pytest-mypy", "pytest-checkdocs (>=2.4)", "pytest-enabler (>=1.0.1)"]
[[package]]
name = "backports.zoneinfo"
version = "0.2.1"
description = "Backport of the standard library zoneinfo module"
category = "main"
optional = false
python-versions = ">=3.6"
[package.extras]
tzdata = ["tzdata"]
[[package]]
name = "beautifulsoup4"
version = "4.10.0"
@ -152,7 +141,6 @@ python-versions = ">=3.8"
[package.dependencies]
asgiref = ">=3.4.1,<4"
"backports.zoneinfo" = {version = "*", markers = "python_version < \"3.9\""}
sqlparse = ">=0.2.2"
tzdata = {version = "*", markers = "sys_platform == \"win32\""}
@ -265,22 +253,6 @@ category = "main"
optional = false
python-versions = ">=3.5"
[[package]]
name = "importlib-metadata"
version = "4.9.0"
description = "Read metadata from Python packages"
category = "main"
optional = false
python-versions = ">=3.7"
[package.dependencies]
zipp = ">=0.5"
[package.extras]
docs = ["sphinx", "jaraco.packaging (>=8.2)", "rst.linker (>=1.9)"]
perf = ["ipython"]
testing = ["pytest (>=6)", "pytest-checkdocs (>=2.4)", "pytest-flake8", "pytest-cov", "pytest-enabler (>=1.0.1)", "packaging", "pep517", "pyfakefs", "flufl.flake8", "pytest-perf (>=0.9.2)", "pytest-black (>=0.3.7)", "pytest-mypy", "importlib-resources (>=1.3)"]
[[package]]
name = "iniconfig"
version = "1.1.1"
@ -311,9 +283,6 @@ category = "main"
optional = false
python-versions = ">=3.6"
[package.dependencies]
importlib-metadata = {version = ">=4.4", markers = "python_version < \"3.10\""}
[package.extras]
testing = ["coverage", "pyyaml"]
@ -768,22 +737,10 @@ python-versions = ">=3.6"
idna = ">=2.0"
multidict = ">=4.0"
[[package]]
name = "zipp"
version = "3.6.0"
description = "Backport of pathlib-compatible object wrapper for zip files"
category = "main"
optional = false
python-versions = ">=3.6"
[package.extras]
docs = ["sphinx", "jaraco.packaging (>=8.2)", "rst.linker (>=1.9)"]
testing = ["pytest (>=4.6)", "pytest-checkdocs (>=2.4)", "pytest-flake8", "pytest-cov", "pytest-enabler (>=1.0.1)", "jaraco.itertools", "func-timeout", "pytest-black (>=0.3.7)", "pytest-mypy"]
[metadata]
lock-version = "1.1"
python-versions = "^3.8"
content-hash = "895eef530799b2b845bcd76139d841342f18373130a24a2513ceccd94767819e"
python-versions = "^3.10"
content-hash = "a32976a9a8d29bebdf5783b5948168194249f40ac76772966d525a4c05e7986d"
[metadata.files]
asgiref = [
@ -802,24 +759,6 @@ attrs = [
{file = "backports.entry_points_selectable-1.1.1-py2.py3-none-any.whl", hash = "sha256:7fceed9532a7aa2bd888654a7314f864a3c16a4e710b34a58cfc0f08114c663b"},
{file = "backports.entry_points_selectable-1.1.1.tar.gz", hash = "sha256:914b21a479fde881635f7af5adc7f6e38d6b274be32269070c53b698c60d5386"},
]
"backports.zoneinfo" = [
{file = "backports.zoneinfo-0.2.1-cp36-cp36m-macosx_10_14_x86_64.whl", hash = "sha256:da6013fd84a690242c310d77ddb8441a559e9cb3d3d59ebac9aca1a57b2e18bc"},
{file = "backports.zoneinfo-0.2.1-cp36-cp36m-manylinux1_i686.whl", hash = "sha256:89a48c0d158a3cc3f654da4c2de1ceba85263fafb861b98b59040a5086259722"},
{file = "backports.zoneinfo-0.2.1-cp36-cp36m-manylinux1_x86_64.whl", hash = "sha256:1c5742112073a563c81f786e77514969acb58649bcdf6cdf0b4ed31a348d4546"},
{file = "backports.zoneinfo-0.2.1-cp36-cp36m-win32.whl", hash = "sha256:e8236383a20872c0cdf5a62b554b27538db7fa1bbec52429d8d106effbaeca08"},
{file = "backports.zoneinfo-0.2.1-cp36-cp36m-win_amd64.whl", hash = "sha256:8439c030a11780786a2002261569bdf362264f605dfa4d65090b64b05c9f79a7"},
{file = "backports.zoneinfo-0.2.1-cp37-cp37m-macosx_10_14_x86_64.whl", hash = "sha256:f04e857b59d9d1ccc39ce2da1021d196e47234873820cbeaad210724b1ee28ac"},
{file = "backports.zoneinfo-0.2.1-cp37-cp37m-manylinux1_i686.whl", hash = "sha256:17746bd546106fa389c51dbea67c8b7c8f0d14b5526a579ca6ccf5ed72c526cf"},
{file = "backports.zoneinfo-0.2.1-cp37-cp37m-manylinux1_x86_64.whl", hash = "sha256:5c144945a7752ca544b4b78c8c41544cdfaf9786f25fe5ffb10e838e19a27570"},
{file = "backports.zoneinfo-0.2.1-cp37-cp37m-win32.whl", hash = "sha256:e55b384612d93be96506932a786bbcde5a2db7a9e6a4bb4bffe8b733f5b9036b"},
{file = "backports.zoneinfo-0.2.1-cp37-cp37m-win_amd64.whl", hash = "sha256:a76b38c52400b762e48131494ba26be363491ac4f9a04c1b7e92483d169f6582"},
{file = "backports.zoneinfo-0.2.1-cp38-cp38-macosx_10_14_x86_64.whl", hash = "sha256:8961c0f32cd0336fb8e8ead11a1f8cd99ec07145ec2931122faaac1c8f7fd987"},
{file = "backports.zoneinfo-0.2.1-cp38-cp38-manylinux1_i686.whl", hash = "sha256:e81b76cace8eda1fca50e345242ba977f9be6ae3945af8d46326d776b4cf78d1"},
{file = "backports.zoneinfo-0.2.1-cp38-cp38-manylinux1_x86_64.whl", hash = "sha256:7b0a64cda4145548fed9efc10322770f929b944ce5cee6c0dfe0c87bf4c0c8c9"},
{file = "backports.zoneinfo-0.2.1-cp38-cp38-win32.whl", hash = "sha256:1b13e654a55cd45672cb54ed12148cd33628f672548f373963b0bff67b217328"},
{file = "backports.zoneinfo-0.2.1-cp38-cp38-win_amd64.whl", hash = "sha256:4a0f800587060bf8880f954dbef70de6c11bbe59c673c3d818921f042f9954a6"},
{file = "backports.zoneinfo-0.2.1.tar.gz", hash = "sha256:fadbfe37f74051d024037f223b8e001611eac868b5c5b06144ef4d8b799862f2"},
]
beautifulsoup4 = [
{file = "beautifulsoup4-4.10.0-py3-none-any.whl", hash = "sha256:9a315ce70049920ea4572a4055bc4bd700c940521d36fc858205ad4fcde149bf"},
{file = "beautifulsoup4-4.10.0.tar.gz", hash = "sha256:c23ad23c521d818955a4151a67d81580319d4bf548d3d49f4223ae041ff98891"},
@ -971,10 +910,6 @@ idna = [
{file = "idna-3.3-py3-none-any.whl", hash = "sha256:84d9dd047ffa80596e0f246e2eab0b391788b0503584e8945f2368256d2735ff"},
{file = "idna-3.3.tar.gz", hash = "sha256:9d643ff0a55b762d5cdb124b8eaa99c66322e2157b69160bc32796e824360e6d"},
]
importlib-metadata = [
{file = "importlib_metadata-4.9.0-py3-none-any.whl", hash = "sha256:e8b45564028bc25f8c99f546616112a6df5de6655893d7eb74c9a99680dc9751"},
{file = "importlib_metadata-4.9.0.tar.gz", hash = "sha256:ee50794eccb0ec340adbc838344ebb9a6ff2bcba78f752d31fc716497e2149d6"},
]
iniconfig = [
{file = "iniconfig-1.1.1-py2.py3-none-any.whl", hash = "sha256:011e24c64b7f47f6ebd835bb12a743f2fbe9a26d4cecaa7f53bc4f35ee9da8b3"},
{file = "iniconfig-1.1.1.tar.gz", hash = "sha256:bc3af051d7d14b2ee5ef9969666def0cd1a000e121eaea580d4a313df4b37f32"},
@ -1483,7 +1418,3 @@ yarl = [
{file = "yarl-1.7.2-cp39-cp39-win_amd64.whl", hash = "sha256:797c2c412b04403d2da075fb93c123df35239cd7b4cc4e0cd9e5839b73f52c58"},
{file = "yarl-1.7.2.tar.gz", hash = "sha256:45399b46d60c253327a460e99856752009fcee5f5d3c80b2f7c0cae1c38d56dd"},
]
zipp = [
{file = "zipp-3.6.0-py3-none-any.whl", hash = "sha256:9fe5ea21568a0a70e50f273397638d39b03353731e6cbbb3fd8502a33fec40bc"},
{file = "zipp-3.6.0.tar.gz", hash = "sha256:71c644c5369f4a6e07636f0aa966270449561fcea2e3d6747b8d23efaa9d7832"},
]

View file

@ -25,7 +25,7 @@ authors = ["Gabriel Augendre <gabriel@augendre.info>"]
license = "GPLv3"
[tool.poetry.dependencies]
python = "^3.8"
python = "^3.10"
django = "^4.0"
markdown = "^3.2"
gunicorn = "^20.0"