-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Env mod 4 #7536
Env mod 4 #7536
Conversation
Occurred when: blacklist YAML config is present but had all entries commented out.
Oh my – having factored out this PR from #7469, I realized there that This decouples the issues above from one another, but doesn't change their impact, in particular for the primary one. |
I rolled back the change to The other changes are still very much needed to fix bugs in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Basically LGTM. Can you add some tests that stress the lines you changed or added?
# distinct from "environment_blacklist" in modules.yaml, which is | ||
# applied on OUTPUT to a specific module flavor. | ||
# --------------------------------------------------------------------- | ||
blacklist.extend( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the name seems confusing, what do you think of renaming blacklist
and whitelist
to something that conveys better their role in this function and remove the comment above?
On a side not: I also slightly prefer to construct a list explicitly rather than splitting a string, given that we have items in it like _
.
@mgsternberg @alalazo it would be great to have this PR merged to enable the use of new Modules releases (4+). What can be done to help ? |
@xdelaruelle As far as I am concerned a rebase + unit tests + reply to the few minor comments above would do. |
Looking at the issues reported here. Concerning:
This is what Spack at 617c1a3 reports: $ spack config blame modules
==> Error: /home/mculpo/PycharmProjects/spack/etc/spack/modules.yaml:3: None is not of type 'array' so it doesn't seem to be an issue anymore. |
I also can't reproduce the two bugs above using 617c1a3 with the |
closes spack#7536 Credits for this change goes to @mgsternberg (original author of spack#7536) The new variables being ignored are specific to Modules v4.
@alalazo wrote:
It's not a showstopper anymore but the error message is terrible. It uses Python lingo for a YAML file and therefore looks rather like a bug. ExampleThe following is valid YAML (so says yamllint 1.15) and Spack clearly parses the syntax just fine but it stumbles on its own schema: modules:
tcl:
all:
filter:
environment_blacklist:
# foo
That error message would be far better for the user if it expressed that an empty YAML sequence (array) is disallowed by the Spack schema. But, not only does that seem overly harsh, you can't intuitively comment out the key of the sequence, because the trouble applies to the parent YAML mapping (dict) as well: modules:
tcl:
all:
filter:
# environment_blacklist:
# # foo
Moreover, the trouble recursively climbs up the hierarchy: modules:
# tcl:
# all:
# filter:
# environment_blacklist:
# # foo
SuggestionPermit (tolerate) empty YAML sequences and mappings in Spack config files. Is this something worthy of discussing further? |
closes spack#7536 Credits for this change goes to @mgsternberg (original author of spack#7536) The new variables being ignored are specific to Modules v4.
closes spack#7536 Credits for this change goes to @mgsternberg (original author of spack#7536) The new variables being ignored are specific to Modules v4.
Patch extracted from #7536 courtesy of @mgsternberg
closes spack#7536 Credits for this change goes to @mgsternberg (original author of spack#7536) The new variables being ignored are specific to Modules v4.
closes spack#7536 Credits for this change goes to @mgsternberg (original author of spack#7536) The new variables being ignored are specific to Modules v4.
closes spack#7536 Credits for this change goes to @mgsternberg (original author of spack#7536) The new variables being ignored are specific to Modules v4.
closes spack#7536 Credits for this change goes to @mgsternberg (original author of spack#7536) The new variables being ignored are specific to Modules v4.
* from_sourcing_file: fixed a bug + added a few ignored variables closes #7536 Credits for this change goes to mgsternberg (original author of #7536) The new variables being ignored are specific to Modules v4. * Use Spack Executable in 'EnvironmentModifications.from_sourcing_file' Using this class avoids duplicating lower level logic to decode stdout and handle non-zero return codes * Extracted a function that returns the environment after sourcing files The logic in `EnvironmentModifications.from_sourcing_file` has been simplified by extracting a function that returns a dictionary with the environment one would have after sourcing the files passed as argument. * Further refactoring of EnvironmentModifications.from_sourcing_file Extracted a function that sanitizes a dictionary removing keys that are blacklisted, but keeping those that are whitelisted. Blacklisting and whitelisting can be done on literals or regex. Extracted a new factory that creates an instance of EnvironmentModifications from a diff of two environments. * Added unit tests * PS1 is blacklisted + more readable names for some variables
…k#10753) * from_sourcing_file: fixed a bug + added a few ignored variables closes spack#7536 Credits for this change goes to mgsternberg (original author of spack#7536) The new variables being ignored are specific to Modules v4. * Use Spack Executable in 'EnvironmentModifications.from_sourcing_file' Using this class avoids duplicating lower level logic to decode stdout and handle non-zero return codes * Extracted a function that returns the environment after sourcing files The logic in `EnvironmentModifications.from_sourcing_file` has been simplified by extracting a function that returns a dictionary with the environment one would have after sourcing the files passed as argument. * Further refactoring of EnvironmentModifications.from_sourcing_file Extracted a function that sanitizes a dictionary removing keys that are blacklisted, but keeping those that are whitelisted. Blacklisting and whitelisting can be done on literals or regex. Extracted a new factory that creates an instance of EnvironmentModifications from a diff of two environments. * Added unit tests * PS1 is blacklisted + more readable names for some variables
Introduction
This PR provides fixes for Spack to function with Environment Modules 4.x and to address minor coding issues.
I factored out the main fix addressed here from #7469. As mentioned in that PR in general, the issue is fundamental and would render Spack a non-starter for new users on a similar platform.
Issues and Fixes
Spack threw
UnboundLocalError
when using Environment Modules 4.x.continue
statement inlib/spack/spack/environment.py:from_sourcing_file()
.This is the absolute minimum needed to accommodate Env-Mod-4.x. It turns out that a changed content of
BASH_FUNC_module()
triggered this problem (see next point).BASH_FUNC_module()
andENV
must be blacklisted to not show up in generated modulefiles.module()
differently, depending on the tty being interactive or not, or more specifically, where stderr goes (see reason in code):and:
Blacklisting
BASH_FUNC_module()
happens to sidestep the initial problem, but the latter should still be fixed to address the uninitialized variable issue.A TypeError/NoneType was thrown if
blacklist
was in the YAML config but had all entries commented out (as happened during debugging), or equivalently has no entries.if
clause.Background
The Environment Modules software project recently saw some major changes when Xavier Delaruelle xavier.delaruelle@cea.fr took on maintanence. He froze the former C-based implementation at 3.x, since it had become difficult to maintain and extend, and instead made the formerly alternative Tcl implemention the primary engine. Like Modules-C, the Modules-Tcl goes back quite some time and was mature but nonetheless new and interesting features are available with 4.x.
Pre-release versions of Environment Modules-4, like Modules-Tcl previously, did not work at all with Spack for their lack of a
modulecmd
script/executable. The 4.x release version conveniently added such a script, which Spack can latch on to. For end users, more involved interfaces are available in amodule
function for Bash and numerous scripting languages, including Python. Those front-end functions support the concept of quarantining variables, in particularLD_LIBRARY_PATH
, which is needed to ensure that any user-side environment modifications do not interfere with running the Tcl interpreter for the Modules engine itself. Since Spack itself isolates module commands, however, this quarantine may not strictly be needed.Development note
While implementing the above, I got the impression that
lib/spack/spack/environment.py:from_sourcing_file()
looks somewhat, shall we say, "organically grown", which is concerning given the complexity of its task. That function could benefit from being split into two tasks:dict
objects.Factoring out task 2 should make it rather more easy to test. It could be done here or in a separate PR. Of interest might be createmodule.py (it is under GPLv2). It uses a slightly different algorithm, jumping off with the rather nifty construct
(prepend,append) = env2[key].split(env1[key])
. There is also a Bash-based version which, remarkably, is shorter.