30 lines
874 B
Python
30 lines
874 B
Python
import os
|
|
import tomllib
|
|
from typing import Annotated, Optional
|
|
|
|
|
|
class Config:
|
|
data: Annotated[Optional[dict],
|
|
"Configuration imported from config.toml"] = None
|
|
|
|
@classmethod
|
|
def load(cls):
|
|
"""Loads the contents of the config.toml file into the class.
|
|
|
|
Raises:
|
|
FileNotFoundError: If the file does not exist.
|
|
"""
|
|
if not cls.file_exists():
|
|
raise FileNotFoundError("config.toml does not exist")
|
|
with open("config.toml", "r") as f:
|
|
cls.data = tomllib.load(f)
|
|
|
|
@classmethod
|
|
def file_exists(cls) -> bool:
|
|
"""Whether the config.toml file exists or needs to be created.
|
|
|
|
Returns:
|
|
bool: True if path exists and is a file, False otherwise.
|
|
"""
|
|
return os.path.exists("config.toml") and os.path.isfile("config.toml")
|