modules : don't pass stream around
This commit is contained in:
parent
2968b60ee0
commit
5da37c573f
1 changed files with 28 additions and 22 deletions
|
@ -149,7 +149,6 @@ def category(self):
|
||||||
# Not very descriptive fallback
|
# Not very descriptive fallback
|
||||||
return 'spack installed package'
|
return 'spack installed package'
|
||||||
|
|
||||||
|
|
||||||
def write(self):
|
def write(self):
|
||||||
"""Write out a module file for this object."""
|
"""Write out a module file for this object."""
|
||||||
module_dir = os.path.dirname(self.file_name)
|
module_dir = os.path.dirname(self.file_name)
|
||||||
|
@ -218,25 +217,27 @@ def dependencies(request='All'):
|
||||||
filter_list = []
|
filter_list = []
|
||||||
|
|
||||||
with open(self.file_name, 'w') as f:
|
with open(self.file_name, 'w') as f:
|
||||||
self.write_header(f)
|
# Header
|
||||||
|
f.write(self.header)
|
||||||
# Automatic loads
|
# Automatic loads
|
||||||
for x in autoload_list:
|
for x in autoload_list:
|
||||||
self.write_autoload(f, x)
|
f.write(self.autoload(x))
|
||||||
# Prerequisites
|
# Prerequisites
|
||||||
for x in prerequisites_list:
|
for x in prerequisites_list:
|
||||||
self.write_prerequisite(f, x)
|
f.write(self.prerequisite(x))
|
||||||
# Modifications to the environment
|
# Modifications to the environment
|
||||||
iterable = self.process_environment_command( filter_environment_modifications(env, filter_list))
|
iterable = self.process_environment_command(filter_environment_modifications(env, filter_list))
|
||||||
for line in iterable:
|
for line in iterable:
|
||||||
f.write(line)
|
f.write(line)
|
||||||
|
|
||||||
def write_header(self, stream):
|
@property
|
||||||
|
def header(self):
|
||||||
raise NotImplementedError()
|
raise NotImplementedError()
|
||||||
|
|
||||||
def write_autoload(self, stream, spec):
|
def autoload(self, spec):
|
||||||
raise NotImplementedError()
|
raise NotImplementedError()
|
||||||
|
|
||||||
def write_prerequisite(self, stream, spec):
|
def prerequisite(self, spec):
|
||||||
raise NotImplementedError()
|
raise NotImplementedError()
|
||||||
|
|
||||||
def process_environment_command(self, env):
|
def process_environment_command(self, env):
|
||||||
|
@ -286,19 +287,22 @@ def use_name(self):
|
||||||
self.spec.compiler.version,
|
self.spec.compiler.version,
|
||||||
self.spec.dag_hash())
|
self.spec.dag_hash())
|
||||||
|
|
||||||
def write_header(self, dk_file):
|
@property
|
||||||
|
def header(self):
|
||||||
# Category
|
# Category
|
||||||
|
header = ''
|
||||||
if self.category:
|
if self.category:
|
||||||
dk_file.write('#c %s\n' % self.category)
|
header += '#c %s\n' % self.category
|
||||||
|
|
||||||
# Short description
|
# Short description
|
||||||
if self.short_description:
|
if self.short_description:
|
||||||
dk_file.write('#d %s\n' % self.short_description)
|
header += '#d %s\n' % self.short_description
|
||||||
|
|
||||||
# Long description
|
# Long description
|
||||||
if self.long_description:
|
if self.long_description:
|
||||||
for line in textwrap.wrap(self.long_description, 72):
|
for line in textwrap.wrap(self.long_description, 72):
|
||||||
dk_file.write("#h %s\n" % line)
|
header += '#h %s\n' % line
|
||||||
|
return header
|
||||||
|
|
||||||
|
|
||||||
class TclModule(EnvModule):
|
class TclModule(EnvModule):
|
||||||
|
@ -324,22 +328,24 @@ def use_name(self):
|
||||||
self.spec.compiler.version,
|
self.spec.compiler.version,
|
||||||
self.spec.dag_hash())
|
self.spec.dag_hash())
|
||||||
|
|
||||||
def write_header(self, module_file):
|
@property
|
||||||
|
def header(self):
|
||||||
# TCL Modulefile header
|
# TCL Modulefile header
|
||||||
module_file.write('#%Module1.0\n')
|
header = '#%Module1.0\n'
|
||||||
# TODO : category ?
|
# TODO : category ?
|
||||||
# Short description
|
# Short description
|
||||||
if self.short_description:
|
if self.short_description:
|
||||||
module_file.write('module-whatis \"%s\"\n\n' % self.short_description)
|
header += 'module-whatis \"%s\"\n\n' % self.short_description
|
||||||
|
|
||||||
# Long description
|
# Long description
|
||||||
if self.long_description:
|
if self.long_description:
|
||||||
module_file.write('proc ModulesHelp { } {\n')
|
header += 'proc ModulesHelp { } {\n'
|
||||||
for line in textwrap.wrap(self.long_description, 72):
|
for line in textwrap.wrap(self.long_description, 72):
|
||||||
module_file.write("puts stderr \"%s\"\n" % line)
|
header += 'puts stderr "%s"\n' % line
|
||||||
module_file.write('}\n\n')
|
header += '}\n\n'
|
||||||
|
return header
|
||||||
|
|
||||||
def write_autoload(self, module_file, spec):
|
def autoload(self, spec):
|
||||||
autoload_format = '''
|
autoload_format = '''
|
||||||
if ![ is-loaded {module_file} ] {{
|
if ![ is-loaded {module_file} ] {{
|
||||||
puts stderr "Autoloading {module_file}"
|
puts stderr "Autoloading {module_file}"
|
||||||
|
@ -347,8 +353,8 @@ def write_autoload(self, module_file, spec):
|
||||||
}}
|
}}
|
||||||
'''''
|
'''''
|
||||||
m = TclModule(spec)
|
m = TclModule(spec)
|
||||||
module_file.write(autoload_format.format(module_file=m.use_name))
|
return autoload_format.format(module_file=m.use_name)
|
||||||
|
|
||||||
def write_prerequisite(self, module_file, spec):
|
def prerequisite(self, spec):
|
||||||
m = TclModule(spec)
|
m = TclModule(spec)
|
||||||
module_file.write('prereq {module_file}\n'.format(module_file=m.use_name))
|
return 'prereq {module_file}\n'.format(module_file=m.use_name)
|
||||||
|
|
Loading…
Reference in a new issue