Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix crash during module generation when '%' character is used in description #2209

Merged
merged 4 commits into from
May 8, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions easybuild/tools/module_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -424,12 +424,15 @@ def get_description(self, conflict=True):
"""
Generate a description.
"""
lines = [
txt = '\n'.join([
"proc ModulesHelp { } {",
" puts stderr {%s" % self._generate_help_text(),
" }",
'}',
'',
])

lines = [
'%(whatis_lines)s',
'',
"set root %(installdir)s",
Expand All @@ -447,10 +450,9 @@ def get_description(self, conflict=True):
# - 'conflict Compiler/GCC/4.8.2/OpenMPI' for 'Compiler/GCC/4.8.2/OpenMPI/1.6.4'
lines.extend(['', "conflict %s" % os.path.dirname(self.app.short_mod_name)])

txt = '\n'.join(lines + ['']) % {
txt += '\n'.join([''] + lines + ['']) % {
'name': self.app.name,
'version': self.app.version,
'description': self.app.cfg['description'],
'whatis_lines': '\n'.join(["module-whatis {%s}" % line for line in self._generate_whatis_lines()]),
'installdir': self.app.installdir,
}
Expand Down Expand Up @@ -672,10 +674,13 @@ def get_description(self, conflict=True):
"""
Generate a description.
"""
lines = [
txt = '\n'.join([
'help([[%s' % self._generate_help_text(),
']])',
'',
])

lines = [
"%(whatis_lines)s",
'',
'local root = "%(installdir)s"',
Expand All @@ -688,10 +693,9 @@ def get_description(self, conflict=True):
# conflict on 'name' part of module name (excluding version part at the end)
lines.extend(['', 'conflict("%s")' % os.path.dirname(self.app.short_mod_name)])

txt = '\n'.join(lines + ['']) % {
txt += '\n'.join([''] + lines + ['']) % {
'name': self.app.name,
'version': self.app.version,
'description': self.app.cfg['description'],
'whatis_lines': '\n'.join(["whatis([[%s]])" % line for line in self._generate_whatis_lines()]),
'installdir': self.app.installdir,
'homepage': self.app.cfg['homepage'],
Expand Down
4 changes: 2 additions & 2 deletions test/framework/docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ def test_list_software(self):
expected = [
'* toy',
'',
'Toy C program.',
'Toy C program, 100% toy.',
'',
'homepage: http://hpcugent.github.com/easybuild',
'',
Expand All @@ -256,7 +256,7 @@ def test_list_software(self):
'*toy*',
'+++++',
'',
'Toy C program.',
'Toy C program, 100% toy.',
'',
'*homepage*: http://hpcugent.github.com/easybuild',
'',
Expand Down
6 changes: 3 additions & 3 deletions test/framework/easyconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ def test_exts_list(self):
' "patches": ["toy-0.0.eb"],', # dummy patch to avoid downloading fail
' "checksums": [',
' "9e9485921c6afe15f62aedfead2c8f6e",', # MD5 checksum for source (gzip-1.4.eb)
' "fad34da3432ee2fd4d6554b86c8df4bf",', # MD5 checksum for patch (toy-0.0.eb)
' "8ebc2c32692be9ee61eadc5d650cd288",', # MD5 checksum for patch (toy-0.0.eb)
' ],',
' }),',
']',
Expand Down Expand Up @@ -979,7 +979,7 @@ def test_fetch_parameters_from_easyconfig(self):
self.assertEqual(name, correct_name)
self.assertEqual(easyblock, correct_easyblock)

self.assertEqual(fetch_parameters_from_easyconfig(read_file(toy_ec_file), ['description'])[0], "Toy C program.")
self.assertEqual(fetch_parameters_from_easyconfig(read_file(toy_ec_file), ['description'])[0], "Toy C program, 100% toy.")

res = fetch_parameters_from_easyconfig("easyblock = 'ConfigureMake' # test comment", ['easyblock'])
self.assertEqual(res, ['ConfigureMake'])
Expand Down Expand Up @@ -1313,7 +1313,7 @@ def test_update(self):
self.assertEqual(ec['unpack_options'].strip(), '--strip-components=1')

ec.update('description', "- just a test")
self.assertEqual(ec['description'].strip(), "Toy C program. - just a test")
self.assertEqual(ec['description'].strip(), "Toy C program, 100% toy. - just a test")

# spaces in between multiple updates for stirng values
ec.update('configopts', 'CC="$CC"')
Expand Down
2 changes: 1 addition & 1 deletion test/framework/easyconfigs/test_ecs/t/toy/toy-0.0-deps.eb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ version = '0.0'
versionsuffix = '-deps'

homepage = 'http://hpcugent.github.com/easybuild'
description = "Toy C program."
description = "Toy C program, 100% toy."

toolchain = {'name': 'dummy', 'version': 'dummy'}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ version = '0.0'
versionsuffix = '-test'

homepage = 'http://hpcugent.github.com/easybuild'
description = "Toy C program."
description = "Toy C program, 100% toy."

toolchain = {'name': 'gompi', 'version': '1.3.12'}
toolchainopts = {'pic': True, 'opt': True, 'optarch': True}
Expand Down
2 changes: 1 addition & 1 deletion test/framework/easyconfigs/test_ecs/t/toy/toy-0.0-iter.eb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ version = '0.0'
versionsuffix = '-iter'

homepage = 'http://hpcugent.github.com/easybuild'
description = "Toy C program."
description = "Toy C program, 100% toy."

toolchain = {'name': 'dummy', 'version': 'dummy'}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ version = '0.0'
versionsuffix = '-multiple'

homepage = 'http://hpcugent.github.com/easybuild'
description = "Toy C program."
description = "Toy C program, 100% toy."

toolchain = {'name': 'dummy', 'version': 'dummy'}

Expand Down
2 changes: 1 addition & 1 deletion test/framework/easyconfigs/test_ecs/t/toy/toy-0.0.eb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name = 'toy'
version = '0.0'

homepage = 'http://hpcugent.github.com/easybuild'
description = "Toy C program."
description = "Toy C program, 100% toy."

toolchain = {'name': 'dummy', 'version': 'dummy'}

Expand Down
2 changes: 1 addition & 1 deletion test/framework/easyconfigs/v2.0/toy-with-sections.eb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ docstring test
name = "toy"

homepage = 'http://hpcugent.github.com/easybuild'
description = "Toy C program."
description = "Toy C program, 100% toy."
docurls = ["https://github.com/hpcugent/easybuild/wiki"]

software_license = GPLv2
Expand Down
2 changes: 1 addition & 1 deletion test/framework/easyconfigs/v2.0/toy.eb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ docstring test
name = "toy"

homepage = 'http://hpcugent.github.com/easybuild'
description = "Toy C program."
description = "Toy C program, 100% toy."
docurls = ["https://github.com/hpcugent/easybuild/wiki"]

software_license = GPLv2
Expand Down
2 changes: 1 addition & 1 deletion test/framework/easyconfigs/yeb/toy-0.0.yeb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ name: toy
version: 0.0

homepage: 'http://hpcugent.github.com/easybuild'
description: "Toy C program."
description: "Toy C program, 100% toy."

toolchain: dummy, dummy

Expand Down
4 changes: 2 additions & 2 deletions test/framework/module_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -643,8 +643,8 @@ def test_mns():
'gzip-1.4-GCC-4.6.3.eb': 'gzip/585eba598f33c64ef01c6fa47af0fc37f3751311',
'gzip-1.5-goolf-1.4.10.eb': 'gzip/fceb41e04c26b540b7276c4246d1ecdd1e8251c9',
'gzip-1.5-ictce-4.1.13.eb': 'gzip/ae16b3a0a330d4323987b360c0d024f244ac4498',
'toy-0.0.eb': 'toy/44a206d9e8c14130cc9f79e061468303c6e91b53',
'toy-0.0-multiple.eb': 'toy/44a206d9e8c14130cc9f79e061468303c6e91b53',
'toy-0.0.eb': 'toy/cb0859b7b15723c826cd8504e5fde2573ab7b687',
'toy-0.0-multiple.eb': 'toy/cb0859b7b15723c826cd8504e5fde2573ab7b687',
}
test_mns()

Expand Down
2 changes: 1 addition & 1 deletion test/framework/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -3055,7 +3055,7 @@ def test_check_style(self):
# introduce whitespace issues
toytxt = toytxt.replace("name = 'toy'", "name\t='toy' ")
# introduce long line
toytxt = toytxt.replace('description = "Toy C program."', 'description = "%s"' % ('toy ' * 30))
toytxt = toytxt.replace('description = "Toy C program, 100% toy."', 'description = "%s"' % ('toy ' * 30))
write_file(toy, toytxt)

args = [
Expand Down
2 changes: 1 addition & 1 deletion test/framework/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ def test_package(self):
self.assertFalse(no_logfiles_regex.search(pkgtxt), "Pattern not '%s' found in: %s" % (no_logfiles_regex.pattern, pkgtxt))

toy_txt = read_file(os.path.join(test_easyconfigs, 't', 'toy', 'toy-0.0-gompi-1.3.12-test.eb'))
replace_str = '''description = """Toy C program. Now with `backticks'\n'''
replace_str = '''description = """Toy C program, 100% toy. Now with `backticks'\n'''
replace_str += '''and newlines"""'''
toy_txt = re.sub('description = .*', replace_str, toy_txt)
toy_file = os.path.join(self.test_prefix, 'toy-test-description.eb')
Expand Down
14 changes: 7 additions & 7 deletions test/framework/toy_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,8 @@ def test_toy_tweaked(self):
"modloadmsg = '%s'" % modloadmsg,
"modtclfooter = 'puts stderr \"oh hai!\"'", # ignored when module syntax is Lua
"modluafooter = 'io.stderr:write(\"oh hai!\")'", # ignored when module syntax is Tcl
"usage = 'This toy is easy to use'",
"examples = 'No example available'",
"usage = 'This toy is easy to use, 100%!'",
"examples = 'No example available, 0% complete'",
"docpaths = ['share/doc/toy/readme.txt', 'share/doc/toy/html/index.html']",
"docurls = ['http://hpcugent.github.com/easybuild/toy/docs.html']",
"upstream_contacts = 'support@toy.org'",
Expand Down Expand Up @@ -954,17 +954,17 @@ def test_toy_module_fulltxt(self):
help_txt = '\n'.join([
r'Description',
r'===========',
r'Toy C program.',
r'Toy C program, 100% toy.',
r'',
r'',
r'Usage',
r'=====',
r'This toy is easy to use',
r'This toy is easy to use, 100%!',
r'',
r'',
r'Examples',
r'========',
r'No example available',
r'No example available, 0% complete',
r'',
r'',
r'More information',
Expand All @@ -986,7 +986,7 @@ def test_toy_module_fulltxt(self):
r'%s' % help_txt,
r'\]\]\)',
r'',
r'whatis\(\[\[Description: Toy C program.\]\]\)',
r'whatis\(\[\[Description: Toy C program, 100% toy.\]\]\)',
r'whatis\(\[\[Homepage: http://hpcugent.github.com/easybuild\]\]\)',
r'',
r'local root = "%s/software/toy/0.0-tweaked"' % self.test_installpath,
Expand Down Expand Up @@ -1022,7 +1022,7 @@ def test_toy_module_fulltxt(self):
r' }',
r'}',
r'',
r'module-whatis {Description: Toy C program.}',
r'module-whatis {Description: Toy C program, 100% toy.}',
r'module-whatis {Homepage: http://hpcugent.github.com/easybuild}',
r'',
r'set root %s/software/toy/0.0-tweaked' % self.test_installpath,
Expand Down