Skip to content

Commit

Permalink
package: Expand "*" to empty if it matches CC
Browse files Browse the repository at this point in the history
Closes: #36
Signed-off-by: Michał Górny <mgorny@gentoo.org>
  • Loading branch information
mgorny committed Apr 30, 2020
1 parent fe4daba commit 2e079dd
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 15 deletions.
3 changes: 2 additions & 1 deletion nattka/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -605,7 +605,8 @@ def sanity_check(self) -> int:
if (('*' in b.atoms or '^' in b.atoms)
and (arches_cced or cc_arches)):
try:
expanded_plist = expand_package_list(repo, b)
expanded_plist = expand_package_list(
repo, b, cc_arches or b.cc)
except ExpandImpossible:
pass

Expand Down
11 changes: 9 additions & 2 deletions nattka/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,18 +340,21 @@ def match_package_list(repo: UnconfiguredTree,

def expand_package_list(repo: UnconfiguredTree,
bug: BugInfo,
target_cc: typing.Iterable[str],
) -> str:
"""
Expand `*` and `^` entries in package list
`repo` is the repository, `bug` is the original bug to work on.
Returns new package list contents.
`target_cc` specifies expected CC list (to simplify "*"). Returns
new package list contents.
Note that this function assumes that match_package_list() has been
called already, and did not raise any exceptions, i.e. that the bug
is known to have a valid package list.
"""

target_cc = frozenset(target_cc)
ret = ''
prev_kw = None
for l in bug.atoms.splitlines(keepends=True):
Expand Down Expand Up @@ -379,9 +382,13 @@ def expand_package_list(repo: UnconfiguredTree,
pkg = select_best_version(m)
cur_kw = []
elif w == '*':
assert target_cc
match_keywords = get_suggested_keywords(
repo, pkg, bug.category == BugCategory.STABLEREQ)
if match_keywords:
if target_cc == set(f'{x}@gentoo.org'
for x in match_keywords):
w = ''
elif match_keywords:
w = ' '.join(
sorted(match_keywords, key=keyword_sort_key))
else:
Expand Down
10 changes: 5 additions & 5 deletions test/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -1430,7 +1430,7 @@ def test_sanity_expand_plist(self, bugz):
560322: BugInfo(BugCategory.STABLEREQ,
'test/mixed-keywords-3 *\r\n'
'test/amd64-testing-2 ^\r\n',
['amd64@gentoo.org', 'hppa@gentoo.org']),
['amd64@gentoo.org']),
}
bugz_inst.resolve_dependencies.return_value = (
bugz_inst.find_bugs.return_value)
Expand Down Expand Up @@ -1464,8 +1464,8 @@ def test_sanity_expand_plist_cc_arches(self, bugz):
bugz_inst.update_status.assert_called_with(
560322, True, None,
cc_add=['amd64@gentoo.org', 'hppa@gentoo.org'],
new_package_list=['test/mixed-keywords-3 amd64 hppa\r\n'
'test/amd64-testing-2 amd64 hppa\r\n'])
new_package_list=['test/mixed-keywords-3 \r\n'
'test/amd64-testing-2 \r\n'])
self.post_verify()

@patch('nattka.cli.NattkaBugzilla')
Expand Down Expand Up @@ -1505,8 +1505,8 @@ def test_sanity_expand_plist_after_cc(self, bugz):
bugz_inst.find_bugs.assert_called_with(bugs=[560322])
bugz_inst.update_status.assert_called_with(
560322, True, None,
new_package_list=['test/mixed-keywords-3 amd64 hppa\r\n'
'test/amd64-testing-2 amd64 hppa\r\n'])
new_package_list=['test/mixed-keywords-3 \r\n'
'test/amd64-testing-2 \r\n'])
self.post_verify()

@patch('nattka.cli.NattkaBugzilla')
Expand Down
38 changes: 31 additions & 7 deletions test/test_package.py
Original file line number Diff line number Diff line change
Expand Up @@ -821,7 +821,8 @@ def test_unmodified(self):
'''
self.assertEqual(
expand_package_list(self.repo,
BugInfo(BugCategory.STABLEREQ, data)),
BugInfo(BugCategory.STABLEREQ, data),
['amd64@gentoo.org', 'hppa@gentoo.org']),
data)

def test_asterisk_streq(self):
Expand All @@ -837,7 +838,8 @@ def test_asterisk_streq(self):
'''
self.assertEqual(
expand_package_list(self.repo,
BugInfo(BugCategory.STABLEREQ, data)),
BugInfo(BugCategory.STABLEREQ, data),
['hppa@gentoo.org']),
expect)

def test_asterisk_kwreq(self):
Expand All @@ -853,7 +855,25 @@ def test_asterisk_kwreq(self):
'''
self.assertEqual(
expand_package_list(self.repo,
BugInfo(BugCategory.KEYWORDREQ, data)),
BugInfo(BugCategory.KEYWORDREQ, data),
['hppa@gentoo.org']),
expect)

def test_asterisk_to_empty(self):
data = '''
test/mixed-keywords-3 *
test/mixed-keywords-4 ^
test/amd64-testing-1 ^
'''
expect = f'''
test/mixed-keywords-3 {""}
test/mixed-keywords-4 {""}
test/amd64-testing-1 {""}
'''
self.assertEqual(
expand_package_list(self.repo,
BugInfo(BugCategory.STABLEREQ, data),
['amd64@gentoo.org', 'hppa@gentoo.org']),
expect)

def test_above(self):
Expand All @@ -873,7 +893,8 @@ def test_above(self):
'''
self.assertEqual(
expand_package_list(self.repo,
BugInfo(BugCategory.STABLEREQ, data)),
BugInfo(BugCategory.STABLEREQ, data),
['hppa@gentoo.org']),
expect)

def test_above_empty(self):
Expand All @@ -887,7 +908,8 @@ def test_above_empty(self):
'''
self.assertEqual(
expand_package_list(self.repo,
BugInfo(BugCategory.STABLEREQ, data)),
BugInfo(BugCategory.STABLEREQ, data),
['hppa@gentoo.org']),
expect)

def test_above_empty_plus_keywords_left(self):
Expand All @@ -897,7 +919,8 @@ def test_above_empty_plus_keywords_left(self):
'''
with self.assertRaises(ExpandImpossible):
expand_package_list(self.repo,
BugInfo(BugCategory.STABLEREQ, data))
BugInfo(BugCategory.STABLEREQ, data),
['hppa@gentoo.org'])

def test_above_empty_plus_keywords_right(self):
data = '''
Expand All @@ -906,7 +929,8 @@ def test_above_empty_plus_keywords_right(self):
'''
with self.assertRaises(ExpandImpossible):
expand_package_list(self.repo,
BugInfo(BugCategory.STABLEREQ, data))
BugInfo(BugCategory.STABLEREQ, data),
['hppa@gentoo.org'])


class FakeEbuild(object):
Expand Down

0 comments on commit 2e079dd

Please sign in to comment.