|
1 | 1 | """tail_jsonl.""" |
2 | 2 |
|
3 | | -from datetime import datetime, timezone |
4 | | -from enum import Enum |
5 | | -from os import getenv |
6 | | -from warnings import filterwarnings |
7 | | - |
8 | | -from beartype import BeartypeConf |
9 | | -from beartype.claw import beartype_this_package |
10 | | -from beartype.roar import BeartypeDecorHintPep585DeprecationWarning |
11 | | -from typing_extensions import Self |
| 3 | +from ._runtime_type_check_setup import configure_runtime_type_checking_mode |
12 | 4 |
|
13 | 5 | __version__ = '1.2.5' |
14 | 6 | __pkg_name__ = 'tail_jsonl' |
15 | 7 |
|
16 | | - |
17 | | -class _RuntimeTypeCheckingModes(Enum): |
18 | | - """Supported global runtime type checking modes.""" |
19 | | - |
20 | | - ERROR = 'ERROR' |
21 | | - WARNING = 'WARNING' |
22 | | - OFF = None |
23 | | - |
24 | | - @classmethod |
25 | | - def from_environment(cls) -> Self: # pragma: no cover |
26 | | - """Return the configured mode.""" |
27 | | - rtc_mode = getenv('RUNTIME_TYPE_CHECKING_MODE') or None |
28 | | - try: |
29 | | - return cls(rtc_mode) |
30 | | - except ValueError: |
31 | | - modes = [_e.value for _e in cls] |
32 | | - msg = f"'RUNTIME_TYPE_CHECKING_MODE={rtc_mode}' is not an allowed mode from {modes}" |
33 | | - raise ValueError(msg) from None |
34 | | - |
35 | | - |
36 | | -def configure_runtime_type_checking_mode() -> None: # pragma: no cover |
37 | | - """Optionally configure runtime type checking mode globally.""" |
38 | | - rtc_mode = _RuntimeTypeCheckingModes.from_environment() |
39 | | - |
40 | | - if rtc_mode is not _RuntimeTypeCheckingModes.OFF: |
41 | | - from beartype.roar import BeartypeClawDecorWarning # noqa: PLC0415 |
42 | | - |
43 | | - beartype_this_package(conf=BeartypeConf( |
44 | | - warning_cls_on_decorator_exception=( |
45 | | - None if rtc_mode is _RuntimeTypeCheckingModes.ERROR else BeartypeClawDecorWarning |
46 | | - ), |
47 | | - )) |
48 | | - |
49 | | - |
50 | | -_PEP585_DATE = 2025 |
51 | | -if datetime.now(tz=timezone.utc).year <= _PEP585_DATE: # pragma: no cover |
52 | | - filterwarnings('ignore', category=BeartypeDecorHintPep585DeprecationWarning) |
53 | 8 | configure_runtime_type_checking_mode() |
54 | 9 |
|
55 | | -# ====== Above is the recommended code from calcipy_template and may be updated on new releases ====== |
| 10 | + |
| 11 | +# == Above code must always be first == |
0 commit comments