Skip to content

Commit

Permalink
Merge pull request #534 from TheCleric/feat-mypy-precommit
Browse files Browse the repository at this point in the history
feat(mypy): Add mypy to pre-commit
  • Loading branch information
mlissner authored May 8, 2024
2 parents a800226 + 2e73397 commit 09d01eb
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 23 deletions.
23 changes: 23 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,29 @@ repos:
- id: pyupgrade
args: [--py311-plus]

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v0.991
hooks:
- id: mypy
additional_dependencies: [
beautifulsoup4==4.12.2,
boto3==1.34.74,
courts-db==0.10.17,
django-debug-toolbar==4.3.0,
django-environ==0.11.2,
django-hcaptcha==0.2.0,
django-htmx==1.17.3,
django-rq==2.10.2,
django-stubs==4.2.0,
"django-tailwind[reload]==3.8.0",
"Mastodon.py[cryptography]==1.8.0",
pillow==10.3.0,
psycopg2-binary==2.9.6,
sentry-sdk==1.44.0,
twitterapi==2.8.2,
types-requests==2.31.0.1,
]

#
# Tried and Failed
#
Expand Down
15 changes: 8 additions & 7 deletions bc/core/utils/images.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@

from django.contrib.staticfiles import finders
from PIL import Image, ImageFont, ImageOps
from PIL.ImageDraw import Draw
from PIL.Image import Image as ImageCls
from PIL.ImageDraw import Draw, ImageDraw


@dataclass
Expand Down Expand Up @@ -173,7 +174,7 @@ def get_dimensions_with_padding(
return ceil(width), ceil(height)

def get_bbox_dimensions(
self, canvas: Draw, title: str, desc: str
self, canvas: ImageDraw, title: str, desc: str
) -> tuple[int, int]:
"""
Returns the dimensions(width and height, in pixels) of the text(title and
Expand Down Expand Up @@ -226,7 +227,7 @@ def get_anchor_coordinates(
y = ceil((self.img.height - height) / 2)
return x, y

def make_image(self) -> Image:
def make_image(self) -> ImageCls:
self.width, _ = self.get_initial_dimensions()
max_character_count = self.get_max_character_count()
# wrap the title and the description using the max_character_count
Expand Down Expand Up @@ -297,9 +298,9 @@ class SponsoredThumbnail:
small_text: str | None = None
title_font_path: str | None = finders.find("fonts/CooperHewitt-Bold.otf")
small_font_path: str | None = finders.find("fonts/CooperHewitt-Medium.otf")
text_box: Image = field(init=False)
background: Image = field(init=False)
overlay_layer: Image = field(init=False)
text_box: ImageCls = field(init=False)
background: ImageCls = field(init=False)
overlay_layer: ImageCls = field(init=False)

def __post_init__(self) -> None:
self.title_font = ImageFont.truetype(self.title_font_path, 46)
Expand Down Expand Up @@ -330,7 +331,7 @@ def get_text_box_dimensions(self) -> tuple[int, int]:

return (bbox_width, bbox_height)

def _fill_text_box(self) -> Image:
def _fill_text_box(self) -> ImageCls:
"""
Creates a canvas for the text box and draw the sponsored text inside it
Expand Down
13 changes: 9 additions & 4 deletions bc/settings/project/security.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,15 @@
# about this, you can check the following links:
# https://github.com/freelawproject/bigcases2/pull/210#discussion_r1182078837
# https://django-debug-toolbar.readthedocs.io/en/latest/installation.html#configure-internal-ips
hostname, _, ips = socket.gethostbyname_ex(socket.gethostname())
INTERNAL_IPS = [".".join(ip.split(".")[:-1] + ["1"]) for ip in ips] + [
"127.0.0.1"
]
try:
hostname, _, ips = socket.gethostbyname_ex(socket.gethostname())
INTERNAL_IPS = [".".join(ip.split(".")[:-1] + ["1"]) for ip in ips] + [
"127.0.0.1"
]
except (
socket.gaierror
): # this is needed as the pre-commit mypy check fails here
INTERNAL_IPS = ["127.0.0.1"]
else:
SESSION_COOKIE_SECURE = True
CSRF_COOKIE_SECURE = True
Expand Down
9 changes: 0 additions & 9 deletions mypy.ini

This file was deleted.

14 changes: 11 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,22 @@ exclude = '''
'''
line-length = 79

[tool.'django-stubs']
django_settings_module = "bc.settings"

[tool.isort]
profile = "black"
line_length = 79

[tool.mypy]
ignore_missing_imports = true
plugins = "mypy_django_plugin.main"
exclude = "migrations/*"

[[tool.mypy.overrides]]
module="django_stubs_ext.*"
follow_imports="normal"

[tool.pylint.messages_control]
disable = "C0330, C0326"

Expand All @@ -102,6 +113,3 @@ max-line-length = "79"
[build-system]
build-backend = "poetry.core.masonry.api"
requires = ["poetry-core>=1.0.0"]

[tool.poetry.scripts]
bigcases2 = "bigcases2.cli:cli"

0 comments on commit 09d01eb

Please sign in to comment.