feat: create libretime_shared package (#1349)
* feat: create libretime_shared package - We don't use pydantic.BaseSettings because of some incompatble loading behavior. * fix: whitelist pydantic in pylintrc * docs: update to new BaseConfig behavior * docs: change confusing config filepath
This commit is contained in:
parent
ba8b51af76
commit
3a615cafa0
13 changed files with 568 additions and 0 deletions
36
shared/libretime_shared/app.py
Normal file
36
shared/libretime_shared/app.py
Normal file
|
@ -0,0 +1,36 @@
|
|||
from abc import ABC, abstractmethod
|
||||
from os import PathLike
|
||||
from pathlib import Path
|
||||
from typing import Optional
|
||||
|
||||
from loguru import logger
|
||||
|
||||
from .logging import LogLevel, setup_logger
|
||||
|
||||
|
||||
# pylint: disable=too-few-public-methods
|
||||
class AbstractApp(ABC):
|
||||
"""
|
||||
Abstracts the creation of an application to reduce boilerplate code such
|
||||
as logging setup.
|
||||
"""
|
||||
|
||||
log_level: LogLevel
|
||||
|
||||
@property
|
||||
@abstractmethod
|
||||
def name(self) -> str:
|
||||
...
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
*,
|
||||
verbosity: int,
|
||||
log_filepath: Optional[PathLike] = None,
|
||||
):
|
||||
if log_filepath is not None:
|
||||
log_filepath = Path(log_filepath)
|
||||
|
||||
self.log_level = setup_logger(verbosity=verbosity, filepath=log_filepath)
|
||||
|
||||
logger.info(f"Starting {self.name}...")
|
Loading…
Add table
Add a link
Reference in a new issue