Update hatch-gradle-version, parametrize static_dir, make exporting optional

This commit is contained in:
object-Object 2023-08-28 00:03:55 -04:00
parent 37d31c88f8
commit f7d3673376
6 changed files with 16 additions and 12 deletions

View file

@ -1,12 +1,9 @@
# general properties/settings
modid = "hexcasting"
book = "hexcasting:thehexbook"
url = "https://gamma-delta.github.io/HexMod"
default_lang = "en_us"
# top takes priority
resource_dirs = [
resource_dirs = [ # top takes priority
{ path = "src/hexdoc/_export/resources", reexport = false },
"{_common.src}/main/resources",
"{_common.src}/generated/resources",
@ -36,6 +33,7 @@ hexcasting = "https://raw.githubusercontent.com/gamma-delta/HexMod/main/Common/s
[template]
main = "main.html.jinja"
static_dir = "static"
packages = [
"hexdoc",
]

View file

@ -0,0 +1 @@
__version__ = "1.0.dev0"

View file

@ -150,8 +150,8 @@ def main(args: Args | None = None) -> None:
subprocess.run(["git", "clean", "-fdX", args.output_dir])
args.output_dir.mkdir(parents=True, exist_ok=True)
static_dir = Path("static")
if static_dir.is_dir():
static_dir = props.template.static_dir
if static_dir and static_dir.is_dir():
shutil.copytree(static_dir, args.output_dir, dirs_exist_ok=True)
(args.output_dir / "index.html").write_text(docs, "utf-8")

View file

@ -24,6 +24,7 @@ class PatternStubProps(StripHiddenModel):
class TemplateProps(StripHiddenModel):
main: str
static_dir: Path | None = None
dirs: list[Path] = Field(default_factory=list)
packages: list[tuple[str, Path]]
args: dict[str, Any]
@ -49,12 +50,12 @@ class Properties(StripHiddenModel):
the text color to the default."""
resource_dirs: list[ResourceDir]
export_dir: Path
entry_id_blacklist: set[ResourceLocation] = Field(default_factory=set)
export_dir: Path | None = None
pattern_stubs: list[PatternStubProps]
entry_id_blacklist: set[ResourceLocation] = Field(default_factory=set)
base_asset_urls: dict[str, NoTrailingSlashHttpUrl]
"""Mapping from modid to the url of that mod's `resources` directory on GitHub."""

View file

@ -43,6 +43,7 @@ class ModResourceLoader:
@contextmanager
def clean_and_load_all(cls, props: Properties) -> Iterator[Self]:
# clear the export dir so we start with a clean slate
if props.export_dir:
subprocess.run(["git", "clean", "-fdX", props.export_dir])
with ExitStack() as stack:
@ -328,6 +329,8 @@ class ModResourceLoader:
decode: Callable[[str], _T] = decode_json_dict,
export: ExportFn[_T] | None = None,
) -> None:
if not self.props.export_dir:
return
out_path = self.props.export_dir / path
logging.getLogger(__name__).debug(f"Exporting {path} to {out_path}")

View file

@ -1,5 +1,5 @@
[build-system]
requires = ["hatchling", "hatch-gradle-version>=0.2.1"]
requires = ["hatchling", "hatch-gradle-version>=0.3.0"]
build-backend = "hatchling.build"
# project metadata
@ -38,8 +38,9 @@ hexdoc = "hexdoc.hexdoc:main"
# Gradle version/deps
[tool.hatch.version]
scheme = "gradle"
source = "gradle-properties"
py-version = "1.0"
py-path = "doc/src/hexdoc/__version__.py"
# directory inclusion