Skip to content

Commit

Permalink
Merge pull request #606 from jodal/bump-deps
Browse files Browse the repository at this point in the history
Bump dependencies
  • Loading branch information
jodal authored Dec 28, 2024
2 parents ec6ad29 + 9d072f8 commit f384d15
Show file tree
Hide file tree
Showing 14 changed files with 172 additions and 210 deletions.
6 changes: 4 additions & 2 deletions docs/conf.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
# noqa: INP001

import toml
import pathlib
import tomllib

project = "Comics"
author = "Stein Magnus Jodal and contributors"
copyright = f"2009-2024, {author}" # noqa: A001

release = toml.load("../pyproject.toml")["project"]["version"]
with pathlib.Path("../pyproject.toml").open("rb") as fh:
release = tomllib.load(fh)["project"]["version"]
version = ".".join(release.split(".")[:2])

extensions = [
Expand Down
1 change: 0 additions & 1 deletion docs/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
Sphinx >= 3.5.2
sphinx-rtd-theme >= 0.5.1
sphinxcontrib-httpdomain >= 1.7.0
toml >= 0.10.2
43 changes: 15 additions & 28 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,19 @@ license = { text = "AGPL-3.0-only" }
classifiers = ["Private :: Do Not Upload"]
requires-python = ">=3.12,<3.13"
dependencies = [
"cssmin==0.2.0",
"cssselect==1.2.0",
"cssselect>=1.2.0",
"defusedxml>=0.7.1",
"dj-database-url>=2.2.0",
"django-allauth==0.51",
"django-bootstrap-form==3.4",
"django-compressor==3.1",
"django-invitations==1.9.3",
"django-tastypie==0.14.7",
"django==3.2.25",
"dj-database-url>=2.3.0",
"django-allauth==0.51", # TODO: Review changelog and update
"django-bootstrap-form>=3.4",
"django-compressor>=4.5.1",
"django-invitations>=2.1.0",
"django-tastypie>=0.15.0",
"django>=4.2.17,<5",
"feedparser>=6.0.11",
"httpx>=0.28.1",
"jsmin==3.0.1",
"lxml>=5.3.0",
"pillow>=11.0.0",
"pytz>=2024.2",
"sentry-sdk>=2.19.2",
"setuptools>=75.6.0", # Needed by django-bootstrap-form
"typenv>=0.2.0",
Expand All @@ -40,8 +37,8 @@ comics = "comics.__main__:main"

[dependency-groups]
dev = [
"django-debug-toolbar>=3.8.1,<4",
"django-extensions>=3.2.3,<4",
"django-debug-toolbar>=4.4.6",
"django-extensions>=3.2.3",
"tox-uv>=1.16.2",
"tox>=4.21",
]
Expand All @@ -50,29 +47,19 @@ dev = [
# docs = []
lint = ["ruff>=0.8.4"]
tests = [
"pytest>=8.2.2,<9",
"pytest-cov>=5.0.0,<6",
"pytest-django>=4.8.0,<5",
"pytest-mock>=3.14.0,<4",
]
typing = [
"django-stubs>=1.16.0,<2",
"mypy>=1.10.0,<2",
"types-pytz>=2024.1.0.20240417,<2025",
"types-toml>=0.10.8.20240310,<0.11",
"pytest>=8.3.4",
"pytest-cov>=6.0.0",
"pytest-django>=4.8.0",
"pytest-mock>=3.14.0",
]
typing = ["django-stubs==4.2.7", "mypy>=1.7,<1.8"]


[tool.django-stubs]
django_settings_module = "comics.settings"


[tool.pytest.ini_options]
filterwarnings = [
"ignore::django.utils.deprecation.RemovedInDjango40Warning:invitations",
"ignore::django.utils.deprecation.RemovedInDjango40Warning:tastypie",
"ignore::django.utils.deprecation.RemovedInDjango41Warning",
]
DJANGO_SETTINGS_MODULE = "comics.settings"


Expand Down
16 changes: 0 additions & 16 deletions src/comics/__init__.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,5 @@
import logging
import warnings

from django.utils.deprecation import RemovedInDjango40Warning

# Install a default log handler so that we don't get errors about missing log
# handlers when running tests.
logging.getLogger("comics").addHandler(logging.NullHandler())

# Filter warnings from dependencies with known deprecation warnings to that we
# can spot any warnings from our own code.
warnings.filterwarnings(
action="ignore",
category=RemovedInDjango40Warning,
module="invitations",
)
warnings.filterwarnings(
action="ignore",
category=RemovedInDjango40Warning,
module="tastypie",
)
4 changes: 3 additions & 1 deletion src/comics/accounts/models.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import uuid

from django.contrib.auth.models import User
Expand Down Expand Up @@ -29,7 +31,7 @@ class UserProfile(models.Model):
default=make_secret_key,
help_text="Secret key for feed and API access",
)
comics = models.ManyToManyField(
comics: models.ManyToManyField[Comic, UserProfile] = models.ManyToManyField(
Comic,
through="Subscription",
)
Expand Down
13 changes: 7 additions & 6 deletions src/comics/aggregator/crawler.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
import re
import time
import xml.sax
import zoneinfo
from dataclasses import dataclass, field
from typing import TYPE_CHECKING

import httpx
import pytz
from django.utils import timezone

from comics.aggregator.exceptions import (
Expand Down Expand Up @@ -153,8 +153,8 @@ def _get_date_to_crawl(self, pub_date: datetime.date | None) -> datetime.date:

@property
def current_date(self) -> datetime.date:
tz = pytz.timezone(self.time_zone)
now_in_tz = tz.normalize(now().astimezone(tz))
time_zone = zoneinfo.ZoneInfo(self.time_zone)
now_in_tz = now().astimezone(time_zone)
return now_in_tz.date()

@property
Expand Down Expand Up @@ -201,9 +201,10 @@ def string_to_date(self, string: str, fmt: str) -> datetime.date:

def date_to_epoch(self, date: datetime.date) -> int:
"""The UNIX time of midnight at ``date`` in the comic's time zone"""
naive_midnight = datetime.datetime(date.year, date.month, date.day)
local_midnight = pytz.timezone(self.time_zone).localize(naive_midnight)
return int(time.mktime(local_midnight.utctimetuple()))
midnight = datetime.datetime(
date.year, date.month, date.day, tzinfo=zoneinfo.ZoneInfo(self.time_zone)
)
return int(time.mktime(midnight.utctimetuple()))


class ComicsKingdomCrawlerBase(CrawlerBase):
Expand Down
10 changes: 5 additions & 5 deletions src/comics/aggregator/tests/test_crawler.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import datetime
import zoneinfo

import pytz
from django.test import TestCase

from comics.aggregator import crawler
Expand All @@ -13,27 +13,27 @@ class CurrentDateWhenLocalTZIsUTCTest(TestCase):
now: datetime.datetime

def setUp(self):
self.tz = pytz.timezone(self.time_zone_local)
self.tz = zoneinfo.ZoneInfo(self.time_zone_local)
self.crawler = crawler.CrawlerBase(None)
crawler.now = lambda: self.now
crawler.today = lambda: self.now.today()

def test_current_date_when_crawler_is_in_local_today(self):
self.now = self.tz.localize(datetime.datetime(2001, 2, 5, 23, 1, 0))
self.now = datetime.datetime(2001, 2, 5, 23, 1, 0, tzinfo=self.tz)
self.crawler.time_zone = self.time_zone_local

today = datetime.date(2001, 2, 5)
self.assertEqual(self.crawler.current_date, today)

def test_current_date_when_crawler_is_in_local_tomorrow(self):
self.now = self.tz.localize(datetime.datetime(2001, 2, 5, 23, 1, 0))
self.now = datetime.datetime(2001, 2, 5, 23, 1, 0, tzinfo=self.tz)
self.crawler.time_zone = self.time_zone_ahead

tomorrow = datetime.date(2001, 2, 6)
self.assertEqual(self.crawler.current_date, tomorrow)

def test_current_date_when_crawler_is_in_local_yesterday(self):
self.now = self.tz.localize(datetime.datetime(2001, 2, 5, 0, 59, 0))
self.now = datetime.datetime(2001, 2, 5, 0, 59, 0, tzinfo=self.tz)
self.crawler.time_zone = self.time_zone_behind

yesterday = datetime.date(2001, 2, 4)
Expand Down
2 changes: 1 addition & 1 deletion src/comics/browser/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class ReleaseMixin(LoginRequiredMixin, ComicMixin):
"""Things common for *all* views of comic releases"""

allow_future = True
template_name = "browser/release_list.html"
template_name: str | None = "browser/release_list.html"

def render_to_response(self, context, **kwargs):
# We hook into render_to_response() instead of get_context_data()
Expand Down
2 changes: 1 addition & 1 deletion src/comics/core/migrations/0001_initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ class Migration(migrations.Migration):
height_field="height",
storage=django.core.files.storage.FileSystemStorage(
base_url="/media/",
location="/home/jodal/dev/comics/media",
location="/home/jodal/dev/comics/run/media",
),
width_field="width",
upload_to=comics.core.models.image_file_path,
Expand Down
4 changes: 3 additions & 1 deletion src/comics/core/models.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import datetime
import os

Expand Down Expand Up @@ -93,7 +95,7 @@ class Release(models.Model):
verbose_name="publication date",
db_index=True,
)
images = models.ManyToManyField(
images: models.ManyToManyField[Image, Release] = models.ManyToManyField(
"Image",
related_name="releases",
)
Expand Down
8 changes: 4 additions & 4 deletions src/comics/core/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
<script>
window.dataLayer = window.dataLayer || [];
function gtag() {
dataLayer.push(arguments);
dataLayer.push(arguments);
}
gtag('js', new Date());
gtag('config', '{{ google_analytics_code }}');
gtag('config', '{{ google_analytics_code }}');
</script>
{% endif %}
</head>
Expand Down Expand Up @@ -141,9 +141,9 @@
</p>
<ul class="list-inline">
<li><a href="{% url "help_about" %}">About</a></li>
{% if user.is_authenticated %}
{% if user.is_authenticated %}
<li><a href="{% url "help_feedback" %}">Contact</a></li>
{% endif %}
{% endif %}
<li><a href="{% url "help_keyboard" %}">Keyboard shortcuts</a></li>
</ul>
</div>
Expand Down
7 changes: 5 additions & 2 deletions src/comics/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
"DJANGO_DEBUG",
default=False,
)
INTERNAL_IPS = [
"127.0.0.1" # Required by django-debug-toolbar
]

#: Site admins
ADMINS = []
Expand Down Expand Up @@ -243,10 +246,10 @@
COMPRESS_FILTERS = {
"css": [
"compressor.filters.css_default.CssAbsoluteFilter",
"compressor.filters.cssmin.CSSMinFilter",
"compressor.filters.cssmin.rCSSMinFilter",
],
"js": [
"compressor.filters.jsmin.JSMinFilter",
"compressor.filters.jsmin.rJSMinFilter",
],
}

Expand Down
11 changes: 11 additions & 0 deletions src/comics/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,20 @@
path("", include("comics.browser.urls")),
]


# Let Django host media if doing local development on runserver
if not settings.MEDIA_URL.startswith("http"):
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)


# Include debug_toolbar during development
if settings.DEBUG:
try:
from debug_toolbar.toolbar import debug_toolbar_urls
except ImportError:
pass
else:
urlpatterns += debug_toolbar_urls()


urlpatterns += static(settings.STATIC_URL)
Loading

0 comments on commit f384d15

Please sign in to comment.