Skip to content

Commit

Permalink
build: copier-auto-update
Browse files Browse the repository at this point in the history
  • Loading branch information
KyleKing committed Jun 18, 2024
1 parent 213416e commit ab2350a
Show file tree
Hide file tree
Showing 8 changed files with 76 additions and 59 deletions.
2 changes: 1 addition & 1 deletion .copier-answers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
8 changes: 6 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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]
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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.'
Expand Down
50 changes: 3 additions & 47 deletions tail_jsonl/__init__.py
Original file line number Diff line number Diff line change
@@ -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 ==
4 changes: 2 additions & 2 deletions tail_jsonl/_private/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()},
)
56 changes: 56 additions & 0 deletions tail_jsonl/_runtime_type_check_setup.py
Original file line number Diff line number Diff line change
@@ -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,
)
9 changes: 5 additions & 4 deletions tests/config_default.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
2 changes: 1 addition & 1 deletion tests/test_config.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down

0 comments on commit ab2350a

Please sign in to comment.