Skip to content

Commit

Permalink
chore(actions): Make Build Run.
Browse files Browse the repository at this point in the history
Updated `env` to ensure existence of certain directories on startup.
Added missing deps.
  • Loading branch information
acederberg committed Feb 6, 2025
1 parent 1c400d1 commit 9a3c87c
Show file tree
Hide file tree
Showing 4 changed files with 188 additions and 16 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,4 @@ blog/dev/_live_quarto_table_files/
blog/projects/blog/typedoc
blog/projects/blog/quartodoc
blog/dsa/leetcode/calendar_2/_oops_files/
.env.actions
37 changes: 22 additions & 15 deletions acederbergio/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import logging
import logging.config
import logging.handlers
import os
import pathlib
import secrets
from os import environ
Expand Down Expand Up @@ -82,7 +83,11 @@ def require(varname: str, default: str | None = None) -> str:


def require_path(
varname: str, default: pathlib.Path | None = None, *, strict: bool = True
varname: str,
default: pathlib.Path | None = None,
*,
strict: bool = True,
ensure_dir: bool = False,
) -> pathlib.Path:
"""Require a setting from environment that is an existing path.
Expand All @@ -96,12 +101,16 @@ def require_path(

var = get(varname)
if var is not None:
return pathlib.Path(var).resolve(strict=strict)

if default is None:
output = pathlib.Path(var)
elif default is None:
raise ValueError(f"Value `{var}` for `{varname}` is falsy.")
else:
output = default

return default.resolve(strict=strict)
if ensure_dir and not os.path.exists(output := output.resolve()):
os.mkdir(output)

return output.resolve(strict=strict)


def create_validator(varname: str, default: str | None = None):
Expand Down Expand Up @@ -160,24 +169,19 @@ def validator(v: Any) -> Any:
WORKDIR = ROOT
PYPROJECT_TOML = ROOT / "pyproject.toml"
CONFIGS = require_path("config_dir", ROOT / "config", strict=False)

BUILD = BLOG / "build"
ICONS = BLOG / "icons"

else:
# NOTE:
WORKDIR = require_path("workdir")
BLOG = require_path("blog", WORKDIR / "blog")
PYPROJECT_TOML = require_path("pyproject_toml", WORKDIR / "pyproject.toml")
CONFIGS = require_path("config_dir", pathlib.Path.home() / "config", strict=False)

BUILD = require_path("build", BLOG / "build")
ICONS = require_path("icons", BLOG / "icons")

BUILD = require_path("build", BLOG / "build", ensure_dir=True)
ICONS = require_path("icons", BLOG / "icons", ensure_dir=True)
VERBOSE = require("verbose", "0") != "0"
TEMPLATES = require_path("templates", SCRIPTS / "templates")
ICONS_SETS = require_path("icon_sets", ICONS / "sets")
BUILD_JSON = require_path("build_json", BLOG / "build.json")
ICONS_SETS = require_path("icon_sets", ICONS / "sets", ensure_dir=True)
BUILD_JSON = require_path("build_json", BLOG / "build.json", strict=False)

LEVEL = require("log_level", "INFO").upper()
LEVEL_FILTERS = require("log_level_filters", LEVEL).upper()
Expand Down Expand Up @@ -239,13 +243,16 @@ def create_logging_config() -> dict[str, Any]:
config_pandoc_filters = {"level": "INFO", "handlers": ["_socket"]}
else:
# NOTE: Add build logs to build in ci mode.
log_file = BUILD / "build.jsonl"
log_file.touch()

handlers.update(
{
"_file": {
"class": "logging.FileHandler",
"level": LEVEL_FILTERS,
"formatter": "json",
"filename": str(BUILD / "build.jsonl"),
"filename": str(log_file),
}
}
)
Expand Down
Loading

0 comments on commit 9a3c87c

Please sign in to comment.