From eb4afe824c3942baae47626d4268b6d10ddb7fc3 Mon Sep 17 00:00:00 2001 From: Sebastian Luther Date: Fri, 15 Oct 2010 15:01:57 +0200 Subject: use_reduce: Next try on full reduction --- pym/portage/dep/__init__.py | 9 ++++++--- pym/portage/tests/dep/test_use_reduce.py | 17 ++++++++++++++--- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/pym/portage/dep/__init__.py b/pym/portage/dep/__init__.py index 3db2ae02d..60e94f0bd 100644 --- a/pym/portage/dep/__init__.py +++ b/pym/portage/dep/__init__.py @@ -445,7 +445,7 @@ def use_reduce(depstr, uselist=[], masklist=[], matchall=False, excludeall=[], i stack[level].extend(l[1]) elif len(l) == 1 and isinstance(l[0], list): # l = [[...]] - last = last_any_of_operator_level(level) + last = last_any_of_operator_level(level-1) if last == -1: if opconvert and isinstance(l[0], list) \ and l[0] and l[0][0] == '||': @@ -453,7 +453,10 @@ def use_reduce(depstr, uselist=[], masklist=[], matchall=False, excludeall=[], i else: stack[level].extend(l[0]) else: - stack[level].append(l[0]) + if opconvert and l[0] and l[0][0] == "||": + stack[level].extend(l[0][1:]) + else: + stack[level].append(l[0]) else: stack[level].extend(l) else: @@ -480,7 +483,7 @@ def use_reduce(depstr, uselist=[], masklist=[], matchall=False, excludeall=[], i stack[level].pop() stack[level].extend(l) else: - if opconvert and starts_with_any_of_dep(level): + if opconvert and ends_in_any_of_dep(level): #In opconvert mode, we have to move the operator from the level #above into the current list. stack[level].pop() diff --git a/pym/portage/tests/dep/test_use_reduce.py b/pym/portage/tests/dep/test_use_reduce.py index f7e9b1012..7c7286ad8 100644 --- a/pym/portage/tests/dep/test_use_reduce.py +++ b/pym/portage/tests/dep/test_use_reduce.py @@ -321,7 +321,7 @@ class UseReduce(TestCase): "A foo? ( || ( B || ( bar? ( || ( C D E ) ) !bar? ( F ) ) ) ) G", uselist = ["foo", "bar"], opconvert = True, - expected_result = ['A', ['||', 'B', ['||', 'C', 'D', 'E']], 'G']), + expected_result = ['A', ['||', 'B', 'C', 'D', 'E'], 'G']), UseReduceTestCase( "A foo? ( || ( B || ( bar? ( || ( C D E ) ) !bar? ( F ) ) ) ) G", uselist = ["foo", "bar"], @@ -376,7 +376,7 @@ class UseReduce(TestCase): "|| ( ( A B ) foo? ( || ( C D ) ) )", uselist = ["foo"], opconvert = True, - expected_result = [['||', ['A', 'B'], ['||', 'C', 'D']]]), + expected_result = [['||', ['A', 'B'], 'C', 'D']]), UseReduceTestCase( "|| ( ( A B ) foo? ( || ( C D ) ) )", @@ -392,6 +392,11 @@ class UseReduce(TestCase): "|| ( ( A B ) || ( C D || ( E ( F G ) || ( H ) ) ) )", expected_result = ['||', [['A', 'B'], 'C', 'D', 'E', ['F', 'G'], 'H']]), + UseReduceTestCase( + "|| ( ( A B ) || ( C D || ( E ( F G ) || ( H ) ) ) )", + opconvert = True, + expected_result = [['||', ['A', 'B'], 'C', 'D', 'E', ['F', 'G'], 'H']]), + UseReduceTestCase( "|| ( foo? ( A B ) )", uselist = ["foo"], @@ -419,7 +424,13 @@ class UseReduce(TestCase): UseReduceTestCase( "|| ( ( A B ) || ( foo? ( bar? ( ( C D || ( baz? ( E ) ( F G ) || ( H ) ) ) ) ) ) )", uselist = ["foo", "bar", "baz"], - expected_result = ['||', [['A', 'B'], 'C', 'D', '||', ['E', ['F', 'G'], 'H']]]), + expected_result = ['||', [['A', 'B'], ['C', 'D', '||', ['E', ['F', 'G'], 'H']]]]), + + UseReduceTestCase( + "|| ( ( A B ) || ( foo? ( bar? ( ( C D || ( baz? ( E ) ( F G ) || ( H ) ) ) ) ) ) )", + uselist = ["foo", "bar", "baz"], + opconvert = True, + expected_result = [['||', ['A', 'B'], ['C', 'D', ['||', 'E', ['F', 'G'], 'H']]]]), UseReduceTestCase( "|| ( foo? ( A B ) )", -- cgit v1.2.3-1-g7c22