Files
modules/init/python.py.in
Xavier Delaruelle fc5674846c init: adapt scripts to --enable-compat-version build
Introduce MODULE_USE_COMPAT_VERSION environment variable to control the
activation of the compatibility version rather main version in case of
--enable-compat-version installation.

The initialization script of the shells supporting compatibility version
are adapted to define the 'module' command based on the modulecmd-compat
binary if MODULE_USE_COMPAT_VERSION is set to 1. Elsewhere module is
based on modulecmd.tcl.

'switchml' function of alias is reintroduced to switch between main and
compatibility version based on the state of the
MODULE_USE_COMPAT_VERSION environment variable.

Acknowledgment: this development has been made and funded within the
framework of the PRACE Fifth Implementation Phase (PRACE-5IP) project
(http://www.prace-ri.eu/). PRACE-5IP receives funding from the EU's
Horizon 2020 research and innovation programme (2014-2020) under grant
agreement no. 730913.
2017-09-13 06:30:19 +02:00

33 lines
1.8 KiB
Python

import os, re, subprocess
@notcompatversion@def module(command, *arguments):
@notcompatversion@ exec(subprocess.Popen(['@TCLSH@', '@libexecdir@/modulecmd.tcl', 'python', command] + list(arguments), stdout=subprocess.PIPE).communicate()[0])
@compatversion@if 'MODULE_USE_COMPAT_VERSION' in os.environ and os.environ['MODULE_USE_COMPAT_VERSION'] == '1':
@compatversion@ # set module command in accordance with active version
@compatversion@ def module(command, *arguments):
@compatversion@ exec(subprocess.Popen(['@libexecdir@/modulecmd-compat', 'python', command] + list(arguments), stdout=subprocess.PIPE).communicate()[0])
@compatversion@else:
@compatversion@ def module(command, *arguments):
@compatversion@ 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
@notcompatversion@if os.access('@initdir@/modulerc', os.R_OK) and not os.environ['MODULEPATH'] and not os.environ['LOADEDMODULES']:
@compatversion@if (not 'MODULE_USE_COMPAT_VERSION' in os.environ or os.environ['MODULE_USE_COMPAT_VERSION'] != '1') and os.access('@initdir@/modulerc', os.R_OK) and not os.environ['MODULEPATH'] and not os.environ['LOADEDMODULES']:
module('source', '@initdir@/modulerc')