From ab2350a8ff423c53ef7467ce97cb0b706387a554 Mon Sep 17 00:00:00 2001 From: Kyle King Date: Tue, 18 Jun 2024 18:04:35 -0400 Subject: [PATCH] build: copier-auto-update --- .copier-answers.yml | 2 +- .pre-commit-config.yaml | 4 +- pyproject.toml | 8 +++- tail_jsonl/__init__.py | 50 ++-------------------- tail_jsonl/_private/core.py | 4 +- tail_jsonl/_runtime_type_check_setup.py | 56 +++++++++++++++++++++++++ tests/config_default.toml | 9 ++-- tests/test_config.py | 2 +- 8 files changed, 76 insertions(+), 59 deletions(-) create mode 100644 tail_jsonl/_runtime_type_check_setup.py diff --git a/.copier-answers.yml b/.copier-answers.yml index fc7bbef..28c06d0 100644 --- a/.copier-answers.yml +++ b/.copier-answers.yml @@ -2,7 +2,7 @@ # Answer file maintained by Copier for: https://github.com/KyleKing/calcipy_template # DO NOT MODIFY THIS FILE. Edit by re-running copier and changing responses to the questions # Check into version control. -_commit: 1.10.4 +_commit: 1.10.7 _src_path: gh:KyleKing/calcipy_template author_email: dev.act.kyle@gmail.com author_name: Kyle King diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 7361b7c..f61ffcc 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -69,7 +69,7 @@ repos: # Note: this version must be the same as the hook revision - "prettier@4.0.0-alpha.8" - "prettier-plugin-sh" - exclude: \.copier-answers\.yml|tests/.*/cassettes/.*\.yaml + exclude: \.copier-answers\.yml|tests/.*/cassettes/.*\.yaml|__snapshots__/.*\.json types_or: [html, javascript, json, shell, yaml] stages: ["pre-commit"] - repo: https://github.com/adrienverge/yamllint.git @@ -86,7 +86,7 @@ repos: exclude: poetry\.lock|config_default.toml|demo_config.toml stages: ["pre-commit"] - repo: https://github.com/KyleKing/calcipy - rev: 2.1.0 + rev: 3.0.1 hooks: - id: copier-forbidden-files - id: lint-fix diff --git a/pyproject.toml b/pyproject.toml index 628c0de..2476616 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -7,8 +7,11 @@ version = "1.2.5" version_files = ["pyproject.toml:^version", "tail_jsonl/__init__.py:^__version"] [tool.mypy] +check_untyped_defs = true disallow_any_generics = true enable_error_code = ["ignore-without-code", "possibly-undefined", "redundant-expr", "truthy-bool"] +extra_checks = true +files = ["tail_jsonl", "tests"] no_implicit_reexport = true plugins = [ "pydantic.mypy", # Most settings are from: https://pydantic-docs.helpmanual.io/mypy_plugin @@ -20,6 +23,7 @@ strict_equality = true warn_no_return = true warn_redundant_casts = true warn_unreachable = true +warn_unused_configs = true warn_unused_ignores = true [tool.poetry] @@ -68,7 +72,7 @@ init_typed = true warn_required_dynamic_aliases = true [tool.pyright] -include = ["tail_jsonl"] +include = ["tail_jsonl", "tests"] pythonVersion = "3.9" [tool.ruff] @@ -107,7 +111,7 @@ unfixable = [ inline-quotes = 'single' [tool.ruff.lint.flake8-tidy-imports.banned-api] -'invoke.collection.Collection'.msg = 'Use calcipy.cli.Collection instead.' +'invoke.collection.Collection'.msg = 'Use calcipy.collection.Collection instead.' 'invoke.tasks.task'.msg = 'Use calcipy.cli.task instead.' 'typing.Callable'.msg = 'Use beartype.typing.* instead.' 'typing.Dict'.msg = 'Use beartype.typing.* instead.' diff --git a/tail_jsonl/__init__.py b/tail_jsonl/__init__.py index 48ec873..ddc0276 100644 --- a/tail_jsonl/__init__.py +++ b/tail_jsonl/__init__.py @@ -1,55 +1,11 @@ """tail_jsonl.""" -from datetime import datetime, timezone -from enum import Enum -from os import getenv -from warnings import filterwarnings - -from beartype import BeartypeConf -from beartype.claw import beartype_this_package -from beartype.roar import BeartypeDecorHintPep585DeprecationWarning -from typing_extensions import Self +from ._runtime_type_check_setup import configure_runtime_type_checking_mode __version__ = '1.2.5' __pkg_name__ = 'tail_jsonl' - -class _RuntimeTypeCheckingModes(Enum): - """Supported global runtime type checking modes.""" - - ERROR = 'ERROR' - WARNING = 'WARNING' - OFF = None - - @classmethod - def from_environment(cls) -> Self: # pragma: no cover - """Return the configured mode.""" - rtc_mode = getenv('RUNTIME_TYPE_CHECKING_MODE') or None - try: - return cls(rtc_mode) - except ValueError: - modes = [_e.value for _e in cls] - msg = f"'RUNTIME_TYPE_CHECKING_MODE={rtc_mode}' is not an allowed mode from {modes}" - raise ValueError(msg) from None - - -def configure_runtime_type_checking_mode() -> None: # pragma: no cover - """Optionally configure runtime type checking mode globally.""" - rtc_mode = _RuntimeTypeCheckingModes.from_environment() - - if rtc_mode is not _RuntimeTypeCheckingModes.OFF: - from beartype.roar import BeartypeClawDecorWarning # noqa: PLC0415 - - beartype_this_package(conf=BeartypeConf( - warning_cls_on_decorator_exception=( - None if rtc_mode is _RuntimeTypeCheckingModes.ERROR else BeartypeClawDecorWarning - ), - )) - - -_PEP585_DATE = 2025 -if datetime.now(tz=timezone.utc).year <= _PEP585_DATE: # pragma: no cover - filterwarnings('ignore', category=BeartypeDecorHintPep585DeprecationWarning) configure_runtime_type_checking_mode() -# ====== Above is the recommended code from calcipy_template and may be updated on new releases ====== + +# == Above code must always be first == diff --git a/tail_jsonl/_private/core.py b/tail_jsonl/_private/core.py index 3a0f23c..32fd018 100644 --- a/tail_jsonl/_private/core.py +++ b/tail_jsonl/_private/core.py @@ -4,7 +4,7 @@ import logging from copy import copy -import dotted +import dotted # type: ignore[import-untyped] from beartype import beartype from beartype.typing import Any, Dict, List, Optional from corallium.loggers.rich_printer import rich_printer @@ -85,7 +85,7 @@ def print_record(line: str, console: Console, config: Config) -> None: } keys = set(printer_kwargs) rich_printer( - **printer_kwargs, + **printer_kwargs, # type: ignore[arg-type] # Ensure that there is no repeat keyword arguments **{f'_{key}' if key in keys else key: value for key, value in record.data.items()}, ) diff --git a/tail_jsonl/_runtime_type_check_setup.py b/tail_jsonl/_runtime_type_check_setup.py new file mode 100644 index 0000000..ab71e43 --- /dev/null +++ b/tail_jsonl/_runtime_type_check_setup.py @@ -0,0 +1,56 @@ +"""Configure runtime typechecking conditionally.""" + +from datetime import datetime, timezone +from enum import Enum +from os import getenv +from warnings import filterwarnings + +from beartype import BeartypeConf +from beartype.claw import beartype_this_package +from beartype.roar import BeartypeDecorHintPep585DeprecationWarning +from typing_extensions import Self + + +class _RuntimeTypeCheckingModes(Enum): + """Supported global runtime type checking modes.""" + + ERROR = 'ERROR' + WARNING = 'WARNING' + OFF = None + + @classmethod + def from_environment(cls) -> Self: # pragma: no cover + """Return the configured mode.""" + rtc_mode = getenv('RUNTIME_TYPE_CHECKING_MODE') or None + try: + return cls(rtc_mode) + except ValueError: + modes = [_e.value for _e in cls] + msg = f"'RUNTIME_TYPE_CHECKING_MODE={rtc_mode}' is not from {modes}" + raise ValueError(msg) from None + + +def configure_runtime_type_checking_mode() -> None: # pragma: no cover + """Optionally configure runtime type checking mode globally.""" + rtc_mode = _RuntimeTypeCheckingModes.from_environment() + + if rtc_mode is not _RuntimeTypeCheckingModes.OFF: + from beartype.roar import BeartypeClawDecorWarning # noqa: PLC0415 + + beartype_this_package( + conf=BeartypeConf( + warning_cls_on_decorator_exception=( + None + if rtc_mode is _RuntimeTypeCheckingModes.ERROR + else BeartypeClawDecorWarning + ), + ), + ) + + +_PEP585_DATE = 2025 +if datetime.now(tz=timezone.utc).year <= _PEP585_DATE: # pragma: no cover + filterwarnings( + 'ignore', + category=BeartypeDecorHintPep585DeprecationWarning, + ) diff --git a/tests/config_default.toml b/tests/config_default.toml index 329fa9e..d6b1127 100644 --- a/tests/config_default.toml +++ b/tests/config_default.toml @@ -19,12 +19,13 @@ on_own_line = ["text", "exception"] timestamp = "#8DAAA1" message = "bold" +key = "#8DAAA1" +value = "#A28EAB" +value_own_line = "#AAA18D" + +[styles.colors] level_error = "#e77d8f" level_warn = "#d8b172" level_info = "#a8cd76" level_debug = "#82a1f1" level_fallback = "#b69bf1" - -key = "#8DAAA1" -value = "#A28EAB" -value_own_line = "#AAA18D" diff --git a/tests/test_config.py b/tests/test_config.py index 6663677..de7dd24 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -1,6 +1,6 @@ from pathlib import Path -from corallium.tomllib import tomllib # type: ignore[no-redef] +from corallium.tomllib import tomllib from tail_jsonl.scripts import _load_config