mirror of
https://github.com/jongracecox/anybadge.git
synced 2025-12-16 02:20:06 +01:00
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:
committed by
Jon Grace-Cox
parent
cc5a757663
commit
a076a4867a
@@ -1,6 +1,6 @@
|
|||||||
repos:
|
repos:
|
||||||
- repo: https://github.com/pre-commit/pre-commit-hooks
|
- repo: https://github.com/pre-commit/pre-commit-hooks
|
||||||
rev: v4.3.0
|
rev: v5.0.0
|
||||||
hooks:
|
hooks:
|
||||||
- id: trailing-whitespace
|
- id: trailing-whitespace
|
||||||
- id: end-of-file-fixer
|
- id: end-of-file-fixer
|
||||||
@@ -11,11 +11,11 @@ repos:
|
|||||||
- id: no-commit-to-branch
|
- id: no-commit-to-branch
|
||||||
args: [--branch, master]
|
args: [--branch, master]
|
||||||
- repo: https://github.com/psf/black
|
- repo: https://github.com/psf/black
|
||||||
rev: 22.6.0
|
rev: 24.10.0
|
||||||
hooks:
|
hooks:
|
||||||
- id: black
|
- id: black
|
||||||
- repo: https://github.com/pre-commit/mirrors-mypy
|
- repo: https://github.com/pre-commit/mirrors-mypy
|
||||||
rev: v0.971
|
rev: v1.14.0
|
||||||
hooks:
|
hooks:
|
||||||
- id: mypy
|
- id: mypy
|
||||||
additional_dependencies: [types-all]
|
additional_dependencies: [types-requests]
|
||||||
|
|||||||
@@ -107,21 +107,21 @@ class Badge:
|
|||||||
self,
|
self,
|
||||||
label,
|
label,
|
||||||
value,
|
value,
|
||||||
font_name: str = None,
|
font_name: Optional[str] = None,
|
||||||
font_size: int = None,
|
font_size: Optional[int] = None,
|
||||||
num_padding_chars: int = None,
|
num_padding_chars: Optional[int] = None,
|
||||||
num_label_padding_chars: float = None,
|
num_label_padding_chars: Optional[float] = None,
|
||||||
num_value_padding_chars: float = None,
|
num_value_padding_chars: Optional[float] = None,
|
||||||
template: Union[Path, str] = None,
|
template: Optional[Union[Path, str]] = None,
|
||||||
style: str = None,
|
style: Optional[str] = None,
|
||||||
value_prefix: str = "",
|
value_prefix: Optional[str] = "",
|
||||||
value_suffix: str = "",
|
value_suffix: Optional[str] = "",
|
||||||
thresholds: Optional[Dict[float, str]] = None,
|
thresholds: Optional[Dict[float, str]] = None,
|
||||||
default_color: str = None,
|
default_color: Optional[str] = None,
|
||||||
use_max_when_value_exceeds: bool = True,
|
use_max_when_value_exceeds: Optional[bool] = True,
|
||||||
value_format: str = None,
|
value_format: Optional[str] = None,
|
||||||
text_color: str = None,
|
text_color: Optional[str] = None,
|
||||||
semver: bool = False,
|
semver: Optional[bool] = False,
|
||||||
):
|
):
|
||||||
"""Constructor for Badge class."""
|
"""Constructor for Badge class."""
|
||||||
# Set defaults if values were not passed
|
# Set defaults if values were not passed
|
||||||
@@ -162,7 +162,18 @@ class Badge:
|
|||||||
value_text = str(self.value_type(value))
|
value_text = str(self.value_type(value))
|
||||||
self.value_prefix = value_prefix
|
self.value_prefix = value_prefix
|
||||||
self.value_suffix = value_suffix
|
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:
|
if font_name not in config.FONT_WIDTHS:
|
||||||
raise ValueError(
|
raise ValueError(
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import argparse
|
|||||||
import logging
|
import logging
|
||||||
from http.server import HTTPServer
|
from http.server import HTTPServer
|
||||||
from os import environ
|
from os import environ
|
||||||
|
from typing import Optional, Tuple
|
||||||
|
|
||||||
from anybadge.server.request_handler import AnyBadgeHTTPRequestHandler
|
from anybadge.server.request_handler import AnyBadgeHTTPRequestHandler
|
||||||
from anybadge.server import config
|
from anybadge.server import config
|
||||||
@@ -9,7 +10,7 @@ from anybadge.server import config
|
|||||||
logger = logging.getLogger(__name__)
|
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."""
|
"""Run a persistent webserver."""
|
||||||
if not listen_address:
|
if not listen_address:
|
||||||
listen_address = config.DEFAULT_SERVER_LISTEN_ADDRESS
|
listen_address = config.DEFAULT_SERVER_LISTEN_ADDRESS
|
||||||
@@ -54,12 +55,20 @@ def parse_args() -> argparse.Namespace:
|
|||||||
return parser.parse_args()
|
return parser.parse_args()
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main() -> None:
|
||||||
"""Run server."""
|
"""Run server."""
|
||||||
|
|
||||||
# Check for environment variables
|
# Check for environment variables
|
||||||
if "ANYBADGE_PORT" in environ:
|
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:
|
if "ANYBADGE_LISTEN_ADDRESS" in environ:
|
||||||
config.DEFAULT_SERVER_LISTEN_ADDRESS = environ["ANYBADGE_LISTEN_ADDRESS"]
|
config.DEFAULT_SERVER_LISTEN_ADDRESS = environ["ANYBADGE_LISTEN_ADDRESS"]
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
"""Templates package."""
|
"""Templates package."""
|
||||||
|
|
||||||
import pkgutil
|
import pkgutil
|
||||||
|
|
||||||
from anybadge.exceptions import UnknownBadgeTemplate
|
from anybadge.exceptions import UnknownBadgeTemplate
|
||||||
|
|||||||
@@ -4,4 +4,6 @@ pygments
|
|||||||
pytest
|
pytest
|
||||||
pytest-cov
|
pytest-cov
|
||||||
requests
|
requests
|
||||||
types-all
|
setuptools
|
||||||
|
types-requests
|
||||||
|
wheel
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
"""Invoke tasks for the project."""
|
"""Invoke tasks for the project."""
|
||||||
|
|
||||||
import glob
|
import glob
|
||||||
import os
|
import os
|
||||||
import subprocess
|
import subprocess
|
||||||
|
|||||||
Reference in New Issue
Block a user