Files
modules/init/python.in
Xavier Delaruelle 63f5918d4c init: do not load modulerc config is env already set
If MODULEPATH or LOADEDMODULES is already set, do not source the
modulerc configuration file in init scripts.

As a consequence, if .modulespath sets a module path, then modulerc will
be ignored which clarifies how default configuration is loaded: if both
.modulespath and modulerc are defined, .modulespath takes precedence
over modulerc.

So if .modulespath sets a module path, all loaded modules defined in the
modulerc file will be ignored.
2017-03-06 06:09:15 +01:00

25 lines
956 B
Plaintext

import os, re, subprocess
def module(command, *arguments):
exec(subprocess.Popen(['@TCLSH@', '@libexecdir@/modulecmd.tcl', 'python', command] + list(arguments), stdout=subprocess.PIPE).communicate()[0])
os.environ['MODULESHOME'] = '@prefix@'
if not 'MODULEPATH' in os.environ:
if os.access('@initdir@/.modulespath', os.R_OK):
pathlist = []
for fline in open('@initdir@/.modulespath', 'r').read().splitlines():
patharg = re.match('^\s*(.*?)[\s#].*$', fline)
if patharg and patharg.group(1):
pathlist.append(patharg.group(1))
os.environ['MODULEPATH'] = ':'.join(pathlist)
else:
os.environ['MODULEPATH'] = ''
if not 'LOADEDMODULES' in os.environ:
os.environ['LOADEDMODULES'] = ''
# load modulerc only if module environment is empty
if os.access('@initdir@/modulerc', os.R_OK) and not os.environ['MODULEPATH'] and not os.environ['LOADEDMODULES']:
module('source', '@initdir@/modulerc')