Skip to content

Commit

Permalink
Fix for #5
Browse files Browse the repository at this point in the history
  • Loading branch information
RhetTbull committed Feb 13, 2024
1 parent a372af5 commit 6a506bd
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ The Jinja2 template engine will replace `{{ source }}` and `{{ target }}` with t
See the [Jinja2 template documentation](https://jinja.palletsprojects.com/en/3.0.x/templates/) for more information on how to use template variables.
The package identifier, the build path, and the output file path may also be templates but they will only have access to the `app`, `version`, and `machine` variables.
The package identifier and path arguments such as the build path and the output file path may also be templates but they will only have access to the `app`, `version`, and `machine` variables.
## To Do
Expand Down
12 changes: 10 additions & 2 deletions applecrate/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def build_installer(
uninstall = validate_optional_path_extension(uninstall, "uninstall", [".sh"])
if uninstall and no_uninstall:
raise ValueError("Cannot specify both --uninstall and --no-uninstall")
install = validate_install(install)
install = validate_install(install, {"app": app, "version": version, "machine": platform.machine()})
link = validate_link(link)
license = validate_optional_path_exists(license, "license")
banner = validate_optional_path_extension(banner, "banner", [".png"])
Expand Down Expand Up @@ -350,13 +350,15 @@ def validate_optional_path_extension(path: str | os.PathLike | None, name: str,

def validate_install(
install: (Iterable[tuple[str | os.PathLike, str | os.PathLike] | list[str | os.PathLike]] | None),
data: dict[str, Any],
) -> list[tuple[pathlib.Path, pathlib.Path]]:
"""Validate build_installer install argument."""
if not install:
return []
pathlib_install = []
for src, dest in install:
src = pathlib.Path(src)
src = render_path(src, data)
if not src.exists():
raise ValueError(f"Install dir/file {src} does not exist")
dest = pathlib.Path(dest)
Expand Down Expand Up @@ -447,7 +449,13 @@ def validate_build_kwargs(**kwargs) -> dict[str, Any]:
kwargs["uninstall"] = validate_optional_path_extension(uninstall, "uninstall", [".sh"])

if install := kwargs.get("install"):
kwargs["install"] = validate_install(install)
# install needs to be rendered to ensure paths exists
data = {
"app": kwargs.get("app"),
"version": kwargs.get("version"),
"machine": platform.machine(),
}
kwargs["install"] = validate_install(install, data)

if link := kwargs.get("link"):
kwargs["link"] = validate_link(link)
Expand Down

0 comments on commit 6a506bd

Please sign in to comment.