Skip to content

new_installer.py: implement overwrite, keep_prefix#51622

Merged
haampie merged 4 commits intodevelopfrom
hs/fix/overwrite-install
Nov 25, 2025
Merged

new_installer.py: implement overwrite, keep_prefix#51622
haampie merged 4 commits intodevelopfrom
hs/fix/overwrite-install

Conversation

@haampie
Copy link
Copy Markdown
Member

@haampie haampie commented Nov 21, 2025

Implement --overwrite and --keep-prefix for the new installer.
This also adds support for installing "develop" specs with dev_path=
variant, as they rely on overwrite installs.

Add PrefixPivoter context manager to handle installation prefix management
during overwrite installations. When overwrite=True, existing installations
are backed up before the new install begins, and restored on failure. The
keep_prefix option controls whether failed installations are preserved for
debugging (when not overwriting).

Priority order for failure handling:

  1. overwrite=True always restores original prefix
  2. keep_prefix=False removes failed installation
  3. keep_prefix=True preserves failed installation

Also update BuildGraph to skip pruning specs in the overwrite set, ensuring
they are reinstalled even if already in the database.

Recovery of the old install dir on failure during overwrite installs is
prioritized by running

  1. rename(prefix, garbage)
  2. rename(old_prefix, prefix)
  3. remove garbage dir recursively, allowing failure

Failure to clean the garbage dir is not an error, it should be a unique dir
name and easy to clean manually (if ever needed).

Cleanup of install prefixes happens in the child process, in contrast to the
old installer.py. This avoids a blocking operation in the UI process.

Adds unit tests which run in 0.1s.

Add PrefixPivoter context manager to handle installation prefix
management during overwrite installations. When overwrite=True,
existing installations are backed up before the new install begins,
and restored on failure. The keep_prefix option controls whether
failed installations are preserved for debugging (when not
overwriting).

Priority order for failure handling:
1. overwrite=True always restores original prefix
2. keep_prefix=False removes failed installation
3. keep_prefix=True preserves failed installation

Also update BuildGraph to skip pruning specs in the overwrite set,
ensuring they are reinstalled even if already in the database.

Recovery of the install dir on install failure during overwrite installs
is prioritized by running

- `rename(prefix, garbage)`
- `rename(old_prefix, prefix)
- remove garbage, allowing failure

Failure to clean the garbage dir is not an error, it should be a unique
dir name and easy to clean manually (if ever needed)

Signed-off-by: Harmen Stoppels <[email protected]>
@haampie haampie force-pushed the hs/fix/overwrite-install branch from 71792d3 to a5b7758 Compare November 21, 2025 12:38
when something is installed but marked for overwrite, we should not
prune it from the build graph

Signed-off-by: Harmen Stoppels <[email protected]>
Signed-off-by: Harmen Stoppels <[email protected]>
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR implements overwrite and keep_prefix functionality for the new installer, adding robust prefix management during package installations. The implementation introduces a PrefixPivoter context manager that handles backing up existing installations during overwrites and cleaning up failed installations based on the specified options.

Key changes:

  • Added PrefixPivoter context manager for installation prefix lifecycle management
  • Modified BuildGraph to skip pruning specs in the overwrite set
  • Refactored installation logic by extracting _install() function from worker_function()

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
lib/spack/spack/new_installer.py Implements PrefixPivoter class for prefix management, adds overwrite/keep_prefix parameters throughout the installation pipeline, and refactors worker_function to delegate installation to _install()
lib/spack/spack/test/test_new_installer.py Adds comprehensive unit tests for PrefixPivoter covering success/failure scenarios, overwrite behavior, keep_prefix options, and failure recovery edge cases
lib/spack/spack/test/installer_build_graph.py Adds test to verify that specs in overwrite_set are not pruned from the build graph even when already installed

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Signed-off-by: Harmen Stoppels <[email protected]>
@alalazo alalazo self-assigned this Nov 25, 2025
@haampie haampie merged commit ae56830 into develop Nov 25, 2025
31 of 32 checks passed
@haampie haampie deleted the hs/fix/overwrite-install branch November 25, 2025 13:25
psakievich pushed a commit to psakievich/spack that referenced this pull request Dec 1, 2025
Implement `--overwrite` and `--keep-prefix` for the new installer.
This also adds support for installing "develop" specs with `dev_path=`
variant, as they rely on overwrite installs.

Add `PrefixPivoter` context manager to handle installation prefix management
during overwrite installations. When `overwrite=True`, existing installations
are backed up before the new install begins, and restored on failure. The
`keep_prefix` option controls whether failed installations are preserved for
debugging (when not overwriting).

Priority order for failure handling:
1. `overwrite=True` always restores original prefix
2. `keep_prefix=False` removes failed installation
3. `keep_prefix=True` preserves failed installation

Also update `BuildGraph` to skip pruning specs in the overwrite set, ensuring
they are reinstalled even if already in the database.

Recovery of the old install dir on failure during overwrite installs is
prioritized by running

1. `rename(prefix, garbage)`
2. `rename(old_prefix, prefix)`
3. remove garbage dir recursively, allowing failure

Failure to clean the garbage dir is not an error, it should be a unique dir
name and easy to clean manually (if ever needed).

Cleanup of install prefixes happens in the child process, in contrast to the
old `installer.py`. This avoids a blocking operation in the UI process.

Adds unit tests which run in 0.1s.
hippo91 pushed a commit to hippo91/spack that referenced this pull request Dec 1, 2025
Implement `--overwrite` and `--keep-prefix` for the new installer.
This also adds support for installing "develop" specs with `dev_path=`
variant, as they rely on overwrite installs.

Add `PrefixPivoter` context manager to handle installation prefix management
during overwrite installations. When `overwrite=True`, existing installations
are backed up before the new install begins, and restored on failure. The
`keep_prefix` option controls whether failed installations are preserved for
debugging (when not overwriting).

Priority order for failure handling:
1. `overwrite=True` always restores original prefix
2. `keep_prefix=False` removes failed installation
3. `keep_prefix=True` preserves failed installation

Also update `BuildGraph` to skip pruning specs in the overwrite set, ensuring
they are reinstalled even if already in the database.

Recovery of the old install dir on failure during overwrite installs is
prioritized by running

1. `rename(prefix, garbage)`
2. `rename(old_prefix, prefix)`
3. remove garbage dir recursively, allowing failure

Failure to clean the garbage dir is not an error, it should be a unique dir
name and easy to clean manually (if ever needed).

Cleanup of install prefixes happens in the child process, in contrast to the
old `installer.py`. This avoids a blocking operation in the UI process.

Adds unit tests which run in 0.1s.
@becker33 becker33 mentioned this pull request Jan 11, 2026
2 tasks
becker33 pushed a commit that referenced this pull request Jan 11, 2026
Implement `--overwrite` and `--keep-prefix` for the new installer.
This also adds support for installing "develop" specs with `dev_path=`
variant, as they rely on overwrite installs.

Add `PrefixPivoter` context manager to handle installation prefix management
during overwrite installations. When `overwrite=True`, existing installations
are backed up before the new install begins, and restored on failure. The
`keep_prefix` option controls whether failed installations are preserved for
debugging (when not overwriting).

Priority order for failure handling:
1. `overwrite=True` always restores original prefix
2. `keep_prefix=False` removes failed installation
3. `keep_prefix=True` preserves failed installation

Also update `BuildGraph` to skip pruning specs in the overwrite set, ensuring
they are reinstalled even if already in the database.

Recovery of the old install dir on failure during overwrite installs is
prioritized by running

1. `rename(prefix, garbage)`
2. `rename(old_prefix, prefix)`
3. remove garbage dir recursively, allowing failure

Failure to clean the garbage dir is not an error, it should be a unique dir
name and easy to clean manually (if ever needed).

Cleanup of install prefixes happens in the child process, in contrast to the
old `installer.py`. This avoids a blocking operation in the UI process.

Adds unit tests which run in 0.1s.
becker33 pushed a commit that referenced this pull request Jan 11, 2026
Implement `--overwrite` and `--keep-prefix` for the new installer.
This also adds support for installing "develop" specs with `dev_path=`
variant, as they rely on overwrite installs.

Add `PrefixPivoter` context manager to handle installation prefix management
during overwrite installations. When `overwrite=True`, existing installations
are backed up before the new install begins, and restored on failure. The
`keep_prefix` option controls whether failed installations are preserved for
debugging (when not overwriting).

Priority order for failure handling:
1. `overwrite=True` always restores original prefix
2. `keep_prefix=False` removes failed installation
3. `keep_prefix=True` preserves failed installation

Also update `BuildGraph` to skip pruning specs in the overwrite set, ensuring
they are reinstalled even if already in the database.

Recovery of the old install dir on failure during overwrite installs is
prioritized by running

1. `rename(prefix, garbage)`
2. `rename(old_prefix, prefix)`
3. remove garbage dir recursively, allowing failure

Failure to clean the garbage dir is not an error, it should be a unique dir
name and easy to clean manually (if ever needed).

Cleanup of install prefixes happens in the child process, in contrast to the
old `installer.py`. This avoids a blocking operation in the UI process.

Adds unit tests which run in 0.1s.

Signed-off-by: Gregory Becker <[email protected]>
becker33 pushed a commit that referenced this pull request Jan 12, 2026
Implement `--overwrite` and `--keep-prefix` for the new installer.
This also adds support for installing "develop" specs with `dev_path=`
variant, as they rely on overwrite installs.

Add `PrefixPivoter` context manager to handle installation prefix management
during overwrite installations. When `overwrite=True`, existing installations
are backed up before the new install begins, and restored on failure. The
`keep_prefix` option controls whether failed installations are preserved for
debugging (when not overwriting).

Priority order for failure handling:
1. `overwrite=True` always restores original prefix
2. `keep_prefix=False` removes failed installation
3. `keep_prefix=True` preserves failed installation

Also update `BuildGraph` to skip pruning specs in the overwrite set, ensuring
they are reinstalled even if already in the database.

Recovery of the old install dir on failure during overwrite installs is
prioritized by running

1. `rename(prefix, garbage)`
2. `rename(old_prefix, prefix)`
3. remove garbage dir recursively, allowing failure

Failure to clean the garbage dir is not an error, it should be a unique dir
name and easy to clean manually (if ever needed).

Cleanup of install prefixes happens in the child process, in contrast to the
old `installer.py`. This avoids a blocking operation in the UI process.

Adds unit tests which run in 0.1s.

Signed-off-by: Gregory Becker <[email protected]>
becker33 pushed a commit that referenced this pull request Jan 15, 2026
Implement `--overwrite` and `--keep-prefix` for the new installer.
This also adds support for installing "develop" specs with `dev_path=`
variant, as they rely on overwrite installs.

Add `PrefixPivoter` context manager to handle installation prefix management
during overwrite installations. When `overwrite=True`, existing installations
are backed up before the new install begins, and restored on failure. The
`keep_prefix` option controls whether failed installations are preserved for
debugging (when not overwriting).

Priority order for failure handling:
1. `overwrite=True` always restores original prefix
2. `keep_prefix=False` removes failed installation
3. `keep_prefix=True` preserves failed installation

Also update `BuildGraph` to skip pruning specs in the overwrite set, ensuring
they are reinstalled even if already in the database.

Recovery of the old install dir on failure during overwrite installs is
prioritized by running

1. `rename(prefix, garbage)`
2. `rename(old_prefix, prefix)`
3. remove garbage dir recursively, allowing failure

Failure to clean the garbage dir is not an error, it should be a unique dir
name and easy to clean manually (if ever needed).

Cleanup of install prefixes happens in the child process, in contrast to the
old `installer.py`. This avoids a blocking operation in the UI process.

Adds unit tests which run in 0.1s.

Signed-off-by: Gregory Becker <[email protected]>
vjranagit pushed a commit to vjranagit/spack that referenced this pull request Jan 18, 2026
Implement `--overwrite` and `--keep-prefix` for the new installer.
This also adds support for installing "develop" specs with `dev_path=`
variant, as they rely on overwrite installs.

Add `PrefixPivoter` context manager to handle installation prefix management
during overwrite installations. When `overwrite=True`, existing installations
are backed up before the new install begins, and restored on failure. The
`keep_prefix` option controls whether failed installations are preserved for
debugging (when not overwriting).

Priority order for failure handling:
1. `overwrite=True` always restores original prefix
2. `keep_prefix=False` removes failed installation
3. `keep_prefix=True` preserves failed installation

Also update `BuildGraph` to skip pruning specs in the overwrite set, ensuring
they are reinstalled even if already in the database.

Recovery of the old install dir on failure during overwrite installs is
prioritized by running

1. `rename(prefix, garbage)`
2. `rename(old_prefix, prefix)`
3. remove garbage dir recursively, allowing failure

Failure to clean the garbage dir is not an error, it should be a unique dir
name and easy to clean manually (if ever needed).

Cleanup of install prefixes happens in the child process, in contrast to the
old `installer.py`. This avoids a blocking operation in the UI process.

Adds unit tests which run in 0.1s.

Signed-off-by: Gregory Becker <[email protected]>
becker33 pushed a commit that referenced this pull request Jan 22, 2026
Implement `--overwrite` and `--keep-prefix` for the new installer.
This also adds support for installing "develop" specs with `dev_path=`
variant, as they rely on overwrite installs.

Add `PrefixPivoter` context manager to handle installation prefix management
during overwrite installations. When `overwrite=True`, existing installations
are backed up before the new install begins, and restored on failure. The
`keep_prefix` option controls whether failed installations are preserved for
debugging (when not overwriting).

Priority order for failure handling:
1. `overwrite=True` always restores original prefix
2. `keep_prefix=False` removes failed installation
3. `keep_prefix=True` preserves failed installation

Also update `BuildGraph` to skip pruning specs in the overwrite set, ensuring
they are reinstalled even if already in the database.

Recovery of the old install dir on failure during overwrite installs is
prioritized by running

1. `rename(prefix, garbage)`
2. `rename(old_prefix, prefix)`
3. remove garbage dir recursively, allowing failure

Failure to clean the garbage dir is not an error, it should be a unique dir
name and easy to clean manually (if ever needed).

Cleanup of install prefixes happens in the child process, in contrast to the
old `installer.py`. This avoids a blocking operation in the UI process.

Adds unit tests which run in 0.1s.

Signed-off-by: Gregory Becker <[email protected]>
becker33 pushed a commit that referenced this pull request Jan 26, 2026
Implement `--overwrite` and `--keep-prefix` for the new installer.
This also adds support for installing "develop" specs with `dev_path=`
variant, as they rely on overwrite installs.

Add `PrefixPivoter` context manager to handle installation prefix management
during overwrite installations. When `overwrite=True`, existing installations
are backed up before the new install begins, and restored on failure. The
`keep_prefix` option controls whether failed installations are preserved for
debugging (when not overwriting).

Priority order for failure handling:
1. `overwrite=True` always restores original prefix
2. `keep_prefix=False` removes failed installation
3. `keep_prefix=True` preserves failed installation

Also update `BuildGraph` to skip pruning specs in the overwrite set, ensuring
they are reinstalled even if already in the database.

Recovery of the old install dir on failure during overwrite installs is
prioritized by running

1. `rename(prefix, garbage)`
2. `rename(old_prefix, prefix)`
3. remove garbage dir recursively, allowing failure

Failure to clean the garbage dir is not an error, it should be a unique dir
name and easy to clean manually (if ever needed).

Cleanup of install prefixes happens in the child process, in contrast to the
old `installer.py`. This avoids a blocking operation in the UI process.

Adds unit tests which run in 0.1s.

Signed-off-by: Gregory Becker <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants