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
5 changes: 5 additions & 0 deletions CONSTRUCT.md
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,11 @@ Metadata about the installer can be found in the `%INSTALLER_NAME%`,
`%INSTALLER_VER%`, `%INSTALLER_PLAT%` environment variables.
`%INSTALLER_TYPE%` is set to `EXE`.

If the uninstallation is performed with `conda-standalone`, the following
environment variables are available: `%UNINSTALLER_REMOVE_CONFIG_FILES%` (set to
`system`, `user`, or `all` if selected), `%UNINSTALLER_REMOVE_USER_DATA%` (set to `1`
if set), and `%UNINSTALLER_REMOVE_CACHES%` (set to `1` if set).

### `default_prefix`

Set default install prefix. On Linux, if not provided, the default prefix
Expand Down
5 changes: 5 additions & 0 deletions constructor/_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,11 @@ class ConstructorConfiguration(BaseModel):
Metadata about the installer can be found in the `%INSTALLER_NAME%`,
`%INSTALLER_VER%`, `%INSTALLER_PLAT%` environment variables.
`%INSTALLER_TYPE%` is set to `EXE`.

If the uninstallation is performed with `conda-standalone`, the following
environment variables are available: `%UNINSTALLER_REMOVE_CONFIG_FILES%` (set to
`system`, `user`, or `all` if selected), `%UNINSTALLER_REMOVE_USER_DATA%` (set to `1`
if set), and `%UNINSTALLER_REMOVE_CACHES%` (set to `1` if set).
"""
default_prefix: NonEmptyStr | None = None
"""
Expand Down
2 changes: 1 addition & 1 deletion constructor/data/construct.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -1072,7 +1072,7 @@
}
],
"default": null,
"description": "Path to a pre uninstall script. This is only supported on Windows, and must be a `.bat` file. Installation path is available as `%PREFIX%`. Metadata about the installer can be found in the `%INSTALLER_NAME%`, `%INSTALLER_VER%`, `%INSTALLER_PLAT%` environment variables. `%INSTALLER_TYPE%` is set to `EXE`.",
"description": "Path to a pre uninstall script. This is only supported on Windows, and must be a `.bat` file. Installation path is available as `%PREFIX%`. Metadata about the installer can be found in the `%INSTALLER_NAME%`, `%INSTALLER_VER%`, `%INSTALLER_PLAT%` environment variables. `%INSTALLER_TYPE%` is set to `EXE`.\nIf the uninstallation is performed with `conda-standalone`, the following environment variables are available: `%UNINSTALLER_REMOVE_CONFIG_FILES%` (set to `system`, `user`, or `all` if selected), `%UNINSTALLER_REMOVE_USER_DATA%` (set to `1` if set), and `%UNINSTALLER_REMOVE_CACHES%` (set to `1` if set).",
"title": "Pre Uninstall"
},
"progress_notifications": {
Expand Down
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
5 changes: 5 additions & 0 deletions docs/source/construct-yaml.md
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,11 @@ Metadata about the installer can be found in the `%INSTALLER_NAME%`,
`%INSTALLER_VER%`, `%INSTALLER_PLAT%` environment variables.
`%INSTALLER_TYPE%` is set to `EXE`.

If the uninstallation is performed with `conda-standalone`, the following
environment variables are available: `%UNINSTALLER_REMOVE_CONFIG_FILES%` (set to
`system`, `user`, or `all` if selected), `%UNINSTALLER_REMOVE_USER_DATA%` (set to `1`
if set), and `%UNINSTALLER_REMOVE_CACHES%` (set to `1` if set).

### `default_prefix`

Set default install prefix. On Linux, if not provided, the default prefix
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