Skip to content

Commit ca0e528

Browse files
Add environment variables to pre-uninstall script (#1206)
* Increase test verbosity * DEBUG: only test conda-standalone uninstallation * Flip skip conditional * Move installer creation after file setup * Move .conda assert statement to after the installation * DEBUG: check user files directory along the way * Add script env variables to Windows uninstaller * Make macOS spelling consistent * Revert "DEBUG: only test conda-standalone uninstallation" This reverts commit 79eada3. * Add news * Apply suggestions from code review Co-authored-by: Robin <34315751+lrandersson@users.noreply.github.com> --------- Co-authored-by: Robin <34315751+lrandersson@users.noreply.github.com>
1 parent 162a5cd commit ca0e528

4 files changed

Lines changed: 43 additions & 18 deletions

File tree

.github/workflows/main.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ jobs:
138138
run: conda config --show-sources
139139
- name: Run unit tests
140140
run: |
141-
pytest -vv --cov=constructor --cov-branch tests/ -m "not examples"
141+
pytest -ra -vvv --cov=constructor --cov-branch tests/ -m "not examples"
142142
coverage run --branch --append -m constructor -V
143143
coverage json
144144
- uses: codecov/codecov-action@57e3a136b779b570ffcdbf80b3bdc90e7fab3de2 # v6.0.0
@@ -156,7 +156,7 @@ jobs:
156156
CONSTRUCTOR_SIGNTOOL_PATH: "C:/Program Files (x86)/Windows Kits/10/bin/10.0.26100.0/x86/signtool.exe"
157157
run: |
158158
rm -rf coverage.json
159-
pytest -vv --cov=constructor --cov-branch tests/test_examples.py
159+
pytest -ra -vvv --cov=constructor --cov-branch tests/test_examples.py
160160
coverage run --branch --append -m constructor -V
161161
coverage json
162162
- uses: codecov/codecov-action@57e3a136b779b570ffcdbf80b3bdc90e7fab3de2 # v6.0.0

constructor/nsis/main.nsi.tmpl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1822,6 +1822,9 @@ Section "Uninstall"
18221822
${Else}
18231823
System::Call 'kernel32::SetEnvironmentVariable(t,t)i("INSTALLER_UNATTENDED", "0")'
18241824
${EndIf}
1825+
{%- for key, escaped_val in SCRIPT_ENV_VARIABLES | items %}
1826+
System::Call 'kernel32::SetEnvironmentVariable(t,t)i("{{ key }}", {{ escaped_val }})'
1827+
{%- endfor %}
18251828

18261829
{%- if uninstall_with_conda_exe %}
18271830
# Parse uninstall options
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
### Enhancements
2+
3+
* EXE: Add script environment variables to pre-uninstall scripts. (#1206)
4+
5+
### Bug fixes
6+
7+
* <news item>
8+
9+
### Deprecations
10+
11+
* <news item>
12+
13+
### Docs
14+
15+
* <news item>
16+
17+
### Other
18+
19+
* <news item>

tests/test_examples.py

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -928,7 +928,7 @@ def test_register_envs(tmp_path, request):
928928
assert str(install_dir) not in environments_txt
929929

930930

931-
@pytest.mark.skipif(sys.platform != "darwin", reason="MacOS only")
931+
@pytest.mark.skipif(sys.platform != "darwin", reason="macOS only")
932932
@pytest.mark.parametrize("domains", ({}, {"enable_anywhere": "false", "enable_localSystem": True}))
933933
def test_pkg_distribution_domains(tmp_path, domains):
934934
recipe_path = _example_path("osxpkg")
@@ -1326,8 +1326,9 @@ def test_ignore_condarc_files(tmp_path, monkeypatch, request):
13261326

13271327

13281328
@pytest.mark.skipif(
1329-
CONDA_EXE == StandaloneExe.CONDA and check_version(CONDA_EXE_VERSION, min_version="24.11.0"),
1330-
reason="Requires conda-standalone 24.11.x or newer",
1329+
CONDA_EXE == StandaloneExe.CONDA
1330+
and not check_version(CONDA_EXE_VERSION, min_version="24.11.0"),
1331+
reason=f"Requires conda-standalone 24.11.x or newer (is {CONDA_EXE_VERSION})",
13311332
)
13321333
@pytest.mark.skipif(not sys.platform == "win32", reason="Windows only")
13331334
@pytest.mark.skipif(not ON_CI, reason="CI only - Interacts with system files")
@@ -1347,26 +1348,13 @@ def test_uninstallation_standalone(
13471348
remove_config_files: str | None,
13481349
tmp_path: Path,
13491350
):
1350-
yaml = YAML()
13511351
recipe_path = _example_path("uninstall_with_conda_exe")
13521352
input_path = tmp_path / "input"
13531353
shutil.copytree(str(recipe_path), str(input_path))
13541354

1355-
installer, install_dir = next(create_installer(input_path, tmp_path))
1356-
monkeypatch.setenv("USERPROFILE", str(tmp_path))
1357-
_run_installer(
1358-
input_path,
1359-
installer,
1360-
install_dir,
1361-
check_subprocess=True,
1362-
uninstall=False,
1363-
)
1364-
13651355
# Set up files for removal.
13661356
# Since conda-standalone is extensively tested upstream,
13671357
# only set up a minimum set of files.
1368-
dot_conda_dir = tmp_path / ".conda"
1369-
assert dot_conda_dir.exists()
13701358

13711359
# Minimum set of files needed for an index cache
13721360
pkg_cache = tmp_path / "pkgs"
@@ -1404,13 +1392,28 @@ def test_uninstallation_standalone(
14041392
for file in user_files:
14051393
(user_files_dir / file).touch()
14061394
assert (user_files_dir / file).exists()
1395+
yaml = YAML()
14071396
construct_yaml_file = input_path / "construct.yaml"
14081397
with construct_yaml_file.open() as file:
14091398
construct_yaml = yaml.load(file)
14101399
construct_yaml["script_env_variables"] = {"USER_FILES": str(user_files_dir)}
14111400
with construct_yaml_file.open(mode="w") as file:
14121401
yaml.dump(construct_yaml, file)
14131402

1403+
installer, install_dir = next(create_installer(input_path, tmp_path))
1404+
monkeypatch.setenv("USERPROFILE", str(tmp_path))
1405+
_run_installer(
1406+
input_path,
1407+
installer,
1408+
install_dir,
1409+
check_subprocess=True,
1410+
uninstall=False,
1411+
)
1412+
1413+
# Ensure that the installation has set up environments.txt
1414+
dot_conda_dir = tmp_path / ".conda"
1415+
assert dot_conda_dir.exists()
1416+
14141417
try:
14151418
_run_uninstaller_exe(install_dir, check=True, options=uninstall_options)
14161419
assert dot_conda_dir.exists() != remove_user_data

0 commit comments

Comments
 (0)