Skip to content

"spack uninstall": don't modify env#33711

Merged
scheibelp merged 24 commits intospack:developfrom
scheibelp:features/uninstall-dont-modify-env2
Nov 8, 2022
Merged

"spack uninstall": don't modify env#33711
scheibelp merged 24 commits intospack:developfrom
scheibelp:features/uninstall-dont-modify-env2

Conversation

@scheibelp
Copy link
Copy Markdown
Member

@scheibelp scheibelp commented Nov 4, 2022

Supersedes #26766

This is a redo of #26766. I found it problematic to merge (even after applying spack style --fix to the affected files, the merge listed a bunch of conflicts that seemed more effort than they were worth to resolve compared to "manual" merge).

All the desired behaviors from #26766 (comment) apply here. I need to do a more comprehensive examination of the underlying and related logic to know if more-extensive changes are required, but FWIW porting the statements over was straightforward.

@spackbot-app spackbot-app bot added commands core PR affects Spack core functionality tests General test capability(ies) labels Nov 4, 2022
" they are also used by another environment: {speclist}".format(
speclist=", ".join(x.name for x in remove_only)
)
)
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This is intended to resolve #26766 (comment) - I assume we don't want to record this as an error, since we want to support it.

All other comments from #26766 (review) are addressed without any caveats.

find = SpackCommand("find")

@pytest.fixture
def environment_setup(self, mutable_mock_env_path, config, mock_packages, mutable_database):
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

These should use the install_mockery fixture, then you won't need to specify fake for all the installs

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Your suggestion is necessary as otherwise I will modify the real spack store, but --fake is still needed since the packages I'm using aren't legitimately install-able

@scheibelp scheibelp changed the title [WIP] "spack uninstall": don't modify env (part 2) "spack uninstall": don't modify env (part 2) Nov 7, 2022
with pytest.raises(
spack.error.SpackError,
match=r".*Will not uninstall.*There are still dependents.*use `spack env remove`",
):
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@becker33 this is my current attempt at following #33711 (comment) , and something I'm doing is incorrect and I also am having trouble following the logic to see how this output would make it into the exception: I assumed it wouldn't based on reading main.py:SpackCommand.__call__, but as noted in this comment, there are tests which seem to be able to examine output.

I'll note one difference between this and test/cmd/install.py:test_install_invalid_spec is that the error is actually raised as an exception (via parse.py) which triggers:

            except BaseException as e:
                tty.debug(e)
                self.error = e
                if fail_on_error:
                    self._log_command_output(out)
                    raise

So that's my theory of why tests which check for failures in commands typically run with fail_on_error=False (I originally copied this strategy from looking elsewhere, which is admittedly naive but on further inspection it would seem necessary pending a refactor of SpackCommand).

@scheibelp scheibelp enabled auto-merge (squash) November 8, 2022 00:25
@scheibelp scheibelp merged commit 1a34156 into spack:develop Nov 8, 2022
@tgamblin tgamblin changed the title "spack uninstall": don't modify env (part 2) "spack uninstall": don't modify env Nov 8, 2022
charmoniumQ pushed a commit to charmoniumQ/spack that referenced this pull request Nov 19, 2022
"spack install foo" no longer adds package "foo" to the environment
(i.e. to the list of root specs) by default: you must specify "--add".
Likewise "spack uninstall foo" no longer removes package "foo" from
the environment: you must specify --remove. Generally this means
that install/uninstall commands will no longer modify the users list
of root specs (which many users found problematic: they had to
deactivate an environment if they wanted to uninstall a spec without
changing their spack.yaml description).

In more detail: if you have environments e1 and e2, and specs [P, Q, R]
such that P depends on R, Q depends on R, [P, R] are in e1, and [Q, R]
are in e2:

* `spack uninstall --dependents --remove r` in e1: removes R from e1
  (but does not uninstall it) and uninstalls (and removes) P
* `spack uninstall -f --dependents r` in e1: will uninstall P, Q, and
   R (i.e. e2 will have dependent specs uninstalled as a side effect)
* `spack uninstall -f --dependents --remove r` in e1: this uninstalls
   P, Q, and R, and removes [P, R] from e1
* `spack uninstall -f --remove r` in e1: uninstalls R (so it is
  "missing" in both environments) and removes R from e1 (note that e1
  would still install R as a dependency of P, but it would no longer
  be listed as a root spec)
* `spack uninstall --dependents r` in e1: will fail because e2 needs R

Individual unit tests were created for each of these scenarios.
amd-toolchain-support pushed a commit to amd-toolchain-support/spack that referenced this pull request Feb 16, 2023
"spack install foo" no longer adds package "foo" to the environment
(i.e. to the list of root specs) by default: you must specify "--add".
Likewise "spack uninstall foo" no longer removes package "foo" from
the environment: you must specify --remove. Generally this means
that install/uninstall commands will no longer modify the users list
of root specs (which many users found problematic: they had to
deactivate an environment if they wanted to uninstall a spec without
changing their spack.yaml description).

In more detail: if you have environments e1 and e2, and specs [P, Q, R]
such that P depends on R, Q depends on R, [P, R] are in e1, and [Q, R]
are in e2:

* `spack uninstall --dependents --remove r` in e1: removes R from e1
  (but does not uninstall it) and uninstalls (and removes) P
* `spack uninstall -f --dependents r` in e1: will uninstall P, Q, and
   R (i.e. e2 will have dependent specs uninstalled as a side effect)
* `spack uninstall -f --dependents --remove r` in e1: this uninstalls
   P, Q, and R, and removes [P, R] from e1
* `spack uninstall -f --remove r` in e1: uninstalls R (so it is
  "missing" in both environments) and removes R from e1 (note that e1
  would still install R as a dependency of P, but it would no longer
  be listed as a root spec)
* `spack uninstall --dependents r` in e1: will fail because e2 needs R

Individual unit tests were created for each of these scenarios.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

commands core PR affects Spack core functionality tests General test capability(ies)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants