-
Notifications
You must be signed in to change notification settings - Fork 90
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
Add script for creating environment module files #2019
Conversation
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.
Neat! This is pretty cool. Just a few comments. The module name should probably bout++
rather than bout
. Please also run your favourite PEP8 tool over this.
bin/add-mod-path.py
Outdated
|
||
def ask_bouttop(): | ||
this = os.path.realpath(__file__) | ||
top = "/".join(this.split("/")[:-2]) |
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.
Might be clearer to use either os.path.basename
or pathlib.Path.parent
?
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 tried basename first, but that doesn't work, at least the one from os.path: https://docs.python.org/3.5/library/os.path.html#os.path.basename
If there is a different one, with different behaviour, I wouldn't call that intuitive.
I only found parent in purepath, but that does anyway the same I do, but by having an additional layer, I would assume it is better then that, so I think it is easier to just do it myself, but if you have prefer the parent one, I don't care that match ...
https://docs.python.org/3.5/library/pathlib.html?highlight=pathlib#pathlib.PurePath.parent
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.
Well it's more that using a named function makes the code more explicit and easier to understand, even if it's doing exactly the same thing under the hood. This isn't something where we need to squeeze out every last drop of performance, so prefer to make code readable.
(btw pathlib.Path
inherits from PurePath
, but can do actual IO operations, PurePath
doesn't need an actual filesystem)
bin/add-mod-path.py
Outdated
def error(*args): | ||
print(*args) | ||
sys.exit(1) |
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.
Why not just use raise RuntimeError
?
Co-Authored-By: Peter Hill <zed.three@gmail.com>
Thanks to @ZedThree for the useful feedback
bin/add-mod-path.py
Outdated
parser.add_argument('--modpath', '-m', action=writeable_dir, nargs=1, | ||
help='The modulepath to install the bout++ module') | ||
parser.add_argument('--name', '-n', nargs=1, | ||
help='''can by any name by which you will be later able to recognice |
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.
Typos:
help='''can by any name by which you will be later able to recognice | |
help='''Can be any name by which you will be later able to recognise |
This program, bin/add-mod-path.py provides
a convenient way to create modules for the environment module for
BOUT++ that sets PYTHONPATH, PATH and BOUT_TOP, so that switching
between different BOUT++ installations is easy.
bin/add-mod-path.py stores the loaded modules as prerequesit, so that you
don't accidentially mix e.g. mpi versions. Feel free to edit the
crated module file, if there are non-needed dependencies.
bin/add-mod-path.py can be used interactively, or the location where to
create the modfiles, the name and the BOUT++ directory can be
passed:
bin/add-mod-path.py [modulepath [name [bout-top]]]
If modulepath is not passed, the script checks whether any of the
paths in $MODULEPATH are writeable, and asks which of them to
choose. If non are writeabel, and you can or want not to run as
root, you can extend this. Create a new folder and at it to your
.bashrc
e.g. with:name can by any name by which you will be later able to recognice
this specific bout installation, e.g.
3d-metrics
. You can laterload the module with
module load bout/name
e.g.module load bout/3d-metrics
.bout-top is the root directory of the BOUT++ installation. Note that
it only works with in-source-builds.
Might help with #2010