55import logging
66import re
77import shutil
8+ import sys
89import sysconfig
910import tempfile
1011from pathlib import Path
1112from subprocess import run
1213
13- import tomli_w
14+ IS_WINDOWS = sys .platform == "win32"
15+ if IS_WINDOWS :
16+ import tomli_w
17+ else :
18+ tomli_w = None # This file is only intended for Windows use
1419
1520from . import preconda
1621from .utils import DEFAULT_REVERSE_DOMAIN_ID , copy_conda_exe , filename_dist
@@ -100,6 +105,16 @@ def get_bundle_app_name(info, name):
100105 return bundle , app_name
101106
102107
108+ def get_license (info ):
109+ """Retrieve the specified license as a dict or return a placeholder if not set."""
110+
111+ if "license_file" in info :
112+ return {"file" : info ["license_file" ]}
113+
114+ placeholder_license = Path (__file__ ).parent / "nsis" / "placeholder_license.txt"
115+ return {"file" : str (placeholder_license )} # convert to str for TOML serialization
116+
117+
103118# Create a Briefcase configuration file. Using a full TOML writer rather than a Jinja
104119# template allows us to avoid escaping strings everywhere.
105120def write_pyproject_toml (tmp_dir , info ):
@@ -110,7 +125,7 @@ def write_pyproject_toml(tmp_dir, info):
110125 "project_name" : name ,
111126 "bundle" : bundle ,
112127 "version" : version ,
113- "license" : ({ "file" : info [ "license_file" ]} if "license_file" in info else { "text" : "" } ),
128+ "license" : get_license ( info ),
114129 "app" : {
115130 app_name : {
116131 "formal_name" : f"{ info ['name' ]} { info ['version' ]} " ,
@@ -130,6 +145,9 @@ def write_pyproject_toml(tmp_dir, info):
130145
131146
132147def create (info , verbose = False ):
148+ if not IS_WINDOWS :
149+ raise Exception (f"Invalid platform '{ sys .platform } '. Only Windows is supported." )
150+
133151 tmp_dir = Path (tempfile .mkdtemp ())
134152 write_pyproject_toml (tmp_dir , info )
135153
@@ -150,7 +168,6 @@ def create(info, verbose=False):
150168 raise FileNotFoundError (
151169 f"Dependency 'briefcase' does not seem to be installed.\n Tried: { briefcase } "
152170 )
153-
154171 logger .info ("Building installer" )
155172 run (
156173 [briefcase , "package" ] + (["-v" ] if verbose else []),
0 commit comments