Initial commit
This commit is contained in:
3
uv_app/__init__.py
Normal file
3
uv_app/__init__.py
Normal file
@@ -0,0 +1,3 @@
|
||||
from uv_app import logging_config, settings
|
||||
|
||||
__all__ = ["logging_config", "settings"]
|
||||
16
uv_app/__main__.py
Normal file
16
uv_app/__main__.py
Normal file
@@ -0,0 +1,16 @@
|
||||
import click
|
||||
|
||||
|
||||
@click.group()
|
||||
def cli() -> None:
|
||||
"""Application Command Line Interface."""
|
||||
|
||||
|
||||
@cli.command()
|
||||
def main() -> None:
|
||||
"""An example command that prints a message."""
|
||||
click.echo("This is an example command from uv_app.")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
cli()
|
||||
1
uv_app/core/__init__.py
Normal file
1
uv_app/core/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
"""Core utilities for the application."""
|
||||
31
uv_app/core/db.py
Normal file
31
uv_app/core/db.py
Normal file
@@ -0,0 +1,31 @@
|
||||
import os
|
||||
from typing import Optional
|
||||
|
||||
import psycopg2
|
||||
from dotenv import load_dotenv
|
||||
|
||||
# Force reload environment variables from .env, ignoring system vars.
|
||||
load_dotenv(override=True)
|
||||
|
||||
DB_HOST = os.getenv("DB_HOST")
|
||||
DB_PORT = os.getenv("DB_PORT")
|
||||
DB_NAME = os.getenv("DB_NAME")
|
||||
DB_USER = os.getenv("DB_USER")
|
||||
DB_PASSWORD = os.getenv("DB_PASSWORD")
|
||||
|
||||
|
||||
def connect_to_db() -> Optional[psycopg2.extensions.connection]:
|
||||
"""Establish a connection to the PostgreSQL database."""
|
||||
try:
|
||||
return psycopg2.connect(
|
||||
host=DB_HOST,
|
||||
port=DB_PORT,
|
||||
database=DB_NAME,
|
||||
user=DB_USER,
|
||||
password=DB_PASSWORD,
|
||||
# Set the client encoding to UTF-8.
|
||||
options="-c client_encoding=utf8",
|
||||
)
|
||||
except psycopg2.Error as exc:
|
||||
print(f"Error connecting to PostgreSQL database: {exc}")
|
||||
return None
|
||||
3
uv_app/example_util.py
Normal file
3
uv_app/example_util.py
Normal file
@@ -0,0 +1,3 @@
|
||||
def addition(a: float, b: float) -> float | int:
|
||||
"""Returns the sum of two numbers."""
|
||||
return a + b
|
||||
9
uv_app/logging_config.py
Normal file
9
uv_app/logging_config.py
Normal file
@@ -0,0 +1,9 @@
|
||||
import logging
|
||||
|
||||
LOGGER = logging.getLogger(__name__)
|
||||
|
||||
logging.basicConfig(
|
||||
format="%(asctime)s [%(levelname)s] - <%(name)s> - %(message)s",
|
||||
level=logging.INFO,
|
||||
handlers=[logging.StreamHandler()],
|
||||
)
|
||||
18
uv_app/settings.py
Normal file
18
uv_app/settings.py
Normal file
@@ -0,0 +1,18 @@
|
||||
from dotenv import find_dotenv
|
||||
from pydantic_settings import BaseSettings, SettingsConfigDict
|
||||
|
||||
DEFAULT_CONFIG_SETTINGS = SettingsConfigDict(
|
||||
env_file=find_dotenv(),
|
||||
env_file_encoding="utf-8",
|
||||
env_ignore_empty=True,
|
||||
extra="ignore",
|
||||
validate_default=True,
|
||||
)
|
||||
|
||||
|
||||
class AppSettings(BaseSettings):
|
||||
model_config = DEFAULT_CONFIG_SETTINGS
|
||||
EXAMPLE_ENV_VARIABLE: str
|
||||
|
||||
|
||||
app_settings = AppSettings()
|
||||
Reference in New Issue
Block a user