-
Notifications
You must be signed in to change notification settings - Fork 305
support adding specific paths to $PATH for generic Binary easyblock via 'prepend_to_path' custom easyconfig parameter #1426
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
Conversation
| 'install_cmd': [None, "Install command to be used.", CUSTOM], | ||
| # staged installation can help with the hard (potentially faulty) check on available disk space | ||
| 'staged_install': [False, "Perform staged installation via subdirectory of build directory", CUSTOM], | ||
| 'prepend_to_path': ['', "Prepend the given path to environment PATH in the module file. Set to None to skip", CUSTOM], |
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.
line too long (130 > 120 characters)
Also allows to not add a path at all. Fixes easybuilders#801
59233da to
3e1de43
Compare
| # staged installation can help with the hard (potentially faulty) check on available disk space | ||
| 'staged_install': [False, "Perform staged installation via subdirectory of build directory", CUSTOM], | ||
| 'prepend_to_path': ['', | ||
| "Prepend the given path to environment PATH in the module file. Set to None to skip", |
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.
Please clarify that the specified path is relative to the installation prefix? Also, putting each part on a separate line is overkill?
'prepend_to_path': ['', "Prepend given directory (relative to installation prefix) to $PATH (use None to skip)",
CUSTOM],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.
Also, maybe we should make the default value [''] (and adjust accordingly below), to allow for adding multiple location to $PATH?
And then you don't need to use None as a magic value, an empty list will do too to skip adding anything to $PATH...
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.
The list idea is good, I'm just not sure if it is helpful. Can there be any situation where you would want to add multiple paths to PATH? Usually it is "bin" and this already lets you add one additional path. Should be enough but I'll change that if you like it better. And I don't consider None to be a magic value. IMO it is very descriptive.
About the separate lines: The Code-review bot was complaining about line length. If I add the relative part then even this would not fit. Where and how shall I split it? I could not find convention.
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.
I admit that having to add multiple locations to $PATH is rare, but it does happen (e.g. both bin & scripts). You are right that not being able to provide multiple locations via prepend_to_path is not a big issue though, you can always get additional locations included via modextrapaths = {'PATH': [...]} in the easyconfig file.
I was only referring to None as magical value since an empty string '' can't be used to skip adding a location to $PATH, and with a list this is no longer necessary (since an empty list [] also does that).
With that in mind, let's indeed keep the default value as is ('').
W.r.t. line length:
'prepend_to_path': ['', "Prepend given directory (relative to installation prefix) to $PATH"
" (use None to skip)", CUSTOM],(not using a , after the first line results in the two strings to be concatenated for the help message)
|
|
||
| txt = super(Binary, self).make_module_extra() | ||
| txt += self.module_generator.prepend_paths("PATH", ['']) | ||
| if not self.cfg['prepend_to_path'] is 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.
@Flamefire Please use if ... is not None, see https://docs.python.org/2/reference/expressions.html#not-in
|
@Flamefire Any idea if you'll be able to make the (trivial) requested changes soon? It would be nice to squeeze this into EasyBuild v3.6.1, which I'd like to get released this week... |
| # staged installation can help with the hard (potentially faulty) check on available disk space | ||
| 'staged_install': [False, "Perform staged installation via subdirectory of build directory", CUSTOM], | ||
| 'prepend_to_path': [[''], "Prepend the given directories (relative to install-dir) to the environment " | ||
| "variable PATH in the module file.", CUSTOM], |
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.
continuation line under-indented for visual indent
7aee2bc to
51772e4
Compare
51772e4 to
7e98049
Compare
|
I was just doing them :) |
| txt = super(Binary, self).make_module_extra() | ||
| txt += self.module_generator.prepend_paths("PATH", ['']) | ||
| if self.cfg['prepend_to_path'] is not None: | ||
| txt += self.module_generator.prepend_paths("PATH", self.cfg['prepend_to_path']) |
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.
@Flamefire I think it's a good idea to be a bit more careful here w.r.t. accessing the custom prepend_to_path easyconfig parameter. Easyblocks that derive from Binary may not pick up the custom easyconfig parameters defined for Binary (because they don't properly define the extra_options static method, or because they don't care), which would result in self.cfg['prepend_to_path'] failing hard with KeyError...
We can be robust against this by using self.cfg.get('prepend_to_path'), but to fully retain backward compatibility we also need to make sure [''] is used as a default value, so we should introduce a constant to avoid hardcoding [''] in multiple places:
PREPEND_TO_PATH_DEFAULT = ['']
...
def make_module_extra(self):
...
prepend_to_path = self.cfg.get('prepend_to_path', PREPEND_TO_PATH_DEFAULT)
if prepend_to_path:
txt += self.module_generator.prepend_paths("PATH", prepend_to_path)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. I was just following existing usages. Example: if self.cfg['install_cmd'] is None:
Shall I change those usages too while I'm on it?
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.
@Flamefire Makes sense, but better do that in a separate commit?
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.
Those actually show that this may be overkill (if there would be a problem with easyblock deriving from Binary we would've known already), but it doesn't hurt in the long run to make this a bit more robust...
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.
Done.
|
Reviewed & tested this with a couple of easyconfigs using |
Also allows to not add a path at all or set it to a specific one.
See e.g. #801 for problems caused by current behavior.
Basically: This EasyBlock is for binary packages or binary installers. So assuming the User/EasyConfig meant to add
installdirtoPATHis questionable at least as we do know nothing about the package to be installed.I thought about making it a simple True/False switch but I think this is more flexible: You can either be fine with
installdirbeing added (kept as default for backwards compatibility), change it to a custom binary path or disable it altogether.