-
Notifications
You must be signed in to change notification settings - Fork 328
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
1 parent
d95c242
commit 97455fc
Showing
12 changed files
with
489 additions
and
63 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
3.12.2 |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,6 +1,6 @@ | ||
try: | ||
from importlib.metadata import version | ||
except ImportError: | ||
from importlib_metadata import version | ||
from importlib.metadata import version, PackageNotFoundError | ||
|
||
__version__ = version("ell") | ||
try: | ||
__version__ = version("ell") | ||
except PackageNotFoundError: | ||
__version__ = "unknown" |
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 |
---|---|---|
@@ -0,0 +1,47 @@ | ||
|
||
from functools import lru_cache | ||
import json | ||
import os | ||
from typing import Optional | ||
from pydantic import BaseModel | ||
|
||
import logging | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
# todo. maybe we default storage dir and other things in the future to a well-known location | ||
# like ~/.ell or something | ||
@lru_cache(maxsize=1) | ||
def ell_home() -> str: | ||
return os.path.join(os.path.expanduser("~"), ".ell") | ||
|
||
|
||
class Config(BaseModel): | ||
pg_connection_string: Optional[str] = None | ||
storage_dir: Optional[str] = None | ||
mqtt_connection_string: Optional[str] = None | ||
def __init__(self, **kwargs): | ||
super().__init__(**kwargs) | ||
|
||
def model_post_init(self, __context): | ||
# Storage | ||
self.pg_connection_string = self.pg_connection_string or os.getenv( | ||
"ELL_PG_CONNECTION_STRING") | ||
self.storage_dir = self.storage_dir or os.getenv("ELL_STORAGE_DIR") | ||
|
||
# Enforce that we use either sqlite or postgres, but not both | ||
if self.pg_connection_string is not None and self.storage_dir is not None: | ||
raise ValueError("Cannot use both sqlite and postgres") | ||
|
||
# For now, fall back to sqlite if no PostgreSQL connection string is provided | ||
if self.pg_connection_string is None and self.storage_dir is None: | ||
# This intends to honor the default we had set in the CLI | ||
# todo. better default? | ||
self.storage_dir = os.getcwd() | ||
|
||
# Pubsub | ||
self.mqtt_connection_string = self.mqtt_connection_string or os.getenv("ELL_MQTT_CONNECTION_STRING") | ||
|
||
logger.info(f"Resolved config: {json.dumps(self.model_dump(), indent=2)}") | ||
|
This file was deleted.
Oops, something went wrong.
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,34 @@ | ||
import logging | ||
from colorama import Fore, Style, init | ||
|
||
def setup_logging(level: int = logging.INFO): | ||
# Initialize colorama for cross-platform colored output | ||
init(autoreset=True) | ||
|
||
# Create a custom formatter | ||
class ColoredFormatter(logging.Formatter): | ||
FORMATS = { | ||
logging.DEBUG: Fore.CYAN + "[%(asctime)s] %(levelname)-8s %(name)s: %(message)s" + Style.RESET_ALL, | ||
logging.INFO: Fore.GREEN + "[%(asctime)s] %(levelname)-8s %(name)s: %(message)s" + Style.RESET_ALL, | ||
logging.WARNING: Fore.YELLOW + "[%(asctime)s] %(levelname)-8s %(name)s: %(message)s" + Style.RESET_ALL, | ||
logging.ERROR: Fore.RED + "[%(asctime)s] %(levelname)-8s %(name)s: %(message)s" + Style.RESET_ALL, | ||
logging.CRITICAL: Fore.RED + Style.BRIGHT + "[%(asctime)s] %(levelname)-8s %(name)s: %(message)s" + Style.RESET_ALL | ||
} | ||
|
||
def format(self, record): | ||
log_fmt = self.FORMATS.get(record.levelno) | ||
formatter = logging.Formatter(log_fmt, datefmt="%Y-%m-%d %H:%M:%S") | ||
return formatter.format(record) | ||
|
||
# Create and configure the logger | ||
logger = logging.getLogger("ell") | ||
logger.setLevel(level) | ||
|
||
# Create console handler and set formatter | ||
console_handler = logging.StreamHandler() | ||
console_handler.setFormatter(ColoredFormatter()) | ||
|
||
# Add the handler to the logger | ||
logger.addHandler(console_handler) | ||
|
||
return logger |
Oops, something went wrong.