Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions constructor/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,9 @@ def error_body(self):
"""),
]
)


class InvalidInstallerTypeError(Exception):
"""Raised when installer_type is invalid for the target platform."""

pass
38 changes: 26 additions & 12 deletions constructor/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
from .construct import parse as construct_parse
from .construct import render as construct_render
from .construct import verify as construct_verify
from .exceptions import InvalidInstallerTypeError
from .fcp import main as fcp_main
from .utils import (
StandaloneExe,
Expand All @@ -46,6 +47,13 @@


def get_installer_type(info: dict):
"""Return the installer type(s) to build for the given platform.

Raises
------
InvalidInstallerTypeError
If the installer type is not valid for the target platform.
"""
osname, unused_arch = info["_platform"].split("-")

os_allowed = {"linux": ("sh",), "osx": ("sh", "pkg"), "win": ("exe", "msi")}
Expand All @@ -62,28 +70,31 @@ def get_installer_type(info: dict):
for t in itype:
if t not in all_allowed:
all_allowed_str = ", ".join(sorted(all_allowed))
sys.exit("Error: invalid installer type '%s'; allowed: %s" % (t, all_allowed_str))
raise InvalidInstallerTypeError(
f"invalid installer type '{t}'; allowed: {all_allowed_str}"
)
if t not in os_allowed[osname]:
os_allowed_str = ", ".join(sorted(os_allowed[osname]))
sys.exit(
"Error: invalid installer type '%s' for %s; allowed: %s"
% (t, osname, os_allowed_str)
raise InvalidInstallerTypeError(
f"invalid installer type '{t}' for {osname}; allowed: {os_allowed_str}"
)
return tuple(itype)
elif itype not in all_allowed:
all_allowed = ", ".join(sorted(all_allowed))
sys.exit("Error: invalid installer type '%s'; allowed: %s" % (itype, all_allowed))
all_allowed_str = ", ".join(sorted(all_allowed))
raise InvalidInstallerTypeError(
f"invalid installer type '{itype}'; allowed: {all_allowed_str}"
)
elif itype == "docker":
if osname != "linux":
sys.exit(
"Error: Docker features are only supported for Linux target platforms. "
raise InvalidInstallerTypeError(
"Docker features are only supported for Linux target platforms. "
"Use --platform linux-ARCH to build a Docker artifact."
)
return ("sh", "docker")
elif itype not in os_allowed[osname]:
os_allowed = ", ".join(sorted(os_allowed[osname]))
sys.exit(
"Error: invalid installer type '%s' for %s; allowed: %s" % (itype, osname, os_allowed)
os_allowed_str = ", ".join(sorted(os_allowed[osname]))
raise InvalidInstallerTypeError(
f"invalid installer type '{itype}' for {osname}; allowed: {os_allowed_str}"
)
else:
return (itype,)
Expand Down Expand Up @@ -234,7 +245,10 @@ def main_build(
info["_debug"] = debug
if installer_type:
info["installer_type"] = installer_type
itypes = get_installer_type(info)
try:
itypes = get_installer_type(info)
except InvalidInstallerTypeError as e:
sys.exit(f"Error: {e}")

if "docker" in itypes:
if not info.get("docker_base_image"):
Expand Down
4 changes: 3 additions & 1 deletion examples/azure_signtool/construct.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@

name: Signed_AzureSignTool
version: 1.0.0
installer_type: [exe, msi]
installer_type:
- exe
- msi
channels:
- https://repo.anaconda.com/pkgs/main/
specs:
Expand Down
Loading
Loading