Skip to content

Commit

Permalink
Refactor Properties into several files for better maintainability
Browse files Browse the repository at this point in the history
  • Loading branch information
object-Object committed May 12, 2024
1 parent 02f4f9e commit dd54f03
Show file tree
Hide file tree
Showing 7 changed files with 373 additions and 302 deletions.
302 changes: 0 additions & 302 deletions src/hexdoc/core/properties.py

This file was deleted.

30 changes: 30 additions & 0 deletions src/hexdoc/core/properties/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
__all__ = [
"JINJA_NAMESPACE_ALIASES",
"AnimatedTexturesProps",
"AnimationFormat",
"BaseProperties",
"EnvironmentVariableProps",
"LangProps",
"PNGTextureOverride",
"Properties",
"TemplateProps",
"TextureTextureOverride",
"TexturesProps",
"env",
"lang",
"properties",
"template",
"textures",
]

from .env import EnvironmentVariableProps
from .lang import LangProps
from .properties import BaseProperties, Properties
from .template import JINJA_NAMESPACE_ALIASES, TemplateProps
from .textures import (
AnimatedTexturesProps,
AnimationFormat,
PNGTextureOverride,
TexturesProps,
TextureTextureOverride,
)
55 changes: 55 additions & 0 deletions src/hexdoc/core/properties/env.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
from __future__ import annotations

from typing import Self

from pydantic import model_validator
from yarl import URL

from hexdoc.model.base import HexdocSettings
from hexdoc.utils.types import PydanticURL


class EnvironmentVariableProps(HexdocSettings):
# default Actions environment variables
github_repository: str
github_sha: str

# set by CI
github_pages_url: PydanticURL

# for putting books somewhere other than the site root
hexdoc_subdirectory: str | None = None

# optional for debugging
debug_githubusercontent: PydanticURL | None = None

@property
def asset_url(self) -> URL:
if self.debug_githubusercontent is not None:
return URL(str(self.debug_githubusercontent))

return (
URL("https://raw.githubusercontent.com")
/ self.repo_owner
/ self.repo_name
/ self.github_sha
)

@property
def repo_owner(self):
return self._github_repository_parts[0]

@property
def repo_name(self):
return self._github_repository_parts[1]

@property
def _github_repository_parts(self):
owner, repo_name = self.github_repository.split("/", maxsplit=1)
return owner, repo_name

@model_validator(mode="after")
def _append_subdirectory(self) -> Self:
if self.hexdoc_subdirectory:
self.github_pages_url /= self.hexdoc_subdirectory
return self
Loading

0 comments on commit dd54f03

Please sign in to comment.