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

Add script for creating environment module files #2019

Merged
merged 4 commits into from
Jun 23, 2020
Merged

Add script for creating environment module files #2019

merged 4 commits into from
Jun 23, 2020

Conversation

dschwoerer
Copy link
Contributor

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:

 mkdir ~/.module
 echo 'export MODULEPATH=$HOME/.module:$MODULEPATH'>> ~/.bashrc
 source ~/.bashrc

name can by any name by which you will be later able to recognice
this specific bout installation, e.g. 3d-metrics. You can later
load 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

Copy link
Member

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


def ask_bouttop():
this = os.path.realpath(__file__)
top = "/".join(this.split("/")[:-2])
Copy link
Member

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?

Copy link
Contributor Author

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

Copy link
Member

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 Show resolved Hide resolved
bin/add-mod-path.py Outdated Show resolved Hide resolved
bin/add-mod-path.py Outdated Show resolved Hide resolved
Comment on lines 6 to 8
def error(*args):
print(*args)
sys.exit(1)
Copy link
Member

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?

bin/add-mod-path.py Outdated Show resolved Hide resolved
bin/add-mod-path.py Outdated Show resolved Hide resolved
bin/add-mod-path.py Outdated Show resolved Hide resolved
dschwoerer and others added 2 commits April 15, 2020 10:28
Co-Authored-By: Peter Hill <zed.three@gmail.com>
Thanks to @ZedThree for the useful feedback
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
Copy link
Member

Choose a reason for hiding this comment

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

Typos:

Suggested change
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

bin/add-mod-path.py Outdated Show resolved Hide resolved
@ZedThree ZedThree merged commit 6d24a05 into next Jun 23, 2020
@ZedThree ZedThree deleted the bout-module branch June 23, 2020 14:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants