Skip to content

Commit da3532b

Browse files
committed
handle non-indented comment on list item via 'iterabove' in extract_comments
1 parent f7c14da commit da3532b

File tree

2 files changed

+5
-7
lines changed

2 files changed

+5
-7
lines changed

easybuild/framework/easyconfig/format/one.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -231,10 +231,7 @@ def _get_item_comments(self, key, val):
231231
"""Get per-item comments for specified parameter name/value."""
232232
item_comments = {}
233233

234-
cand_above_comments = list(self.comments['iterabove'].get(key, {}).items())
235-
cand_above_comments.extend(list(self.comments['above'].items()))
236-
237-
for comment_key, comment_val in cand_above_comments:
234+
for comment_key, comment_val in self.comments['iterabove'].get(key, {}).items():
238235
if str(val) in comment_key:
239236
item_comments['above'] = comment_val
240237

@@ -434,9 +431,10 @@ def grab_more_comment_lines(lines, param_key):
434431
self.comments['above'][last_param_key] = comment
435432
else:
436433
# if the comment is not above a parameter definition,
437-
# just use the whole next line to determine where the comment belongs...
434+
# then it must be a comment for an item of an iterable parameter value
438435
before_comment, _ = split_on_comment_hash(rawlines[0], last_param_key)
439-
self.comments['above'][before_comment.rstrip()] = comment
436+
comment_key = before_comment.rstrip()
437+
self.comments['iterabove'].setdefault(last_param_key, {})[comment_key] = comment
440438
else:
441439
# if there are no more lines, the comment (block) is at the tail
442440
self.comments['tail'] = comment

test/framework/easyconfig.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1964,7 +1964,6 @@ def test_dump_comments(self):
19641964

19651965
# check internal structure to keep track of comments
19661966
self.assertEqual(ec.parser._formatter.comments['above'], {
1967-
" 'https://anotherexample.com',": ['# annoying non-indented comment'],
19681967
'dependencies': [
19691968
'# this is a multiline comment above dependencies',
19701969
'# I said multiline',
@@ -2004,6 +2003,7 @@ def test_dump_comments(self):
20042003
},
20052004
'source_urls': {
20062005
" 'https://example.com',": ['# first possible source URL'],
2006+
" 'https://anotherexample.com',": ['# annoying non-indented comment'],
20072007
},
20082008
})
20092009
self.assertEqual(ec.parser._formatter.comments['iterinline'], {

0 commit comments

Comments
 (0)