/CMod

Module written in C

Primary LanguageTeXGNU General Public License v2.0GPL-2.0

CMod

Module written in C

This is a verbatim redistribution (fair use under GPL v2.0) of cmod written by the following people:

  • Per Cederqvist
  • Kent Engström
  • Henrik Rindlöw
  • David Kågedal

The source file can be found at http://www.lysator.liu.se/cmod/

Installation

  • git clone https://github.com/yuhangwang/CMod.git
  • cd CMod/src/source
  • tar xvf cmod-1.1.tar.gz
  • cd cmod-1.1
  • mkdir -p ~/install/cmod/1.1
  • ./configure --prefix=$HOME/install/cmod/1.1
  • make
  • make check
  • make install
  • If you are using bash shell, add the following line to your .bashrc file (or .bash_profile if you are using Mac OS) source $HOME/install/cmod/1.1/etc/cmod/bash.init
  • If you are using tcsh shell, add the following line to your .cshrc file source $HOME/install/cmod/1.1/etc/cmod/tcsh.init
  • To dynamically load/unload some software into your shell environment, you need to write some module specification scripts and use module use [path to your module specification folder] command to make module aware of these scripts. Take a look at the use case below.

Use case

  • Suppose we have installed a new version of python and we want to use module to dynamically loaded it into the our shell environment when we need it and unload it when we are done.
  • First, you need to make a folder containing the CMod scripts. mkdir -p ~/modules/python
  • Then create a new file ~/modules/python/default
    with the following content.
    prepend-path PATH /Users/steven/install/miniconda/3/bin
    prepend-path DYLD_LIBRARY_PATH /Users/steven/install/miniconda/3/lib
    
  • You can also use other file names such as ~/modules/python/3.7. Then you have to use module add python/3.7 instead of just module add python.
  • Add the following lines in your ~/.bashrc file
    source $HOME/install/cmod/1.1/etc/cmod/bash.init
    module use $HOME/modules
    
  • Refresh your BASH shell using source ~/.bashrc
  • Now you can see the available modules with module avail
  • To load a module into your current bash shell, use module add python
  • To remove the module, use module rm python
  • To see the currently loaded modules, use module list
  • You can add more module files to ~/modules similar to the python example.

Commands available in a CMod specification script

  • append-path: appending a directory to a path.
  • prepend-path: prepending a directory to a path.
  • remove-path: removing a directory from a path.
  • setenv: setting a variable to a fixed value.
  • unsetenv: unsetting a variable.

Most commonly used module commands

  • module add: add module(s), e.g., module add python/3.7
  • module try-add: same as module add except without error messages if the module is not found.
  • module rm: remove a loaded module, e.g., module rm python/3.7
  • module use: add a new path that contains module scripts, e.g., module use /home/steven/modules/apps. In the apps folder, you can put subfolders which contain module specification scripts, e.g., apps/python/default.
  • module unuse: remove a path searchable by module
  • module list: list currently loaded modules
  • module avail: list all available modules, a very useful feature to see all the software you have installed.

Full documentation

A complete documentation can be found in the info folder of your cmod installation path.
You can also browse the documentation contained in the usage/cmod.md file of this Github repository.

Examples

For some example module specification scripts, take a look at the examples folder.