code: def setup(basepath=DEFAULT_BASEPATH):
      
  
      module_version = os.environ.get('MODULE_VERSION', DEFAULT_VERSION)
      moduleshome = os.path.join(basepath, module_version)
  
      # Abort if MODULESHOME does not exist
      if not os.path.isdir(moduleshome):
          print('payu: warning: MODULESHOME does not exist; disabling '
                'environment modules.')
          os.environ['MODULESHOME'] = ''
          return
  
      os.environ['MODULE_VERSION'] = module_version
      os.environ['MODULE_VERSION_STACK'] = module_version
      os.environ['MODULESHOME'] = moduleshome
  
      if 'MODULEPATH' not in os.environ:
          module_initpath = os.path.join(moduleshome, 'init', '.modulespath')
          with open(module_initpath) as initpaths:
              modpaths = [
                  line.partition('#')[0].strip()
                  for line in initpaths.readlines() if not line.startswith('#')
              ]
  
          os.environ['MODULEPATH'] = ':'.join(modpaths)
  
      os.environ['LOADEDMODULES'] = os.environ.get('LOADEDMODULES', '')
  
      # Environment modules with certain characters will cause corruption
      # when MPI jobs get launched on other nodes (possibly a PBS issue).
      #
      # Bash processes obscure the issue on Raijin, since it occurs in an
      # environment module function, and bash moves those to the end of
      # the environment variable list.
      #
      # Raijin's mpirun wrapper is a bash script, and therefore "fixes" by doing
      # the shuffle and limiting the damage to other bash functions, but some
      # wrappers (e.g. OpenMPI 2.1.x) may not be present.  So we manually patch
      # the problematic variable here.  But a more general solution would be nice
      # someday.
  
      if 'BASH_FUNC_module()' in os.environ:
          bash_func_module = os.environ['BASH_FUNC_module()']
          os.environ['BASH_FUNC_module()'] = bash_func_module.replace('\n', ';')
docs: Set the environment modules used by the Environment Module system.