Skip to content

Commit

Permalink
Do some dependency cleanup & add poetry pre-commit hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
matti-lamppu committed Nov 18, 2024
1 parent 53729f3 commit 286b8d0
Show file tree
Hide file tree
Showing 7 changed files with 189 additions and 294 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
name: "Run tests and SonarCloud scan"
runs-on: ubuntu-latest
env:
POETRY_VERSION: 1.7.1
POETRY_VERSION: 1.8.4

services:
postgres:
Expand Down
15 changes: 14 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ ci:
skip:
# Cannot access poetry on pre-commit.ci
- python-safety-dependencies-check
- poetry-lock

repos:

Expand Down Expand Up @@ -32,4 +33,16 @@ repos:
hooks:
- id: python-safety-dependencies-check
files: pyproject.toml
args: ["--ignore=64396,64459"]
# Ignore some issues in sub-dependencies:
# - https://data.safetycli.com/v/64396/97c/ | django-helusers -> python-jose -> ecdsa
# - https://data.safetycli.com/v/64459/97c/ | django-helusers -> python-jose -> ecdsa
# - https://data.safetycli.com/v/70612/97c/ | django-jinja -> jinja2
# - https://data.safetycli.com/v/70715/97c/ | django-helusers -> python-jose
# - https://data.safetycli.com/v/70716/97c/ | django-helusers -> python-jose
args: ["--ignore=64396,64459,70612,70715,70716"]

- repo: https://github.com/python-poetry/poetry
rev: 1.8.4
hooks:
- id: poetry-check
- id: poetry-lock
4 changes: 2 additions & 2 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ FROM base AS builder
# Old variables need to be redeclared after "from" statements so that defaults can be used.
ARG PROJECT_ROOT=/tvp
ARG VENV_ROOT=$PROJECT_ROOT/venv
ARG DEPS=main
ARG DEPS=main,admin,celery

# Install build dependencies
# - build-essential: for building uWSGI
Expand All @@ -72,7 +72,7 @@ ENV POETRY_VIRTUALENVS_IN_PROJECT=true
ENV POETRY_INSTALLER_PARALLEL=false

# Install poetry.
RUN curl -sSL https://install.python-poetry.org | POETRY_VERSION=1.7.1 python -
RUN curl -sSL https://install.python-poetry.org | POETRY_VERSION=1.8.4 python -

# Copy poetry files.
COPY poetry.lock pyproject.toml /
Expand Down
347 changes: 125 additions & 222 deletions poetry.lock

Large diffs are not rendered by default.

65 changes: 29 additions & 36 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[tool.poetry]
name = "Tilavarauspalvelu"
version = "0"
description = ""
description = "Backend for the new space and resource reservation platform for the City of Helsinki."
authors = []
classifiers = [
# This prevents accidentally running 'poetry publish'
Expand All @@ -10,83 +10,76 @@ classifiers = [

[tool.poetry.dependencies]
python = ">=3.12,<3.13"
celery = { extras = ["redis"], version = "5.4.0" }
certifi = "2024.8.30"
cryptography = "43.0.3"
Django = "5.1.3"
django-admin-data-views = "0.4.2"
django-admin-extra-buttons = "1.6.0"
django-admin-rangefilter = "0.13.2"
django-admin-sortable2 = "2.2.3"
django-auditlog = "3.0.0"
django-celery-beat = "2.7.0"
django-celery-results = "2.5.1"
django-cors-headers = "4.6.0"
django-enumfields2 = "3.0.2"
django-environ = "0.11.2"
django-environment-config = { version = "0.2.2", extras = ["db"] }
django-extensions = "3.2.3"
django-extra-fields = "3.0.2"
django-filter = "24.3"
django-graphql-jwt = "0.4.0"
django-health-check = "3.18.3"
django-helusers = "0.13.0"
django-import-export = "4.2.1"
django-jinja = "2.11.0"
django-lookup-property = "0.1.7"
django-modeltranslation = "0.19.10"
django-more-admin-filters = "1.8"
django-modeltranslation = "0.19.11"
django-mptt = "0.16.0"
django-recurrence = "1.11.1"
django-redis = "5.4.0"
django-subforms = "0.3.1"
django-tinymce = "4.1.0"
djangorestframework = "3.15.2"
easy-thumbnails = "2.10"
elasticsearch-django = "8.5.2"
graphene-django = "3.2.2"
graphene-django-extensions = "0.4.8"
graphene-django-extensions = "0.4.9"
helsinki-profile-gdpr-api = "0.2.0"
hiredis = "3.0.0"
icalendar = "6.0.1"
jinja2 = "3.1.4"
mjml-python = "1.3.4"
psycopg2 = "2.9.10"
python-dateutil = "2.9.0.post0"
pyyaml = "6.0.2"
redis = "5.2.0"
redis = { version = "5.2.0", extras = ["hiredis"] }
sentry-sdk = "2.18.0"
social-auth-app-django = "5.4.2"
# Skip installation on Windows as uWSGI does not support it without Cygwin.
uWSGI = { version = "2.0.28", markers = "sys_platform != 'win32'" }
whitenoise = "6.8.2"
xhtml2pdf = "0.2.16"

[tool.poetry.dependencies.uWSGI]
version = "2.0.23"
# Skip installation on Windows as uWSGI does not support it without Cygwin.
# Windows users should use WSL for their local development virtualenv, but can
# still create another virtualenv in Windows without uWSGI for pre-commit hooks.
markers = "sys_platform != 'win32'"
[tool.poetry.group.admin.dependencies]
# Dependencies related to the admin panel or other "administrative" tasks.
django-admin-data-views = "0.4.2"
django-admin-extra-buttons = "1.6.0"
django-admin-rangefilter = "0.13.2"
django-admin-sortable2 = "2.2.4"
django-extensions = "3.2.3"
django-import-export = "4.2.1"
django-more-admin-filters = "1.9"
django-subforms = "0.3.1"
django-tinymce = "4.1.0"

[tool.poetry.group.celery.dependencies]
# Dependencies related to Celery tasks.
celery = { version = "5.4.0", extras = ["redis"] }
django-celery-beat = "2.7.0"
django-celery-results = "2.5.1"

[tool.poetry.group.test.dependencies]
# Dependencies only required for running tests.
django-debug-toolbar = "4.4.6" # django-graphiql-debug-toolbar 0.2.0 breaks with django-debug-toolbar 4.4.6
django-graphiql-debug-toolbar = "0.2.0"
factory-boy = "3.3.1"
faker = "30.8.2"
faker = "33.0.0"
freezegun = "1.5.1"
html2text = "2024.2.26"
polib = "1.2.0"
pyinstrument = "5.0.0"
pypdf2 = "3.0.1"
pytest = "8.3.3"
pytest-cov = "6.0.0"
pytest-django = "4.9.0"
pytest-xdist = "3.6.1"
requests-mock = "1.12.1"
html2text = "2024.2.26"

[tool.poetry.group.lint.dependencies]
# Dependencies only required for linting.
pre-commit = "4.0.1"
ruff = "0.7.3"
ruff = "0.7.4"
ruff-lsp = "0.0.58"
pyinstrument = "5.0.0"

[tool.poetry.plugins.pytest11]
tilavarauspalvelu = "tests.plugins"
Expand Down
47 changes: 17 additions & 30 deletions tilavarauspalvelu/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
from django.utils.functional import classproperty
from django.utils.translation import gettext_lazy as _
from django.utils.translation import pgettext_lazy
from enumfields import Enum

from tilavarauspalvelu.typing import permission

Expand Down Expand Up @@ -277,35 +276,23 @@ def text_path(self) -> str:
return f"email/text/{self.value}.jinja"


class HaukiResourceState(Enum):
OPEN = "open"
CLOSED = "closed"
UNDEFINED = "undefined"
SELF_SERVICE = "self_service"
WITH_KEY = "with_key"
WITH_RESERVATION = "with_reservation"
OPEN_AND_RESERVABLE = "open_and_reservable"
WITH_KEY_AND_RESERVATION = "with_key_and_reservation"
ENTER_ONLY = "enter_only"
EXIT_ONLY = "exit_only"
WEATHER_PERMITTING = "weather_permitting"
NOT_IN_USE = "not_in_use"
MAINTENANCE = "maintenance"

class Labels:
OPEN = pgettext_lazy("HaukiResourceState", "Open")
CLOSED = pgettext_lazy("HaukiResourceState", "Closed")
UNDEFINED = pgettext_lazy("HaukiResourceState", "Undefined")
SELF_SERVICE = pgettext_lazy("HaukiResourceState", "Self service")
WITH_KEY = pgettext_lazy("HaukiResourceState", "With key")
WITH_RESERVATION = pgettext_lazy("HaukiResourceState", "With reservation")
OPEN_AND_RESERVABLE = pgettext_lazy("HaukiResourceState", "Open and reservable")
WITH_KEY_AND_RESERVATION = pgettext_lazy("HaukiResourceState", "With key and reservation")
ENTER_ONLY = pgettext_lazy("HaukiResourceState", "Enter only")
EXIT_ONLY = pgettext_lazy("HaukiResourceState", "Exit only")
WEATHER_PERMITTING = pgettext_lazy("HaukiResourceState", "Weather permitting")
NOT_IN_USE = pgettext_lazy("HaukiResourceState", "Not in use")
MAINTENANCE = pgettext_lazy("HaukiResourceState", "Maintenance")
class HaukiResourceState(models.TextChoices):
OPEN = "open", pgettext_lazy("HaukiResourceState", "Open")
CLOSED = "closed", pgettext_lazy("HaukiResourceState", "Closed")
UNDEFINED = "undefined", pgettext_lazy("HaukiResourceState", "Undefined")
SELF_SERVICE = "self_service", pgettext_lazy("HaukiResourceState", "Self service")
WITH_KEY = "with_key", pgettext_lazy("HaukiResourceState", "With key")
WITH_RESERVATION = "with_reservation", pgettext_lazy("HaukiResourceState", "With reservation")
OPEN_AND_RESERVABLE = "open_and_reservable", pgettext_lazy("HaukiResourceState", "Open and reservable")
WITH_KEY_AND_RESERVATION = (
"with_key_and_reservation",
pgettext_lazy("HaukiResourceState", "With key and reservation"),
)
ENTER_ONLY = "enter_only", pgettext_lazy("HaukiResourceState", "Enter only")
EXIT_ONLY = "exit_only", pgettext_lazy("HaukiResourceState", "Exit only")
WEATHER_PERMITTING = "weather_permitting", pgettext_lazy("HaukiResourceState", "Weather permitting")
NOT_IN_USE = "not_in_use", pgettext_lazy("HaukiResourceState", "Not in use")
MAINTENANCE = "maintenance", pgettext_lazy("HaukiResourceState", "Maintenance")

@classmethod
def accessible_states(cls):
Expand Down
3 changes: 1 addition & 2 deletions tilavarauspalvelu/templatetags/tilavarauspalvelu.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from decimal import Decimal

import jinja2
from django import template
from django_jinja import library

Expand All @@ -13,7 +12,7 @@
@library.filter(name="currency")
def format_currency(price: Decimal | float) -> str:
if not isinstance(price, Decimal) and not isinstance(price, int) and not isinstance(price, float):
raise jinja2.TemplateError(f"Error trying to format value as currency. '{price}' is not a number.")
raise TypeError(f"Error trying to format value as currency. '{price}' is not a number.")

price = round_decimal(Decimal(price), 2)
return f"{price:,.2f}".replace(",", " ").replace(".", ",")
Expand Down

0 comments on commit 286b8d0

Please sign in to comment.