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
3 changes: 2 additions & 1 deletion constructor/briefcase.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,8 @@ def create_install_options_list(info: dict) -> list[dict]:
"name": f"{script_type}_install_script",
"title": f"{script_type.capitalize()}-install script",
"description": script_description,
"default": False,
# Mirror NSIS: default to enabled when the script exists.
"default": bool(script),
}
)

Expand Down
22 changes: 13 additions & 9 deletions examples/scripts/post_install.bat
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,23 @@ echo Added by post-install script > "%PREFIX%\post_install_sentinel.txt"
if not "%INSTALLER_NAME%" == "Scripts" exit 1
if not "%INSTALLER_VER%" == "1.0.0" exit 1
if not "%INSTALLER_PLAT%" == "win-64" exit 1
if not "%INSTALLER_TYPE%" == "EXE" exit 1
if not "%INSTALLER_UNATTENDED%" == "1" exit 1
if not "%INSTALLER_TYPE%" == "EXE" if not "%INSTALLER_TYPE%" == "MSI" exit 1
rem INSTALLER_UNATTENDED is not yet set by MSI installers (see conda/constructor#1276).
if "%INSTALLER_TYPE%" == "EXE" if not "%INSTALLER_UNATTENDED%" == "1" exit 1
if "%PREFIX%" == "" exit 1
if not "%CUSTOM_VARIABLE_1%" == "FIR$T-CUSTOM_STRING WITH SPACES AND @*! CHARACTERS" exit 1
if not "%CUSTOM_VARIABLE_2%" == "$ECOND-CUSTOM_STRING WITH SPACES AND @*! CHARACTERS" exit 1
if not exist "%PREFIX%\pre_install_sentinel.txt" exit 1

if not exist "%INSTALLER_PATH%" (
echo ERROR: "INSTALLER_PATH=%INSTALLER_PATH%" points to a file that does not exist!
exit 1
)
rem INSTALLER_PATH and INSTALLER_PLUGINSDIR are only set by EXE installers.
if "%INSTALLER_TYPE%" == "EXE" (
if not exist "%INSTALLER_PATH%" (
echo ERROR: "INSTALLER_PATH=%INSTALLER_PATH%" points to a file that does not exist!
exit 1
)

if not exist "%INSTALLER_PLUGINSDIR%" (
echo ERROR: "INSTALLER_PLUGINSDIR=%INSTALLER_PLUGINSDIR%" points to a directory that does not exist!
exit 1
if not exist "%INSTALLER_PLUGINSDIR%" (
echo ERROR: "INSTALLER_PLUGINSDIR=%INSTALLER_PLUGINSDIR%" points to a directory that does not exist!
exit 1
)
)
5 changes: 3 additions & 2 deletions examples/scripts/pre_install.bat
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
if not "%INSTALLER_NAME%" == "Scripts" exit 1
if not "%INSTALLER_VER%" == "1.0.0" exit 1
if not "%INSTALLER_PLAT%" == "win-64" exit 1
if not "%INSTALLER_TYPE%" == "EXE" exit 1
if not "%INSTALLER_UNATTENDED%" == "1" exit 1
if not "%INSTALLER_TYPE%" == "EXE" if not "%INSTALLER_TYPE%" == "MSI" exit 1
rem INSTALLER_UNATTENDED is not yet set by MSI installers (see conda/constructor#1276).
if "%INSTALLER_TYPE%" == "EXE" if not "%INSTALLER_UNATTENDED%" == "1" exit 1
if "%PREFIX%" == "" exit 1
if not "%CUSTOM_VARIABLE_1%" == "FIR$T-CUSTOM_STRING WITH SPACES AND @*! CHARACTERS" exit 1
if not "%CUSTOM_VARIABLE_2%" == "$ECOND-CUSTOM_STRING WITH SPACES AND @*! CHARACTERS" exit 1
Expand Down
20 changes: 20 additions & 0 deletions tests/test_briefcase.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
_get_python_info,
_get_script_env_variables,
_setup_envs_commands,
create_install_options_list,
create_uninstall_options_list,
get_bundle_app_name,
get_license,
Expand Down Expand Up @@ -645,6 +646,25 @@ def test_create_uninstall_options_list():
assert "remove_config_files" in option_names


@pytest.mark.parametrize("script_type", ["pre", "post"])
def test_install_options_script_default_enabled(tmp_path, script_type):
"""Pre/post-install script options default to enabled when a script exists.

This mirrors the NSIS installer, which checks the box by default when the
script is present (see nsis/main.nsi.tmpl).
"""
script = tmp_path / f"{script_type}_install.bat"
script.write_text("@echo script")

info = mock_info.copy()
info[f"{script_type}_install"] = str(script)
info[f"{script_type}_install_desc"] = "Custom script description"

options = create_install_options_list(info)
option = next(opt for opt in options if opt["name"] == f"{script_type}_install_script")
assert option["default"] is True


def test_render_templates_with_virtual_specs():
"""Test that virtual_specs check block is rendered when specs are provided."""
info = mock_info.copy()
Expand Down
Loading