fix module load behaviour [WIP] [donotmerge]#3827
fix module load behaviour [WIP] [donotmerge]#3827healther wants to merge 11 commits intospack:developfrom
Conversation
check in a module loads call whether exactly one spec is found in the db
|
After some more digging I found See the latest commit for my latest attempt. I'm not too happy with the error messages, ideally edit: I'm not sure about the failing travis job for python2.7, locally |
lib/spack/spack/database.py
Outdated
| if unique: | ||
| if len(results) > 1: | ||
| tty.die('Found more than one spec for {}'.format(query_spec)) | ||
| tty.die('Found more than one spec for ' + str(query_spec)) |
There was a problem hiding this comment.
'{}'.format() only works for Python 2.7+. You have to use '{0}'.format() in Python 2.6+.
|
I'd propose to get rid of |
|
Ping |
|
@alalazo Can you take a look at this? You know a lot more about our module support than I do. |
|
@alalazo did you find time to take a look at this? |
|
@healther No sorry, but will try to have a look later in the day. |
| """ | ||
| concrete_specs = self.query(query_spec, known, installed) | ||
| concrete_specs = self.query(query_spec, known, installed, unique=True) | ||
| assert len(concrete_specs) <= 1 |
There was a problem hiding this comment.
Do you agree that we will never hit this line:
assert len(concrete_specs) <= 1because if unique=True and len(results) == 0 the program will tty.die?
I think we shouldn't change anything in the DB API, but rather act in cmd/module.py
There was a problem hiding this comment.
I'm not particularly attached to this solution, it's only the first one that did what I wanted. That being said, I find the concept of query_one strange, imho it should just be a parameter.
Nevertheless, if we can accomplish the load-fix in module.py I'm all for it. Shall I try there again? Discussions here suggested that, a check of specs = args.specs(**query_args) might be sufficient.
I'll try that later (or tomorrow). I haven't done it so far, as I wanted some Feedback on how you want this PR done first.
edit: Yes, that line cannot be reached
There was a problem hiding this comment.
I put @tgamblin as a reviewer because skimming the code query_one seems to be used only in tests. In that case it may be fine to erase it completely, and have a unique argument to query.
The only comment that would remain from my side is that I wouldn't use tty directly in the database module, but raise an appropriate error. The command should then catch it and react with tty.die.
alalazo
left a comment
There was a problem hiding this comment.
The two tests LGTM, but I would rather modify the code in cmd/module.py to use the existing DB API. Overall I think the behavior is the one the users will expect if they load modules using spack load.
|
Turns out there is a much shorter solution on the level of I still think it would be worthwhile removing the |
|
Close and reopen to trigger Travis edit: Wasn't there the possibility to look at the individual Travis tests? Did you remove that or am I just failing to find it? |
You can click on "Details" next to the Travis icon and then check the logs there. |
|
thanks, somehow I failed to find that. All checks passed -> please let me know if you have improvements, otherwise this is ready from my side |
alalazo
left a comment
There was a problem hiding this comment.
I think this change will break spack module refresh and spack module rm. On the OP side the fact that we don't have unit tests signaling the issue.
lib/spack/spack/cmd/module.py
Outdated
| } | ||
| query_args = constraint_qualifiers.get(args.subparser_name, {}) | ||
| specs = args.specs(**query_args) | ||
| if len(specs) > 1: |
There was a problem hiding this comment.
@healther This is in the module command. I didn't try it, but it seems it will prevent the regeneration of multiple modules at once. What happens if you try:
$ spack module refresh -m tcl
using this branch?
|
You are right, that must have been the reason for the convoluted solution I had... |
Because it is non-determinstic. Same with
See (or better yet, attend) today's Telcon. |
|
It breaks exactly because it just loads everything that matches, rather than complain when it finds not exactly one match. |
|
@citibeth I wouldn't describe that as "broken". I can't speak for |
I agree, complaining instead of just loading everything (this PR) is an improvement and should be merged. But it doesn't fix the fundamental problem that the command is not scriptable. |
It's scriptable as long as you provide a hash. I'm not sure if there will ever be an alternative to that and I don't know enough about "Spack Environments" to tell if that will help. Personally I would use |
|
Okay, so from my side this is good to go. @alalazo you still have a change request outstanding. |
alalazo
left a comment
There was a problem hiding this comment.
The logic now LGTM. I suggested a few improvements below, but I'll leave to you if you want to implement them. If not I can also submit a PR after this is merged.
lib/spack/spack/test/cmd/module.py
Outdated
|
|
||
| def test_load_multi_install_package(database, parser, capfd): | ||
| args = parser.parse_args(['loads', 'mpileaks']) | ||
| # with pytest.raises(SystemExit): |
There was a problem hiding this comment.
Why don't you use pytest.raises? Personally I don't see the need to check what is in the error message (which may be changed later).
| def test_load_non_existing_package(database, parser, capfd): | ||
| args = parser.parse_args(['loads', 'py-pudb']) | ||
| try: | ||
| module.module(parser, args) |
| if len(specs) > 1: | ||
| message = ("Trying to load multiple modules, please be more " | ||
| "specific. Currently we would load: \n\t" + | ||
| "\n\t".join(str(s) for s in specs) + "\n") |
There was a problem hiding this comment.
An improvement here would be to use spack.cmd.display_specs to display specs, as it will be consistent with all the other commands. I don't think we say 'Aborting.' anywhere else, so I would also remove that.
There was a problem hiding this comment.
I added it specifically, so that the user (i.e. me) can be sure, that spack didn't actually change anything in the environment, I can remove it if you want, but since spack, at least right now, has the reputation of being overeager (at least at our lab), I'd prefer to be specific.
|
I haven't been closely following this PR, but I wonder whether we should make P.S. I don't use |
|
@adamjstewart I agree with you, here though we are modifying the behavior of |
|
Oh boy, there are too many commands... What's the difference? |
|
The problem with I'd prefer to leave the tests as is, as any change should be intentional, in which case it is trivial to adapt the test(s). I ran into this myself, because I had forgotten how I had written the test after less than 3 weeks. |
|
WIP pending decision regarding the intended behaviour of |
|
Mark down one more fundamentally broken thing that Spack environment work
will likely improve,
…On May 10, 2017 4:04 AM, "healther" ***@***.***> wrote:
WIP pending decision regarding the intended behaviour of spack load see
#4189 <#4189>.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#3827 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AB1cd5ySHx9gxuvYyD5NASd0GALPy5Koks5r4W-dgaJpZM4M9BtP>
.
|
|
We use environment modules so I am very excited to see this fixed. "spack load r" should not load all three versions of R which I have installed. I don't know if this happens to be related but when users do "spack load blah," if blah happens to not be installed, the user gets no message stating that's the case. It would also be nice if "spack info" would report if whether the package happens to be installed already. |
fixes spack#2215 fixes spack#2570 fixes spack#6676 fixes spack#7281 closes spack#3827 This PR reverts the use of `spack module loads` in favor of `spack module find` when loading module files via Spack. After this PR `spack load` will accept a single spec at a time, and will be able to interpret correctly the `--dependencies` option.
fixes spack#2215 fixes spack#2570 fixes spack#6676 fixes spack#7281 closes spack#3827 This PR reverts the use of `spack module loads` in favor of `spack module find` when loading module files via Spack. After this PR `spack load` will accept a single spec at a time, and will be able to interpret correctly the `--dependencies` option.
fixes spack#2215 fixes spack#2570 fixes spack#6676 fixes spack#7281 closes spack#3827 This PR reverts the use of `spack module loads` in favor of `spack module find` when loading module files via Spack. After this PR `spack load` will accept a single spec at a time, and will be able to interpret correctly the `--dependencies` option.
fixes spack#2215 fixes spack#2570 fixes spack#6676 fixes spack#7281 closes spack#3827 This PR reverts the use of `spack module loads` in favor of `spack module find` when loading module files via Spack. After this PR `spack load` will accept a single spec at a time, and will be able to interpret correctly the `--dependencies` option.
fixes #2215 fixes #2570 fixes #6676 fixes #7281 closes #3827 This PR reverts the use of `spack module loads` in favor of `spack module find` when loading module files via Spack. After this PR `spack load` will accept a single spec at a time, and will be able to interpret correctly the `--dependencies` option.
Fixes #2215.
Partially due to my tests for #3761, but also regularly when interacting with
spackI become annoyed, that it doesn't complain enough. If I ask it to load a package which is installed in multiple versions.spack's behaviour is to just load ALL of them. Even worse, in the case of 0 matching packages it silently does nothing.This PR adds a check in a
module loadscall whether exactly one spec is found in the db. I'm sure that it is not the most elegant way, but it works for me . The error message (well the dying message) should distinguish between having found n>1 or n=0 matching packages (which it doesn't do at the moment).This here is mostly to ask the questions, whether a) this feature is wanted, b) this is the correct wau of introducing the logic and c) what the scope of the error message should be.
I know that I broke two tests in
lib/spack/spack/test/cmd/module.py, but I don't know how I have to read the output ofspack test. So any help/feedback is appreciated.