-
-
Notifications
You must be signed in to change notification settings - Fork 1
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
20 changed files
with
162 additions
and
263 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 |
---|---|---|
@@ -1,6 +1,10 @@ | ||
# ENV files | ||
**/.env | ||
|
||
# Configuration Files | ||
**/.yml | ||
**/.yaml | ||
|
||
# Cache files | ||
**/__pycache__ | ||
**/*.py[cod] | ||
|
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 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
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,52 @@ | ||
from pathlib import Path | ||
from typing import Any, Generic, Optional, TypeVar, Union, overload | ||
|
||
import yaml | ||
|
||
_T = TypeVar("_T") | ||
|
||
|
||
class CatherineConfig(Generic[_T]): | ||
def __init__(self, path: Path): | ||
self.path = path | ||
self._config: dict[str, Union[_T, Any]] = {} | ||
self.load_from_file() | ||
|
||
def load_from_file(self) -> None: | ||
try: | ||
with open(self.path, "r") as f: | ||
self._config: dict[str, Union[_T, Any]] = yaml.safe_load(f.read()) | ||
except FileNotFoundError: | ||
self._config = {} | ||
|
||
@property | ||
def bot(self) -> _T: | ||
return self._config["bot"] | ||
|
||
@property | ||
def postgres(self) -> _T: | ||
return self._config["postgres"] | ||
|
||
@overload | ||
def get(self, key: Any) -> Optional[Union[_T, Any]]: | ||
... | ||
|
||
@overload | ||
def get(self, key: Any, default: Any) -> Union[_T, Any]: | ||
... | ||
|
||
def get(self, key: Any, default: Any = None) -> Optional[Union[_T, Any]]: | ||
"""Retrieves a config entry.""" | ||
return self._config.get(str(key), default) | ||
|
||
def __contains__(self, item: Any) -> bool: | ||
return str(item) in self._config | ||
|
||
def __getitem__(self, item: Any) -> Union[_T, Any]: | ||
return self._config[str(item)] | ||
|
||
def __len__(self) -> int: | ||
return len(self._config) | ||
|
||
def all(self) -> dict[str, Union[_T, Any]]: | ||
return self._config |
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,18 +1,8 @@ | ||
import os | ||
from pathlib import Path | ||
from typing import Dict, Optional | ||
|
||
from dotenv import dotenv_values | ||
|
||
|
||
def is_docker() -> bool: | ||
path = "/proc/self/cgroup" | ||
return os.path.exists("/.dockerenv") or ( | ||
os.path.isfile(path) and any("docker" in line for line in open(path)) | ||
) | ||
|
||
|
||
def read_env(path: Path, read_from_file: bool = True) -> Dict[str, Optional[str]]: | ||
if is_docker() or read_from_file is False: | ||
return {**os.environ} | ||
return {**dotenv_values(path)} |
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,14 @@ | ||
# Catherine-Chan's main configuration | ||
bot: | ||
token: "BOT TOKEN HERE" | ||
dev_mode: False | ||
|
||
prometheus: | ||
enabled: False | ||
host: "127.0.0.1" | ||
port: 6789 | ||
|
||
# Postgres Configuration | ||
postgres: | ||
revision: "rev5" | ||
uri: "postgres://username:password@127.0.0.1:5432/postgres" |
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,4 +1,4 @@ | ||
sphinx==7.3.7 | ||
sphinx>=7.3.7 | ||
furo>=2023.8.19 | ||
sphinx-copybutton>=0.5.2 | ||
sphinxext-opengraph>=0.8.2 | ||
sphinxext-opengraph>=0.8.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
Oops, something went wrong.