Skip to content

Commit

Permalink
chore: config work
Browse files Browse the repository at this point in the history
  • Loading branch information
phil65 committed Nov 11, 2024
1 parent 88856b4 commit 9b8554f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
15 changes: 13 additions & 2 deletions mkdocs_mknodes/appconfig/appconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
)
from pydantic.functional_validators import BeforeValidator
from pydantic_core import PydanticCustomError
import upath

from mkdocs_mknodes.appconfig import jinjaconfig, themeconfig, validationconfig
from mkdocs_mknodes.appconfig.base import ConfigFile
Expand Down Expand Up @@ -261,7 +262,7 @@ class AppConfig(ConfigFile):
"""
repo_path: str = "."
"""Path to the repository to create a website for. (`http://....my_project.git`)"""
clone_depth: int = 100
clone_depth: int | None = 100
"""Clone depth in case the repository is remote. (Required for `git-changelog`)."""
build_folder: str | None = None
"""Folder to create the Markdown files in.
Expand Down Expand Up @@ -318,7 +319,7 @@ class AppConfig(ConfigFile):
Allows setting up loaders, extensions and the render behavior.
"""
docs_dir: DirectoryPath = Field("docs")
docs_dir: str = Field("docs/")
"""Directory containing documentation markdown source files.
!!! info "Path Resolution"
Expand Down Expand Up @@ -772,6 +773,16 @@ def validate_nav(
return []
return values

@field_validator("docs_dir", mode="before")
@classmethod
def validate_docs_dir(cls, value: str, info: ValidationInfo) -> str:
config_file_path = info.data["config_file_path"]
config_dir = upath.UPath(config_file_path).parent if config_file_path else None
path = upath.UPath(value)
if config_dir and not path.is_absolute():
path = config_dir / path
return str(path.resolve())

@field_validator("dev_addr", mode="before")
@classmethod
def validate_ip_port(cls, v: str) -> str:
Expand Down
2 changes: 1 addition & 1 deletion mkdocs_mknodes/builders/configbuilder.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def build_mkdocs_config(
if self.clone_depth is not None:
cfg.clone_depth = self.clone_depth
# cfg = {**cfg, **kwargs}
text = yamling.dump_yaml(cfg.model_dump(mode="json"))
text = yamling.dump_yaml(cfg.model_dump(mode="json", exclude_none=True))
buffer = io.StringIO(text)
buffer.name = cfg.config_file_path
config = mknodesconfig.MkNodesConfig.from_yaml(buffer, **kwargs)
Expand Down

0 comments on commit 9b8554f

Please sign in to comment.