Skip to content

Improve and unify developer shell interfaces#47492

Draft
psakievich wants to merge 35 commits intodevelopfrom
psakiev/dev-build
Draft

Improve and unify developer shell interfaces#47492
psakievich wants to merge 35 commits intodevelopfrom
psakiev/dev-build

Conversation

@psakievich
Copy link
Copy Markdown
Contributor

@psakievich psakievich commented Nov 8, 2024

Updated Scope:

This PR adds functionality to spack dev-build and spack build-env to increase compatibility and add a longstanding external feature build-env-dive to spack core.

build-env-dive [spec] is a shell function that

  1. Launches a subshell with the build-environment for the spec active
  2. Navigates to the build directory of the spec
  3. Changes the prompt to indicate to the user they are in the build-env subshell

The features added are:

  • spack build-env
    • add --dive for diving into the build-env
    • change the prompt as part of the dive process (bourne shells and csh only for now)
    • add spack build-env --status for people using shells that don't have a changed prompt (aka fish, powershell)
    • add --cd for navigation with subshell commands, (reproduces spack cd as a precursor to the dive/cmd)
  • spack dev-build
    • allow it to work with spack environments (requires specs to be marked as develop)
    • remove constraint for concrete spec
    • add --prompt and unify code for the --drop-in with spack build-env --dive
  • aliases
    • create a spack dev-dive alias to replace build-env-dive completely

Example developer workflow

$ spack env activate --temp
$ spack add zlib-ng
$ spack stage -p $SPACK_ENV zlib-ng
$ spack develop zlib-ng
$ spack install -u autoreconf zlib-ng
# fails
$ spack dev-dive zlib-ng
# prompt changed, let's check the location
zlib-ng-build-env $ pwd
/private/var/folders/ln/1_3kxbwd35s_ylsjlm3zmqmc00307v/T/spack-ne8_m488/zlib-ng
# confirm build-env in case we forget where we are in subshell hierarchy
zlib-ng-build-env $ spack build-env --status
==> In build env zlib-ng-wrsaadvkbg7rjj7kfjw5rhdrrfdswcmm
# fix code
zlib-ng-build-env $ make -j6
# builds  now
zlib-ng-build-env $ exit
$ spack build-env --status
==> build environment not detected
$ spack install

Original message:

There is really no reason why spack develop and dev-build shouldn't play along with each other. dev-build just assumes it can't work in an environment. This PR makes it so dev-build will look for matching develop specs in a concrete environment.

We could optionally make it do a spack add && spack develop if they don't exist but I think that is too far reaching.

We have constantly been re-writing a build-env-dive shell function that

  1. loads the build environment for a develop spec in a subshell
  2. spack cd -b to the build directory

Item 1 is already in place with spack dev-build so rather than write a whole new funciton, I think we should make them compatible.

That said I think the dev-build interface is a little clunky for how build-env-dive has been used and I think it needs to be improved, but it might just be doable through aliases.

Things I want to add still:

  • prompt to indicate you are in the build environment when using --build-dive
  • navigation option, dive then go to build or src directory

@psakievich psakievich added the snl-core-team Issue for SNL Spack developers label Nov 8, 2024
@spackbot-app spackbot-app bot added commands core PR affects Spack core functionality labels Nov 8, 2024
@haampie
Copy link
Copy Markdown
Member

haampie commented Nov 8, 2024

spack dev-build --help and docs should be updated.

As for a shell with the build environment, what's wrong with spack build-env? That it's lacking --drop-in and doesn't change the working dir? Adding that flag sounds useful and trivial.

I've never used spack dev-build --drop-in, looks very weird to me that it happens past .install() and won't happen on install failure. Do you agree?

To me it would make more sense if:

  • spack build-env --drop-in would do what it says without install
  • spack install/dev-build --drop-in would drop in on install failure

@psakievich
Copy link
Copy Markdown
Contributor Author

psakievich commented Nov 8, 2024

spack dev-build --help and docs should be updated.

As for a shell with the build environment, what's wrong with spack build-env? That it's lacking --drop-in and doesn't change the working dir? Adding that flag sounds useful and trivial.

I've never used spack dev-build --drop-in, looks very weird to me that it happens past .install() and won't happen on install failure. Do you agree?

To me it would make more sense if:

  • spack build-env --drop-in would do what it says without install
  • spack install/dev-build --drop-in would drop in on install failure

Yes I agree. Adding a --drop-in, I would prefer --dive, for build-env makes a lot of sense. The drop-in still happens even if the install fails for this command. The PackageInstaller.install() can fail but the command continues to the drop-in section. Overall I find this pretty unintuitive.

I started working on this yesterday because some SNL staff mentioned they use this, but it's not great, and they haven't used spack develop. 😭 I'm hoping this will also be a bridge to convert people over to spack develop.

I would propose the following for dev-build:

Stage 1. Make it compatible with environments and spack develop (this PR).
Stage 2. Advertise to the user base and determine how much use dev-build actually gets
Stage 3. Deprecate and then major refactor or remove after a release cycle.

Overall I think the dev-build command may have a place, but when I'm developing I don't want to run a command with a ton of options since development CLI commands tend to be repetitive and frequent.

I don't like that it is essentially wrapping spack install for non-environments and I find the current interface clunky. However for quick and dirty develop it seems like it could be useful if it is refactored and updated.

@psakievich
Copy link
Copy Markdown
Contributor Author

I think I might give up on the prompt for this PR. I think adding that plus a --drop-in/--dive option to build-env might be suitable for a follow on PR. I think I'll put the navigation option in either with or after that. Really I'd like to give more thought to cleaning up the relationship between these two. I spent a couple hours today trying to get the prompt stuff to work, but I don't think it is necessary for this PR.

I personally would classify this as a bug fix since there was no real reason for this command to not work with environments in the past.

@haampie I've updated the help section. This command does not appear in the docs 😬 . Not sure I want to add it right now given I consider it a candiadate to be reworked or deleted.

@psakievich psakievich marked this pull request as ready for review November 8, 2024 17:03
@psakievich psakievich marked this pull request as draft November 12, 2024 20:28
@psakievich psakievich changed the title Make dev-build compatible with spack develop Improve and unify spack development shell interfaces Nov 13, 2024
I tried consolidating but I am not convinced it will work
correctly
@johnwparent
Copy link
Copy Markdown
Contributor

Left a review comment, still need to take a closer pass for Windows concerns, but this should at least unblock the CI.

Co-authored-by: John W. Parent <[email protected]>
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.

Partial review, still need to look closer at the dev_build and location commands.

Trying this on Windows results in an error, tracing that down now.

pass
except subprocess.CalledProcessError:
pass
raise SpackError("Unknown shell type being used on Windows")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Do you want me to add support for CMD?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Hmm what do you think is best? I could just punt on windows for this PR and you could do a follow on? Otherwise likely yes? I never use windows so I don't really know what is best here.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I can also just commit directly to this PR if you're cool with that, shouldn't take long

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yeah that is fine if the changes are small. If I run into too many more windows issues then I think we should break it into two PR's since I can't really test windows behavior outside of CI at the moment.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Agreed, that's reasonable.

else:
try:
output = subprocess.check_output(
'powershell -Command "echo $PSVersionTable"', universal_newlines=True
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This will always pass (fine if we don't want to support CMD), as the powershell executable is always in the path unless a user removed it explicitly.

I think something like:

pproc_name = psutil.Process(os.getppid()).name()
is_power_shell = bool(re.fullmatch('pwsh|pwsh.exe|powershell|powershell.exe', pproc_name))

With a better regex would be best.

mods = EnvironmentModifications()

if shell == "fish" or shell == "pwsh" or shell == "bat":
# requires a function and can't be set with os.environ
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

bat can be set from env variables

@psakievich psakievich added this to the v1.1.0 milestone Jul 25, 2025
Signed-off-by: psakiev <[email protected]>
@psakievich psakievich marked this pull request as draft August 13, 2025 11:44
Signed-off-by: psakiev <[email protected]>
Signed-off-by: psakiev <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

build-environment commands core PR affects Spack core functionality defaults documentation Improvements or additions to documentation environments shell-support snl-core-team Issue for SNL Spack developers tests General test capability(ies) utilities

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

5 participants