Skip to content

spack env create: allow creation from environment dir#51433

Merged
becker33 merged 11 commits intodevelopfrom
features/env-from-dir
Nov 6, 2025
Merged

spack env create: allow creation from environment dir#51433
becker33 merged 11 commits intodevelopfrom
features/env-from-dir

Conversation

@becker33
Copy link
Copy Markdown
Member

@becker33 becker33 commented Oct 13, 2025

Currently, when an environment is created from another environment's lockfile, it loses all config information. This not relevant if the environment is installed as-is, but matters when reconcretizing.

Additionally, other artifacts in the environment (such as repos or developer source) are either ignored or rewritten into absolute paths to the original environment.

This PR introduces a capability to create an environment as a copy of another entire environment. It uses the same syntax as before (spack env create myenv /path/to/env/spack.{yaml,lock}), but allows referencing the environment dir.

spack env create myenv /path/to/env

or the environment name

spack env create myenv2 myenv

This copies the entire environment dir, and only rewrites relative paths that point outside the environment (e.g. path: ../../foo).

includes unit test and docs updates.

@becker33 becker33 force-pushed the features/env-from-dir branch from 7bdf196 to 4373a47 Compare October 13, 2025 13:28
Signed-off-by: Gregory Becker <[email protected]>
Signed-off-by: Gregory Becker <[email protected]>
Signed-off-by: Gregory Becker <[email protected]>
@becker33 becker33 added the v1.1.0 PRs to backport for v1.1.0 label Oct 14, 2025
@alecbcs
Copy link
Copy Markdown
Member

alecbcs commented Oct 15, 2025

@becker33 it would be cool to extend this functionality a little to allow someone to clone a named environment -> to an independent environment in a directory like so,

$ spack env create /path/to/new/environment myoldenv

@becker33
Copy link
Copy Markdown
Member Author

@alecbcs that is already covered by this PR

@alecbcs
Copy link
Copy Markdown
Member

alecbcs commented Oct 30, 2025

Trying this PR I ran into a couple of errors on edge cases. Happy to help work on fixing these if needed.

While the following works when creating a new environment,

> spack env create .
==> Created independent environment in: /Users/scott112/src/scratch/spack-test
==> Activate with: spack env activate .

I noticed that if you attempt to do the same while cloning an existing environment it fails,

> spack env create . default
==> Error: [Errno 17] File exists: '.'

If you point to a nonexistent directory it appears to then work, but fails to generate the view.
(I think this is because the clone is copying the existing view from the other environment.)

> spack env create ./spack-env-test default
==> Created independent environment in: /path/to/spack-env-test
==> Activate with: spack env activate ./spack-env-test
==> Error: Failed to generate environment view, because the target /path/to/spack-env-test/.spack-env/._view/52zrqd743mpt4bo2evttasinwfeji2zl already exists or is not empty. To update the view, remove this path, and run `spack env view regenerate`

@becker33
Copy link
Copy Markdown
Member Author

becker33 commented Nov 4, 2025

I think it's more accurate to say it emits an error about the view -- you're right that the problem is that the view already exists.

Copy link
Copy Markdown
Member

@alecbcs alecbcs left a comment

Choose a reason for hiding this comment

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

Looks good to me. @becker33 feel free to merge when ready.

I do not believe the GitLab CI failure is related.

@becker33 becker33 merged commit 1f58a5a into develop Nov 6, 2025
31 of 32 checks passed
@becker33 becker33 deleted the features/env-from-dir branch November 6, 2025 18:14
@alalazo alalazo mentioned this pull request Nov 12, 2025
17 tasks
@alalazo alalazo removed the v1.1.0 PRs to backport for v1.1.0 label Nov 13, 2025
@alalazo
Copy link
Copy Markdown
Member

alalazo commented Nov 13, 2025

No need for the label, was merged before we branched

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