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:
Jonas L 2022-01-06 14:40:52 +01:00 committed by GitHub
parent ba8b51af76
commit 3a615cafa0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 568 additions and 0 deletions

View 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}...")