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" modid = "hexcasting"
book = "hexcasting:thehexbook" book = "hexcasting:thehexbook"
url = "https://gamma-delta.github.io/HexMod" url = "https://gamma-delta.github.io/HexMod"
default_lang = "en_us" default_lang = "en_us"
# top takes priority resource_dirs = [ # top takes priority
resource_dirs = [
{ path = "src/hexdoc/_export/resources", reexport = false }, { path = "src/hexdoc/_export/resources", reexport = false },
"{_common.src}/main/resources", "{_common.src}/main/resources",
"{_common.src}/generated/resources", "{_common.src}/generated/resources",
@ -36,6 +33,7 @@ hexcasting = "https://raw.githubusercontent.com/gamma-delta/HexMod/main/Common/s
[template] [template]
main = "main.html.jinja" main = "main.html.jinja"
static_dir = "static"
packages = [ packages = [
"hexdoc", "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]) subprocess.run(["git", "clean", "-fdX", args.output_dir])
args.output_dir.mkdir(parents=True, exist_ok=True) args.output_dir.mkdir(parents=True, exist_ok=True)
static_dir = Path("static") static_dir = props.template.static_dir
if static_dir.is_dir(): if static_dir and static_dir.is_dir():
shutil.copytree(static_dir, args.output_dir, dirs_exist_ok=True) shutil.copytree(static_dir, args.output_dir, dirs_exist_ok=True)
(args.output_dir / "index.html").write_text(docs, "utf-8") (args.output_dir / "index.html").write_text(docs, "utf-8")

View file

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

View file

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

View file

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