chore: Update pre-commit hooks

Update pre-commit hooks to latest version and apply fixes for
mypy type checking and linting.
This commit is contained in:
Jon Grace-Cox
2024-12-30 06:43:37 -05:00
parent cc5a757663
commit 1886226b65
6 changed files with 47 additions and 23 deletions

View File

@@ -1,6 +1,6 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.3.0
rev: v5.0.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
@@ -11,11 +11,11 @@ repos:
- id: no-commit-to-branch
args: [--branch, master]
- repo: https://github.com/psf/black
rev: 22.6.0
rev: 24.10.0
hooks:
- id: black
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v0.971
rev: v1.14.0
hooks:
- id: mypy
additional_dependencies: [types-all]
additional_dependencies: [types-requests]

View File

@@ -107,21 +107,21 @@ class Badge:
self,
label,
value,
font_name: str = None,
font_size: int = None,
num_padding_chars: int = None,
num_label_padding_chars: float = None,
num_value_padding_chars: float = None,
template: Union[Path, str] = None,
style: str = None,
value_prefix: str = "",
value_suffix: str = "",
font_name: Optional[str] = None,
font_size: Optional[int] = None,
num_padding_chars: Optional[int] = None,
num_label_padding_chars: Optional[float] = None,
num_value_padding_chars: Optional[float] = None,
template: Optional[Union[Path, str]] = None,
style: Optional[str] = None,
value_prefix: Optional[str] = "",
value_suffix: Optional[str] = "",
thresholds: Optional[Dict[float, str]] = None,
default_color: str = None,
use_max_when_value_exceeds: bool = True,
value_format: str = None,
text_color: str = None,
semver: bool = False,
default_color: Optional[str] = None,
use_max_when_value_exceeds: Optional[bool] = True,
value_format: Optional[str] = None,
text_color: Optional[str] = None,
semver: Optional[bool] = False,
):
"""Constructor for Badge class."""
# Set defaults if values were not passed
@@ -162,7 +162,18 @@ class Badge:
value_text = str(self.value_type(value))
self.value_prefix = value_prefix
self.value_suffix = value_suffix
self.value_text = value_prefix + value_text + value_suffix
# Combine prefix, value and suffix into a single value_text string
if value_prefix:
self.value_text = value_prefix
else:
self.value_text = ""
self.value_text += value_text
if value_suffix:
self.value_text += value_suffix
if font_name not in config.FONT_WIDTHS:
raise ValueError(

View File

@@ -2,6 +2,7 @@ import argparse
import logging
from http.server import HTTPServer
from os import environ
from typing import Optional, Tuple
from anybadge.server.request_handler import AnyBadgeHTTPRequestHandler
from anybadge.server import config
@@ -9,7 +10,7 @@ from anybadge.server import config
logger = logging.getLogger(__name__)
def run(listen_address: str = None, port: int = None):
def run(listen_address: Optional[str] = None, port: Optional[int] = None):
"""Run a persistent webserver."""
if not listen_address:
listen_address = config.DEFAULT_SERVER_LISTEN_ADDRESS
@@ -54,12 +55,20 @@ def parse_args() -> argparse.Namespace:
return parser.parse_args()
def main():
def main() -> None:
"""Run server."""
# Check for environment variables
if "ANYBADGE_PORT" in environ:
config.DEFAULT_SERVER_PORT = environ["ANYBADGE_PORT"]
port = environ["ANYBADGE_PORT"]
try:
port_int = int(port)
except ValueError:
logger.error(
"ANYBADGE_PORT environment variable must be an integer. Got %s", port
)
raise
config.DEFAULT_SERVER_PORT = port_int
if "ANYBADGE_LISTEN_ADDRESS" in environ:
config.DEFAULT_SERVER_LISTEN_ADDRESS = environ["ANYBADGE_LISTEN_ADDRESS"]

View File

@@ -1,4 +1,5 @@
"""Templates package."""
import pkgutil
from anybadge.exceptions import UnknownBadgeTemplate

View File

@@ -4,4 +4,6 @@ pygments
pytest
pytest-cov
requests
types-all
setuptools
types-requests
wheel

View File

@@ -1,4 +1,5 @@
"""Invoke tasks for the project."""
import glob
import os
import subprocess