3030from .construct import parse as construct_parse
3131from .construct import render as construct_render
3232from .construct import verify as construct_verify
33+ from .exceptions import InvalidInstallerTypeError
3334from .fcp import main as fcp_main
3435from .utils import (
3536 StandaloneExe ,
4647
4748
4849def get_installer_type (info : dict ):
50+ """Return the installer type(s) to build for the given platform.
51+
52+ Raises
53+ ------
54+ InvalidInstallerTypeError
55+ If the installer type is not valid for the target platform.
56+ """
4957 osname , unused_arch = info ["_platform" ].split ("-" )
5058
5159 os_allowed = {"linux" : ("sh" ,), "osx" : ("sh" , "pkg" ), "win" : ("exe" , "msi" )}
@@ -62,28 +70,31 @@ def get_installer_type(info: dict):
6270 for t in itype :
6371 if t not in all_allowed :
6472 all_allowed_str = ", " .join (sorted (all_allowed ))
65- sys .exit ("Error: invalid installer type '%s'; allowed: %s" % (t , all_allowed_str ))
73+ raise InvalidInstallerTypeError (
74+ f"invalid installer type '{ t } '; allowed: { all_allowed_str } "
75+ )
6676 if t not in os_allowed [osname ]:
6777 os_allowed_str = ", " .join (sorted (os_allowed [osname ]))
68- sys .exit (
69- "Error: invalid installer type '%s' for %s; allowed: %s"
70- % (t , osname , os_allowed_str )
78+ raise InvalidInstallerTypeError (
79+ f"invalid installer type '{ t } ' for { osname } ; allowed: { os_allowed_str } "
7180 )
7281 return tuple (itype )
7382 elif itype not in all_allowed :
74- all_allowed = ", " .join (sorted (all_allowed ))
75- sys .exit ("Error: invalid installer type '%s'; allowed: %s" % (itype , all_allowed ))
83+ all_allowed_str = ", " .join (sorted (all_allowed ))
84+ raise InvalidInstallerTypeError (
85+ f"invalid installer type '{ itype } '; allowed: { all_allowed_str } "
86+ )
7687 elif itype == "docker" :
7788 if osname != "linux" :
78- sys . exit (
79- "Error: Docker features are only supported for Linux target platforms. "
89+ raise InvalidInstallerTypeError (
90+ "Docker features are only supported for Linux target platforms. "
8091 "Use --platform linux-ARCH to build a Docker artifact."
8192 )
8293 return ("sh" , "docker" )
8394 elif itype not in os_allowed [osname ]:
84- os_allowed = ", " .join (sorted (os_allowed [osname ]))
85- sys . exit (
86- "Error: invalid installer type '%s ' for %s ; allowed: %s" % ( itype , osname , os_allowed )
95+ os_allowed_str = ", " .join (sorted (os_allowed [osname ]))
96+ raise InvalidInstallerTypeError (
97+ f" invalid installer type '{ itype } ' for { osname } ; allowed: { os_allowed_str } "
8798 )
8899 else :
89100 return (itype ,)
@@ -234,7 +245,10 @@ def main_build(
234245 info ["_debug" ] = debug
235246 if installer_type :
236247 info ["installer_type" ] = installer_type
237- itypes = get_installer_type (info )
248+ try :
249+ itypes = get_installer_type (info )
250+ except InvalidInstallerTypeError as e :
251+ sys .exit (f"Error: { e } " )
238252
239253 if "docker" in itypes :
240254 if not info .get ("docker_base_image" ):
0 commit comments