shell integration and system packages#7591
shell integration and system packages#7591MarkusLohmayer wants to merge 3 commits intospack:developfrom MarkusLohmayer:patch-1
Conversation
I added what I have in my ~/.bash_profile to use spack. Also I made a small comment about how to tell spack to use system packages, because I was initially confused.
|
@svenevs what was the difference between |
|
@MarquitoForrest you should simply set With that, I don't think this should be merged in its current form. I can go into details if you need, but the short version: the |
|
To be clear, the fact that you are confused means the docs could be clearer. Maybe put a |
|
I am on Mac OS X / Darwin and I did not know about this difference regarding startup procedure of a terminal window until now! This answer explains it well I think: https://apple.stackexchange.com/a/119714 So on Darwin the problem is that users pay the cost of source Further auto-completion worked equally well with my bash function overwriting the actual |
|
Wow. This just killed me a little inside. Who do they think they are?!!! Thanks @MarquitoForrest, I'm surprised I haven't encountered this yet...and I'm sure many future The changes in the latest commit are good progress, but I think the following would be a little nicer (it explains which file to use for which system, and why this happens): .. tip::
**Linux**
On traditional Linux / Unix systems, the file you want to place
.. code-block:: bash
export SPACK_ROOT=/path/to/spack
source $SPACK_ROOT/share/spack/setup-env.sh
is in your shell's *profile* startup script. For example, if ``bash`` is
your shell, then place these two lines in ``~/.bash_profile``. Placing
it in the *profile* means that this will only be loaded **once** when you
log into your machine (either via a graphical login, or via ``ssh``).
Though you can place these two commands in your *run commands* file (such
as ``~/.bashrc``), doing so means that ``setup-env.sh`` is sourced for
*every* terminal you launch. This is less convenient as you now must
wait every time you launch a new terminal session, rather than just
loading it once at login.
**After editing your shell's profile startup script, make sure you log
out and then log back in for the changes to take place.**
**MacOS**
MacOS, unfortunately, does not obey the startup conventions. Files such
as ``~/.bash_profile`` (when present), are loaded with each new shell
rather than at login. As such, there is little to no difference between
your shell's *profile* and *run commands* files.
To accommodate this, we encourage you to create your shell's *run
commands* file (e.g., ``touch ~/.bashrc`` for ``bash``, which is the
default shell on MacOS) and add the following using your favorite text
editor:
.. code-block:: bash
export SPACK_ROOT=/path/to/spack
function spack {
# overwrites spack command
# if not yet initialized, initialize spack's shell integration
if [ -z ${SPACK_SHELL+x} ] ; then
source $SPACK_ROOT/share/spack/setup-env.sh
fi
# run the real spack command with all passed parameters
$SPACK_ROOT/bin/spack "$@"
}
Since sourcing ``setup-env.sh`` for every terminal launched is not ideal,
this function defers sourcing ``setup-env.sh`` until you need it. The
**first** time you execute ``spack`` in a terminal session will load
``setup-env.sh``. Each subsequent call to ``spack`` *in the same
terminal session* will skip sourcing ``setup-env.sh`` (since it has
already been loaded for the current shell).It's mostly the same as what you had, but it uses some reStructuredText syntax that makes it stick out more / easier to parse the differences between Linux and MacOS (and made that alphabetical). Attached is what it looks like rendered. I only mention this for your benefit, when using teletype text in markdown you use a single back-tick, but in RST single back-ticks are hyperlinks (ugh). You have to use two. The implication is that when it sees single back-ticks but cannot evaluate a valid hyperlink target, it actually makes it italic (lol). Another one to look out for is the same as markdown, two asterisks are bold and a single asterisk is italic. However, underscores for italics are not allowed as they also have to do with how hyperlinks work. |
|
Thanks for the positive feedback! |
Sorry if this is too much of a modification. My intent was to include all the information we collected but at the same time keep the docs as short as possible. I hope it was a reasonably good attempt. Feel free to make corrections or redo it if you feel it is not good.
|
@svenevs @adamjstewart Please don't forget about this and consider my latest commit for the docs. |
|
Hi @MarquitoForrest: thanks for the awesome PR! I really like the lazy sourcing you added to |
|
@tgamblin |
|
@tgamblin you want it lazy-sourced for all platforms or just darwin? @MarquitoForrest I can help with this, I'll PR against your PR (on your fork) :) |
|
Closing, since no activity has been done on this PR in a couple of years and changes seem outdated. If anybody thinks this should stay open, please undo this. |

I added what I have in my ~/.bash_profile to use spack. I think it improves the user experience.
@adamjstewart
Also I made a small comment about how to tell spack to use system packages, because I was initially confused.