Skip to content

spack env track command#41897

Merged
tgamblin merged 26 commits intospack:developfrom
alecbcs:add/env-add-cmd
Nov 8, 2024
Merged

spack env track command#41897
tgamblin merged 26 commits intospack:developfrom
alecbcs:add/env-add-cmd

Conversation

@alecbcs
Copy link
Copy Markdown
Member

@alecbcs alecbcs commented Dec 29, 2023

This PR adds a sub-command to spack env (track) which allows users to add/link
anonymous environments into their installation as named environments. This allows
users to more easily track their installed packages and the environments they're
dependencies of. For example, with the addition of #41731 it's now easier to remove
all packages not required by any environments with,

spack gc -bE

Usage

spack env track /path/to/env
==> Linked environment in /path/to/env
==> You can activate this environment with:
==>     spack env activate env

By default track /path/to/env will use the last directory in the path as the name of
the environment. However users may customize the name of the linked environment
with -n | --name. Shown below.

spack env track /path/to/env --name foo 
==> Tracking environment in /path/to/env
==> You can activate this environment with:
==>     spack env activate foo

When removing a linked environment, Spack will remove the link to the environment
but will keep the structure of the environment within the directory. This will allow
users to remove a linked environment from their installation without deleting it from
a shared repository.

There is a spack env untrack command that can be used to only untrack a tracked
environment -- it will fail if it is used on a managed environment. Users can also use
spack env remove to untrack an environment.

This allows users to continue to share environments in git repositories while also having
the dependencies of those environments be remembered by Spack.

@spackbot-app spackbot-app bot added commands core PR affects Spack core functionality environments tests General test capability(ies) labels Dec 29, 2023
@alecbcs alecbcs requested a review from tgamblin December 29, 2023 17:26
@alecbcs
Copy link
Copy Markdown
Member Author

alecbcs commented Dec 29, 2023

@tgamblin from our conversation yesterday. Let me know what you think. I decided to use symlinks instead of the misc cache since it seems like a nice fit into existing functionality.

@alecbcs alecbcs changed the title Add mini spack env add command spack env add command Jul 12, 2024
@alecbcs alecbcs force-pushed the add/env-add-cmd branch 3 times, most recently from 8b3da95 to 50bce08 Compare August 23, 2024 23:25
Copy link
Copy Markdown
Contributor

@johnwparent johnwparent left a comment

Choose a reason for hiding this comment

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

One small issue, otherwise looks good on Windows!

johnwparent
johnwparent previously approved these changes Oct 23, 2024
Copy link
Copy Markdown
Contributor

@johnwparent johnwparent left a comment

Choose a reason for hiding this comment

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

LGTM!

@alecbcs alecbcs changed the title spack env add command spack env track command Oct 24, 2024
@alecbcs alecbcs force-pushed the add/env-add-cmd branch 5 times, most recently from 255cad7 to 2f82e71 Compare October 24, 2024 22:49
@tgamblin tgamblin added this to the v0.23 milestone Oct 25, 2024
@tgamblin tgamblin merged commit ff26d2f into spack:develop Nov 8, 2024
@alecbcs alecbcs deleted the add/env-add-cmd branch November 13, 2024 01:28
fryeguy52 pushed a commit to fryeguy52/spack that referenced this pull request Dec 17, 2024
This PR adds a sub-command to `spack env` (`track`) which allows users to add/link
anonymous environments into their installation as named environments. This allows
users to more easily track their installed packages and the environments they're
dependencies of. For example, with the addition of spack#41731 it's now easier to remove
all packages not required by any environments with,

```
spack gc -bE
```

#### Usage
```
spack env track /path/to/env
==> Linked environment in /path/to/env
==> You can activate this environment with:
==>     spack env activate env
```

By default `track /path/to/env` will use the last directory in the path as the name of 
the environment. However users may customize the name of the linked environment
with `-n | --name`. Shown below.
```
spack env track /path/to/env --name foo 
==> Tracking environment in /path/to/env
==> You can activate this environment with:
==>     spack env activate foo
```

When removing a linked environment, Spack will remove the link to the environment
but will keep the structure of the environment within the directory. This will allow
users to remove a linked environment from their installation without deleting it from
a shared repository.

There is a `spack env untrack` command that can be used to *only* untrack a tracked
environment -- it will fail if it is used on a managed environment.  Users can also use
`spack env remove` to untrack an environment.

This allows users to continue to share environments in git repositories  while also having
the dependencies of those environments be remembered by Spack.

---------

Co-authored-by: Todd Gamblin <[email protected]>
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 environments shell-support tests General test capability(ies)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants