Skip to content

Commit

Permalink
feature(actions): Should Build without Database.
Browse files Browse the repository at this point in the history
Added `include` to `db.Config` because the database should not be used
in builds (for now).
Added banner, svg captures, and japanese figure.
Added more notes on NVIM improvements.
  • Loading branch information
acederberg committed Feb 7, 2025
1 parent bb31225 commit 399bd20
Show file tree
Hide file tree
Showing 8 changed files with 564 additions and 104 deletions.
1 change: 0 additions & 1 deletion .github/workflows/commit_checks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ jobs:
echo "ACEDERBERG_IO_ENV=ci" >> "GITHUB_ENV"
source .venv/bin/activate
poetry run acederbergio db config
poetry run coverage run -m pytest
poetry run coverage html
- name: Upload Coverage Report.
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,4 @@ blog/projects/blog/typedoc
blog/projects/blog/quartodoc
blog/dsa/leetcode/calendar_2/_oops_files/
.env.actions
blog/posts/keywords/*.svg
31 changes: 28 additions & 3 deletions acederbergio/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,16 @@ def check_object_id(value) -> str | None:
pydantic.Field(default=None),
pydantic.BeforeValidator(check_object_id),
]
FlagURL = Annotated[str, typer.Option("--mongodb-url"), pydantic.Field(URL)]
FlagURL = Annotated[
pydantic.MongoDsn, typer.Option("--mongodb-url"), pydantic.Field(URL)
]
FlagDatabase = Annotated[str, pydantic.Field(DATABASE)]


def create_client(*, _mongodb_url: str | None = None, cls: Type = MongoClient):
mongodb_url = env.require("mongodb_url", _mongodb_url)
def create_client(
*, _mongodb_url: pydantic.MongoDsn | str | None = None, cls: Type = MongoClient
):
mongodb_url = env.require("mongodb_url", str(_mongodb_url))
return cls(mongodb_url, server_api=ServerApi("1"))


Expand All @@ -64,6 +68,27 @@ class Config(ysp.BaseYamlSettings):

database: FlagDatabase
url: FlagURL
include: Annotated[
bool,
pydantic.Field(
default=env.ENV == "ci",
description="""
When mongodb is not required (e.g. during builds) use this to
run without it. Some documents using this code do not need mongodb
for one off renders. To set this, do
.. code:: python
ACEDERBERG_IO_MONGODB_INCLUDE=false
and verify:
.. code:: shell
acederbergio db config
""",
),
]

def create_client(self) -> MongoClient:
return create_client(_mongodb_url=self.url)
Expand Down
7 changes: 5 additions & 2 deletions acederbergio/pdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def compare(cls, left: "Metrics", right: "Metrics") -> Self:
)


class Metrics(util.HasTimestamp):
class Metrics(util.HasTimestamp, db.HasMongoId):
"""
**RAKE** metrics for a piece of text.
Expand Down Expand Up @@ -203,6 +203,9 @@ async def lazy(
force: bool = False,
) -> Self:

# if db is None:
# return cls.create(cls.createDF(text), text=text, metadata=metadata)

collection = db[cls._collection]
res = await collection.find_one(cls.match_text(text)["$match"])
if not force and res is not None:
Expand Down Expand Up @@ -469,7 +472,7 @@ def __init__(
@classmethod
def resolveText(cls, text: FlagText, _file: FlagFile) -> tuple[str, dict[str, str]]:
if text is None and _file is None:
util.CONSOLE.print("[red]Failed to determine text.")
util.CONSOLE.print("[red]One of `--text` or `--file` is required.")
raise typer.Exit(3)

metadata = dict(origin="cli", origin_file="pdf.py")
Expand Down
5 changes: 3 additions & 2 deletions acederbergio/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ def print_yaml(
rule_title: str = "",
rule_kwargs: dict[str, Any] = dict(),
is_complex: bool = False,
console: rich.console.Console = CONSOLE,
**kwargs_model_dump,
) -> rich.syntax.Syntax | None:
if items:
Expand Down Expand Up @@ -109,9 +110,9 @@ def print_yaml(
)

if rule_title or rule_kwargs:
CONSOLE.rule(rule_title, **rule_kwargs)
console.rule(rule_title, **rule_kwargs)

CONSOLE.print(s)
console.print(s)
return s


Expand Down
Loading

0 comments on commit 399bd20

Please sign in to comment.