Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
9 changes: 7 additions & 2 deletions constructor/nsis/main.nsi.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -1842,19 +1842,24 @@ Section "Uninstall"
${If} $UninstRemoveConfigFiles_User_State == ${BST_CHECKED}
${If} $UninstRemoveConfigFiles_System_State == ${BST_CHECKED}
StrCpy $R0 "$R0 --remove-config-files=all"
System::Call 'kernel32::SetEnvironmentVariable(t,t)i("UNINSTALLER_REMOVE_CONFIG_FILES", "all")'
${Else}
StrCpy $R0 "$R0 --remove-config-files=user"
System::Call 'kernel32::SetEnvironmentVariable(t,t)i("UNINSTALLER_REMOVE_CONFIG_FILES", "user")'
${EndIf}
${ElseIf} $UninstRemoveConfigFiles_System_State == ${BST_CHECKED}
StrCpy $R0 "$R0 --remove-config-files=system"
System::Call 'kernel32::SetEnvironmentVariable(t,t)i("UNINSTALLER_REMOVE_CONFIG_FILES", "system")'
${EndIf}

${If} $UninstRemoveUserData_State == ${BST_CHECKED}
StrCpy $R0 "$R0 --remove-user-data"
StrCpy $R0 "$R0 --remove-user-data"
System::Call 'kernel32::SetEnvironmentVariable(t,t)i("UNINSTALLER_REMOVE_USER_DATA", "1")'
${EndIf}

${If} $UninstRemoveCaches_State == ${BST_CHECKED}
StrCpy $R0 "$R0 --remove-caches"
StrCpy $R0 "$R0 --remove-caches"
System::Call 'kernel32::SetEnvironmentVariable(t,t)i("UNINSTALLER_REMOVE_CACHES", "1")'
Comment thread
lrandersson marked this conversation as resolved.
${EndIf}

${Print} "Removing files and folders..."
Expand Down
19 changes: 19 additions & 0 deletions examples/uninstall_with_conda_exe/construct.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# yaml-language-server: $schema=../../constructor/data/construct.schema.json
"$schema": "../../constructor/data/construct.schema.json"

name: UninstallWithCondaExe
version: 1.0.0
installer_type: all

channels:
- https://repo.anaconda.com/pkgs/main/

specs:
- python
- conda

register_python: False
initialize_conda: False
initialize_by_default: false
uninstall_with_conda_exe: true
pre_uninstall: pre-uninstall.bat
14 changes: 14 additions & 0 deletions examples/uninstall_with_conda_exe/pre-uninstall.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
IF "%UNINSTALLER_REMOVE_USER_DATA%" == "1" (
DEL "%USER_FILES%\data"
)
IF "%UNINSTALLER_REMOVE_CACHES%" == "1" (
DEL "%USER_FILES%\cache"
)
IF DEFINED UNINSTALLER_REMOVE_CONFIG_FILES (
IF "%UNINSTALLER_REMOVE_CONFIG_FILES%" NEQ "user" (
DEL "%USER_FILES%\config_system"
)
IF "%UNINSTALLER_REMOVE_CONFIG_FILES%" NEQ "system" (
DEL "%USER_FILES%\config_user"
)
)
19 changes: 19 additions & 0 deletions news/1197-expose-uninstallation-variables
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
### Enhancements

* EXE: Expose uninstallation options as environment variables for pre-uninstallation scripts. (#1197)

### Bug fixes

* <news item>

### Deprecations

* <news item>

### Docs

* <news item>

### Other

* <news item>
22 changes: 19 additions & 3 deletions tests/test_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -1347,11 +1347,23 @@ def test_uninstallation_standalone(
remove_config_files: str | None,
tmp_path: Path,
):
recipe_path = _example_path("customize_controls")
yaml = YAML()
recipe_path = _example_path("uninstall_with_conda_exe")
input_path = tmp_path / "input"
shutil.copytree(str(recipe_path), str(input_path))
with open(input_path / "construct.yaml", "a") as construct:
construct.write("uninstall_with_conda_exe: true\n")

# Create extra files to delete in pre-uninstall script
user_files_dir = tmp_path / "user_files"
for file in ("cache", "data", "config_user", "config_system"):
(user_files_dir / file).touch()

construct_yaml_file = input_path / "construct.yaml"
with construct_yaml_file.open() as file:
construct_yaml = yaml.load(file)
construct_yaml["script_env_variables"] = {"USER_FILES": str(user_files_dir)}
with construct_yaml_file.open(mode="w") as file:
yaml.dump(construct_yaml, file)

installer, install_dir = next(create_installer(input_path, tmp_path))
monkeypatch.setenv("USERPROFILE", str(tmp_path))
_run_installer(
Expand Down Expand Up @@ -1398,6 +1410,10 @@ def test_uninstallation_standalone(
assert pkg_cache.exists() != remove_caches
assert system_rc.exists() != remove_system_rcs
assert user_rc.exists() != remove_user_rcs
assert (user_files_dir / "data").exists() != remove_user_data
assert (user_files_dir / "cache").exists() != remove_caches
assert (user_files_dir / "config_system").exists() != remove_system_rcs
assert (user_files_dir / "config_user").exists() != remove_user_rcs
finally:
if system_rc.parent.exists():
shutil.rmtree(system_rc.parent)
Expand Down
Loading