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

lmod: fix use of custom separator in prepend_path etc. #8737

Merged
merged 3 commits into from
Aug 1, 2018

Conversation

SteVwonder
Copy link
Member

Fixes: #8736

@SteVwonder
Copy link
Member Author

This PR now includes tests for the generation of the custom separator in lmod's {prepend,append,remove}_path.

@SteVwonder SteVwonder force-pushed the fix-lmod-separator branch 2 times, most recently from 06348ae to 1042639 Compare July 30, 2018 23:09
@SteVwonder
Copy link
Member Author

@alalazo: the travis tests on this PR are now passing. This is now ready for your (or anyone else's) review.

Copy link
Member

@alalazo alalazo left a 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 != ':' %}
Copy link
Member

Choose a reason for hiding this comment

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

Looking at:

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?

Copy link
Member Author

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.

Copy link
Member Author

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. 🎉

content = modulefile_content('module-path-separator')

for line in content:
if re.match(r'[a-z]+_path\("COLON"', line) is not None:
Copy link
Member

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.

Changes include:
  - removing 'is not None' from conditional
  - simplify control logic in lmod module template
Copy link
Member

@alalazo alalazo left a 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.

@alalazo alalazo merged commit de60e9d into spack:develop Aug 1, 2018
@alalazo
Copy link
Member

alalazo commented Aug 1, 2018

@SteVwonder Thanks!

@SteVwonder SteVwonder deleted the fix-lmod-separator branch November 17, 2018 18:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants