diff --git a/constructor/briefcase/run_installation.bat b/constructor/briefcase/run_installation.bat index 1abdc7066..8519fb8ee 100644 --- a/constructor/briefcase/run_installation.bat +++ b/constructor/briefcase/run_installation.bat @@ -45,7 +45,8 @@ rem Set CONDA_QUIET primarily to disable the spinners set CONDA_QUIET={{ 0 if add_debug else 1 }} rem Get the name of the install directory -for %%I in ("%INSTDIR%") do set "APPNAME=%%~nxI" +for %%I in ("%INSTDIR%") do set "DISTRIBUTION_NAME=%%~nxI" +set MENUINST_DISTRIBUTION_NAME=%DISTRIBUTION_NAME% set "LOG=%INSTDIR%\install.log" {%- if script_env_variables %} @@ -128,6 +129,16 @@ if "%ALLUSERS%"=="0" ( if errorlevel 1 ( exit /b %errorlevel% ) ) +rem Persist distribution_name to menuinst.toml before installing packages. +rem This ensures the value is captured even if no packages have shortcuts. +rem At this point %BASE_PATH%\Menu has no .json files (packages not installed yet), +rem so menuinst only writes distribution_name - no shortcuts are created here. +"%CONDA_EXE%" menuinst --install -p "%BASE_PATH%" --root-prefix "%BASE_PATH%" +if errorlevel 1 ( exit /b %errorlevel% ) +if not exist "%BASE_PATH%\Menu\menuinst.toml" ( + {{ error_block('Failed to initialize shortcut configuration', 14) }} +) + {%- if has_pre_install %} rem Run user-supplied pre-install script {%- if has_pre_install_desc %} diff --git a/tests/test_examples.py b/tests/test_examples.py index 9deca5361..f7628b0c7 100644 --- a/tests/test_examples.py +++ b/tests/test_examples.py @@ -997,28 +997,35 @@ def test_example_scripts(tmp_path, request): def test_example_shortcuts(tmp_path, request): input_path = _example_path("shortcuts") for installer, install_dir in create_installer(input_path, tmp_path): + # console_shortcut package uses hardcoded "Anaconda3" in its menu definition + distribution_name = "Anaconda3" + if sys.platform == "win32": + # Verify shortcuts don't exist before installation (not leftover from previous run (since EXE/MSI run in a loop)) + for key in ("ProgramData", "AppData"): + start_menu = Path(os.environ[key]) / "Microsoft/Windows/Start Menu/Programs" + package_1 = start_menu / "Package 1" + if package_1.is_dir(): + assert not (package_1 / "A.lnk").is_file(), "A.lnk exists before installation" + assert not (package_1 / "B.lnk").is_file(), "B.lnk exists before installation" + _run_installer(input_path, installer, install_dir, request=request, uninstall=False) # check that the shortcuts are created if sys.platform == "win32": - # MSI shortcut verification expected to fail due to menuinst bug - # https://github.com/conda/menuinst/issues/453 - if installer.suffix == ".msi": - pytest.xfail("MSI shortcut verification fails due to menuinst#453") for key in ("ProgramData", "AppData"): start_menu = Path(os.environ[key]) / "Microsoft/Windows/Start Menu/Programs" package_1 = start_menu / "Package 1" - anaconda = start_menu / "Anaconda3 (64-bit)" - if package_1.is_dir() and anaconda.is_dir(): + console_shortcut_dir = start_menu / f"{distribution_name} (64-bit)" + if package_1.is_dir() and console_shortcut_dir.is_dir(): assert (package_1 / "A.lnk").is_file() assert (package_1 / "B.lnk").is_file() # The shortcut created from the 'base' env # should not exist because we filtered it out in the YAML # We do expect one shortcut from 'another_env' - assert not (anaconda / "Anaconda Prompt.lnk").is_file() - assert (anaconda / "Anaconda Prompt (another_env).lnk").is_file() + assert not (console_shortcut_dir / "Anaconda Prompt.lnk").is_file() + assert (console_shortcut_dir / "Anaconda Prompt (another_env).lnk").is_file() break else: - raise AssertionError("No shortcuts found!") + raise AssertionError(f"No shortcuts found! Expected '{distribution_name} (64-bit)'") if installer.suffix == ".msi": _run_uninstaller_msi(installer, install_dir) else: