-
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
lmod: fix use of custom separator in prepend_path etc. #8737
Conversation
This PR now includes tests for the generation of the custom separator in lmod's |
06348ae
to
1042639
Compare
@alalazo: the travis tests on this PR are now passing. This is now ready for your (or anyone else's) review. |
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.
💯 For the unit test. A comment on the template (please check and report back) and just a minor and optional remark on style.
@@ -72,6 +72,21 @@ end | |||
|
|||
{% block environment %} | |||
{% for command_name, cmd in environment_modifications %} | |||
{% if cmd.separator != ':' %} |
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.
Looking at:
spack/lib/spack/spack/environment.py
Lines 54 to 59 in df1e233
def __init__(self, name, value, **kwargs): | |
self.name = name | |
self.value = value | |
self.separator = kwargs.get('separator', ':') | |
self.args = {'name': name, 'value': value, 'separator': self.separator} | |
self.args.update(kwargs) |
it seems to me that cmd.separator
will always be defined in the template. We can thus avoid the proliferation of conditionals in the template itself, by simply replacing:
prepend_path("{{ cmd.name }}", "{{ cmd.value }}")
with:
prepend_path("{{ cmd.name }}", "{{ cmd.value }}", "{{ cmd.separator }}")
This imo has the benefit of changing only 5 lines and not adding nested conditional logic. Can you try to see if this works?
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.
Sure! That is a much cleaner way of handling it. If it works, would you like me to propagate this change to the tcl module file as well (https://github.com/spack/spack/blob/develop/share/spack/templates/modules/modulefile.tcl#L49)? That is originally where I copied this control flow from.
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.
Reporting back that this does in fact work. 🎉
lib/spack/spack/test/modules/lmod.py
Outdated
content = modulefile_content('module-path-separator') | ||
|
||
for line in content: | ||
if re.match(r'[a-z]+_path\("COLON"', line) is not None: |
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.
Minor comment on style (not sure if everybody in the project here will agree, so feel free to discard this if you don't like it). This and the next condition can be written:
if re.match(r'[a-z]+_path\("COLON"', line):
....
without the additional is not None
. I find this style more readable.
1042639
to
1f04834
Compare
Changes include: - removing 'is not None' from conditional - simplify control logic in lmod module template
1f04834
to
472aff8
Compare
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.
LGTM. I'll test drive this asap and then merge.
@SteVwonder Thanks! |
Fixes: #8736