Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some changes to spack_root_to_path #342

Merged
merged 1 commit into from
Sep 11, 2024
Merged

Conversation

giordano
Copy link
Member

@giordano giordano commented Sep 9, 2024

  • Add comments to improve clarity of all the conditions considered
  • There were unnecessary else branches
  • Cater for the dramatic case where both SPACK_ROOT and PATH are not set
  • Fix the case where PATH isn't set but SPACK_ROOT is (we were returning the function dir before, fun)
  • Fix the case where spack_bindir isn't in PATH (we were using * for non-commutative concatenation of strings, it turns out in Python one should use + instead for this operation)

@giordano giordano requested a review from tkoskela September 9, 2024 20:41
* Add comments to improve clarity of all the conditions considered
* There were unnecessary `else` branches
* Cater for the dramatic case where both `SPACK_ROOT` and `PATH` are not set
* Fix the case where `PATH` isn't set but `SPACK_ROOT` is (we were returning the
  function `dir` before, fun)
* Fix the case where `spack_bindir` isn't in `PATH` (we were using `*` for
  non-commutative concatenation of strings, it turns out in Python one should
  use `+` instead for this operation)
@giordano giordano force-pushed the mg/fix-spack-root-to-path branch from 88bb71a to ffe5a9d Compare September 9, 2024 20:42
Comment on lines +21 to +33
# Somehow we don't know what's the Spack root, then return PATH as is,
# but if also PATH is not set (what a dramatic case) then return an
# empty string.
return "" if path is None else path

spack_bindir = os.path.join(spack_root, 'bin')
if path is None:
# Somehow PATH isn't set, only return `spack_bindir`
return spack_bindir

if spack_bindir in path.split(os.path.pathsep):
# `spack_bindir` is already in PATH, return the environment
# variable as is.
Copy link
Member

Choose a reason for hiding this comment

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

To make this more readable, could you start with the most likely cases and leave the corner cases to the end?

Copy link
Member Author

Choose a reason for hiding this comment

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

I first need to check spack_bindir and path aren't None though, which is what the two ifs above are doing.

Copy link
Member

Choose a reason for hiding this comment

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

Right, I didn't realise all the if branches return and thought they'd all get checked regardless. It's fine then

@giordano giordano merged commit 4153164 into main Sep 11, 2024
@giordano giordano deleted the mg/fix-spack-root-to-path branch September 11, 2024 09:23
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.

2 participants