-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
76 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 == |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters