appeasing flake8, also cleaning up header

The header append lines were too long, so I just converted it into a
multi-line string template so it's all one piece now instead of a bunch
of appends.
This commit is contained in:
Tom Scogland 2016-08-24 11:56:33 -07:00
parent 73620fe868
commit 2b6833cb80

View File

@ -549,11 +549,13 @@ def file_name(self):
def header(self): def header(self):
timestamp = datetime.datetime.now() timestamp = datetime.datetime.now()
# TCL Modulefile header # TCL Modulefile header
header = '#%Module1.0\n' header = """\
header += '## Module file created by spack (https://github.com/LLNL/spack) on %s\n' % timestamp #%%Module1.0
header += '##\n' ## Module file created by spack (https://github.com/LLNL/spack) on %s
header += '## %s\n' % self.spec.short_spec ##
header += '##\n' ## %s
##
""" % (timestamp, self.spec.short_spec)
# TODO : category ? # TODO : category ?
# Short description # Short description
@ -569,39 +571,42 @@ def header(self):
return header return header
def process_environment_command(self, env): def process_environment_command(self, env):
environment_modifications_formats_colon = { environment_modifications_formats_colon = {
PrependPath: 'prepend-path {name} \"{value}\"\n', PrependPath: 'prepend-path {name} \"{value}\"\n',
AppendPath: 'append-path {name} \"{value}\"\n', AppendPath: 'append-path {name} \"{value}\"\n',
RemovePath: 'remove-path {name} \"{value}\"\n', RemovePath: 'remove-path {name} \"{value}\"\n',
SetEnv: 'setenv {name} \"{value}\"\n', SetEnv: 'setenv {name} \"{value}\"\n',
UnsetEnv: 'unsetenv {name}\n' UnsetEnv: 'unsetenv {name}\n'
} }
environment_modifications_formats_general = { environment_modifications_formats_general = {
PrependPath: 'prepend-path --delim "{separator}" {name} \"{value}\"\n', PrependPath:
AppendPath: 'append-path --delim "{separator}" {name} \"{value}\"\n', 'prepend-path --delim "{separator}" {name} \"{value}\"\n',
RemovePath: 'remove-path --delim "{separator}" {name} \"{value}\"\n', AppendPath:
SetEnv: 'setenv {name} \"{value}\"\n', 'append-path --delim "{separator}" {name} \"{value}\"\n',
UnsetEnv: 'unsetenv {name}\n' RemovePath:
} 'remove-path --delim "{separator}" {name} \"{value}\"\n',
for command in env: SetEnv: 'setenv {name} \"{value}\"\n',
# Token expansion from configuration file UnsetEnv: 'unsetenv {name}\n'
name = command.args.get('name', '').format(**self.upper_tokens) }
value = str(command.args.get('value', '')).format(**self.tokens) for command in env:
command.update_args(name=name, value=value) # Token expansion from configuration file
# Format the line int the module file name = command.args.get('name', '').format(**self.upper_tokens)
try: value = str(command.args.get('value', '')).format(**self.tokens)
if command.args.get('separator', ':') == ':': command.update_args(name=name, value=value)
yield environment_modifications_formats_colon[type( # Format the line int the module file
command)].format(**command.args) try:
else: if command.args.get('separator', ':') == ':':
yield environment_modifications_formats_general[type( yield environment_modifications_formats_colon[type(
command)].format(**command.args) command)].format(**command.args)
except KeyError: else:
message = ('Cannot handle command of type {command}: ' yield environment_modifications_formats_general[type(
'skipping request') command)].format(**command.args)
details = '{context} at {filename}:{lineno}' except KeyError:
tty.warn(message.format(command=type(command))) message = ('Cannot handle command of type {command}: '
tty.warn(details.format(**command.args)) 'skipping request')
details = '{context} at {filename}:{lineno}'
tty.warn(message.format(command=type(command)))
tty.warn(details.format(**command.args))
def module_specific_content(self, configuration): def module_specific_content(self, configuration):
naming_tokens = self.tokens naming_tokens = self.tokens