Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade requirements and pre-commit #345

Merged
merged 1 commit into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
repos:
- repo: https://github.com/psf/black
rev: 24.3.0
rev: 24.10.0
hooks:
- id: black

Expand All @@ -17,26 +17,26 @@ repos:
files: \.html$

- repo: https://github.com/asottile/pyupgrade
rev: v3.15.1
rev: v3.19.0
hooks:
- id: pyupgrade
args: [ "--py310-plus" ]

- repo: https://github.com/rtts/djhtml
rev: '3.0.6'
rev: '3.0.7'
hooks:
- id: djhtml
- id: djcss
- id: djjs

- repo: https://github.com/adamchainz/django-upgrade
rev: 1.16.0
rev: 1.22.2
hooks:
- id: django-upgrade
args: [ --target-version, "4.1" ]

- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: 'v0.3.4'
rev: 'v0.8.2'
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
2 changes: 1 addition & 1 deletion catalog/management/commands/load_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def slugify0(name):


class Command(BaseCommand):
def handle(self, *args: Any, **options: Any) -> None:
def handle(self, *args: Any, **options: Any) -> None: # noqa: PLR0912
with open("csv/programs.json") as f:
programs = json.load(f)

Expand Down
2 changes: 1 addition & 1 deletion catalog/management/parser/build_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def get_or_create_bloc(fac: dict, program: dict, bloc: dict) -> dict:
fac = get_or_create_fac(fac)
program = get_or_create_program(fac, program)

bloc = bloc["val"] if bloc["val"] != "U" else "1"
bloc = bloc["val"] if bloc["val"] != "U" else "1" # type: ignore
if bloc not in program["blocs"]:
program["blocs"][bloc] = {"val": bloc, "courses": {}}
return program["blocs"][bloc]
Expand Down
4 changes: 2 additions & 2 deletions catalog/tests/load_tree_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ def test_fill_twice():
assert course.name == new_course.name


@pytest.mark.slow()
@pytest.mark.network()
@pytest.mark.slow
@pytest.mark.network
def test_load_tree_hit_ulb():
call_command("loadtree", REAL_TREE, hitulb=True)

Expand Down
9 changes: 3 additions & 6 deletions documents/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,14 +258,11 @@ def repair(self, document_id: int) -> int:

@contextlib.contextmanager
def file_as_local(fileobj, prefix="", suffix=""):
tmpfile = tempfile.NamedTemporaryFile(prefix=prefix, suffix=suffix)
tmpfile.write(fileobj.read())
tmpfile.flush()
with tempfile.NamedTemporaryFile(prefix=prefix, suffix=suffix) as tmpfile:
tmpfile.write(fileobj.read())
tmpfile.flush()

try:
yield tmpfile
finally:
tmpfile.close()


@contextlib.contextmanager
Expand Down
8 changes: 4 additions & 4 deletions documents/tests/celery_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def create_doc(name, ext):
return doc


@pytest.mark.slow()
@pytest.mark.slow
def test_add_to_queue():
doc = create_doc("Document name", ".pdf")
with open("documents/tests/files/3pages.pdf", "rb") as fd:
Expand All @@ -63,7 +63,7 @@ def test_add_to_queue():
assert doc.original.path == doc.pdf.path


@pytest.mark.slow()
@pytest.mark.slow
def test_send_duplicate():
test_add_to_queue()

Expand All @@ -80,8 +80,8 @@ def test_send_duplicate():


# TODO : mock unoconv and provide a fake pdf instead
@pytest.mark.unoconv()
@pytest.mark.slow()
@pytest.mark.unoconv
@pytest.mark.slow
def test_send_office():
doc = create_doc("My office doc", ".docx")

Expand Down
2 changes: 1 addition & 1 deletion documents/tests/document_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
pytestmark = pytest.mark.django_db


@pytest.fixture()
@pytest.fixture
def doc():
user = User.objects.create_user(netid="test_user")
doc = Document.objects.create(name="A document", user=user)
Expand Down
4 changes: 2 additions & 2 deletions documents/tests/logic_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
pytestmark = pytest.mark.django_db


@pytest.fixture()
@pytest.fixture
def user():
return User.objects.create_user(netid="test_user")


@pytest.fixture()
@pytest.fixture
def course():
return Course.objects.create(slug="test-t-100")

Expand Down
6 changes: 3 additions & 3 deletions documents/thumbnail.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

import statistics

import fitz
import pymupdf
from PIL import Image, ImageOps


def _get_thumb_from_page(page: fitz.fitz.Page):
def _get_thumb_from_page(page: pymupdf.Page):
pix = page.get_pixmap()
mode = "RGBA" if pix.alpha else "RGB"
img = Image.frombytes(mode, (pix.width, pix.height), pix.samples)
Expand All @@ -18,7 +18,7 @@ def get_thumbnail(
pdf: str | None = None, stream: IO[bytes] | None = None
) -> tuple[int, Image.Image]:
s = stream.read() if stream else None
doc = fitz.open(filename=pdf, stream=s, filetype="pdf")
doc = pymupdf.open(filename=pdf, stream=s, filetype="pdf")

# Iterate on the first 10 pages to find an interesting one to thumbnail
for i in range(min(doc.page_count, 10)):
Expand Down
8 changes: 4 additions & 4 deletions integration/test_webtest.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,27 @@
pytestmark = [pytest.mark.django_db, pytest.mark.webtest]


@pytest.fixture()
@pytest.fixture
def app():
wtm = django_webtest.WebTestMixin()
wtm._patch_settings()
yield django_webtest.DjangoTestApp()
wtm._unpatch_settings()


@pytest.fixture()
@pytest.fixture
def user():
return User.objects.create_user(
netid="nimarcha", email="lol@lol.be", first_name="Nikita", last_name="Marchant"
)


@pytest.fixture()
@pytest.fixture
def tags():
return [Tag.objects.create(name="my tag"), Tag.objects.create(name="my other tag")]


@pytest.fixture()
@pytest.fixture
def tree():
root = Category.objects.create(name="ULB")
science = Category.objects.create(name="science")
Expand Down
6 changes: 3 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ markers = """
postgresql: needs a postgresql database to run
"""

[tool.ruff]
[tool.ruff.lint]
select = [
"F", "E", "W", "YTT", "B", "COM818",
"C4", "DTZ", "T10", "EXE", "ISC",
Expand All @@ -26,17 +26,17 @@ ignore = [
"E501", # Line too long
"B905", # Not available <3.10
"PT011", # `pytest.raises(Exception)` is too broad
"PT004", # Fixture does not return anything
"SIM108", # Use ternary operator
"SIM105", # Use `contextlib.suppress(Alarm)`
"PLR2004", # Magic value used in comparison
"PLR0913", # Too many arguments to function call
"PLR0911", # Too many return statements
"PLC1901", # if x != "" is not the same as if x
"RUF012", # Mutable class attributes should be annotated with `typing.ClassVar`
"SIM103", # Return the condition directly
]

[tool.ruff.per-file-ignores]
[tool.ruff.lint.per-file-ignores]
"__init__.py" = ["F401"] # imported but unused
"www/settings.py" = ["F403"] # import *` used; unable to detect undefined names
"www/test_settings.py" = ["F403"] # import *` used; unable to detect undefined names
Loading
Loading