Skip to content

Commit

Permalink
feature(scripts): Started Keyword Analysis Fun.
Browse files Browse the repository at this point in the history
Added PDF parsing and RAKE metrics.
Added ``NLTK`` notes including rake.
Added ``BaseDBContext``.
Added ``acederbergio.pdf``.
Added ``print_df`` and the JSON decoder that can handle ``pydantic``
objects.
Output cell styling updates.
  • Loading branch information
acederberg committed Feb 5, 2025
1 parent 67d72b4 commit 1c400d1
Show file tree
Hide file tree
Showing 10 changed files with 1,297 additions and 20 deletions.
2 changes: 2 additions & 0 deletions acederbergio/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from acederbergio.api.main import cli as cli_server
from acederbergio.api.quarto import cli as cli_quarto
from acederbergio.pdf import cli as cli_pdf
from acederbergio.config import cli as cli_config
from acederbergio.db import cli as cli_db
from acederbergio.docs import cli as cli_docs
Expand All @@ -11,6 +12,7 @@
from acederbergio.verify import cli as cli_verify

cli = typer.Typer(pretty_exceptions_enable=False)
cli.add_typer(cli_pdf, name="pdf")
cli.add_typer(cli_quarto, name="quarto")
cli.add_typer(cli_server, name="serve")
cli.add_typer(cli_docs, name="docs")
Expand Down
36 changes: 35 additions & 1 deletion acederbergio/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import rich
import typer
import yaml_settings_pydantic as ysp
from motor.motor_asyncio import AsyncIOMotorClient
from motor.motor_asyncio import AsyncIOMotorClient, AsyncIOMotorDatabase
from pymongo import MongoClient
from pymongo.server_api import ServerApi

Expand Down Expand Up @@ -86,6 +86,40 @@ def typerCallback(
context.obj = cls() # type: ignore


class BaseDBContext:
"""
Minimal context for typer commands that use the database.
"""

database: Config
# config: T_Config

_client: AsyncIOMotorClient | None
_db: AsyncIOMotorDatabase | None

def __init__(
self,
database: Config | None = None,
):
self.database = database or Config.model_validate({})
self._collection = None
self._client = None

@property
def client(self) -> AsyncIOMotorClient:
if self._client is None:
self._client = self.database.create_client_async()

return self._client

@property
def db(self) -> AsyncIOMotorDatabase:
if self._collection is None:
self._db = self.client[self.database.database]

return self._db # type: ignore


cli = typer.Typer(callback=Config.typerCallback, help="Mongodb connections.")


Expand Down
3 changes: 3 additions & 0 deletions acederbergio/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ def create_logging_config() -> dict[str, Any]:
config_pandoc_filters = {"level": LEVEL_FILTERS, "handlers": ["_file"]}

config_api = {"level": LEVEL_API, "handlers": ["queue"]}
config_rest = {"level": LEVEL, "handlers": ["_rich"]}
out = {
"version": 1,
"formatters": formatters,
Expand All @@ -276,6 +277,8 @@ def create_logging_config() -> dict[str, Any]:
"acederbergio.api.quarto": config_api,
"acederbergio.api.routes": config_api,
"acederbergio.api.schemas": config_api,
# ETC
"acederbergio.pdf": config_rest,
# ROOT. Do not propogate to this. Logging propagation is stupid and
# can cause
"root": config_api,
Expand Down
Loading

0 comments on commit 1c400d1

Please sign in to comment.