public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
From: "Ralph Sennhauser" <sera@gentoo.org>
To: gentoo-commits@lists.gentoo.org
Subject: [gentoo-commits] proj/java-config:master commit in: src/java_config_2/, tests/testsuite/
Date: Sat, 28 Dec 2013 13:15:42 +0000 (UTC)	[thread overview]
Message-ID: <1388233590.4bf5f0fe191531185c15fb2efa48b06becbc08fd.sera@gentoo> (raw)

commit:     4bf5f0fe191531185c15fb2efa48b06becbc08fd
Author:     Ralph Sennhauser <sera <AT> gentoo <DOT> org>
AuthorDate: Fri Dec 27 16:49:15 2013 +0000
Commit:     Ralph Sennhauser <sera <AT> gentoo <DOT> org>
CommitDate: Sat Dec 28 12:26:30 2013 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/java-config.git;a=commit;h=4bf5f0fe

VersionManager: Drop dependency on Portage

Replace dep-string filtering with a much simpler but non validating
internal algorithm. BGO#464608

Add more tests

---
 src/java_config_2/VersionManager.py | 43 ++++++++++++++++++++++---------------
 tests/testsuite/VersionManager.py   | 12 ++++++++++-
 2 files changed, 37 insertions(+), 18 deletions(-)

diff --git a/src/java_config_2/VersionManager.py b/src/java_config_2/VersionManager.py
index c3fcc3f..7b94a8c 100644
--- a/src/java_config_2/VersionManager.py
+++ b/src/java_config_2/VersionManager.py
@@ -4,9 +4,6 @@
 # Copyright 2005-2013 Gentoo Foundation
 # Distributed under the terms of the GNU General Public license v2
 
-import sys
-sys.path.append("/usr/lib/portage/pym")
-
 from . import VM, Errors 
 from java_config_2.FileParser import *
 import os, glob, re
@@ -110,23 +107,35 @@ class VersionManager:
     def filter_depend( self, atoms ):
         """Filter the dependency string for useful information"""
 
-        import os
+        def dep_string_reduce(dep_string,enabled_useflags):
+            dest = []
+            tokens = iter(dep_string.split())
+            useflags = enabled_useflags.split()
+
+            for token in tokens:
+                if token[-1] == "?":
+                    if token[:-1] not in useflags:
+                        level = 0
+                        while 1:
+                            token = next(tokens)
+                            if token == "(":
+                                level+=1
+                            if token == ")":
+                                level-=1
+                                if level < 1:
+                                    break
+                    continue
+                elif token == "(" or token == ")":
+                    continue
+                else:
+                    dest.append(token)
+
+            return " ".join(dest)
+
         # gjl does not use use flags
         try:
             use = os.environ["USE"]
-
-            # Local import to avoid initializing portage elsewhere
-            try:
-                from portage.dep import use_reduce,paren_reduce
-            except ImportError:
-                from portage_dep import use_reduce,paren_reduce
-            from portage import flatten
-
-            # Normalize white space for Portage
-            atoms = " ".join(atoms.split())
-
-            # Remove conditional depends that are not turned on
-            atoms = " ".join(flatten(use_reduce(paren_reduce(atoms),uselist=use)))
+            atoms = dep_string_reduce(atoms, use)
         except KeyError:
             pass
         return atoms

diff --git a/tests/testsuite/VersionManager.py b/tests/testsuite/VersionManager.py
index 3700be8..cc8a50b 100644
--- a/tests/testsuite/VersionManager.py
+++ b/tests/testsuite/VersionManager.py
@@ -46,11 +46,21 @@ class TestVersionManager(unittest.TestCase):
         rmatch = "|| =virtual/jdk-1.5 =virtual/jdk-1.4 dev-java/ant-core java-virtuals/jaf"
         self.assertEquals(self.verman.filter_depend(self.example_dep_or), rmatch)
     
-    def test_filter_depend_use(self):
+    def test_filter_depend_use_enabled(self):
         os.environ["USE"] = "java"
         rmatch = ">=virtual/jdk-1.5* dev-java/ant-core java-virtuals/jaf"
         self.assertEquals(self.verman.filter_depend(self.example_dep_use), rmatch)
 
+    def test_filter_depend_use_disabled(self):
+        os.environ["USE"] = ""
+        rmatch = "dev-java/ant-core java-virtuals/jaf"
+        self.assertEquals(self.verman.filter_depend(self.example_dep_use), rmatch)
+
+    def test_filter_depend_use_unset(self):
+        del os.environ["USE"]
+        rmatch = self.example_dep_use
+        self.assertEquals(self.verman.filter_depend(self.example_dep_use), rmatch)
+
     def test_version_satisfies(self):
         vm = self.em.get_vm('sun-jdk-1.6')
         self.assertTrue(self.verman.version_satisfies('>=virtual/jdk-1.5', vm))


                 reply	other threads:[~2013-12-28 13:15 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1388233590.4bf5f0fe191531185c15fb2efa48b06becbc08fd.sera@gentoo \
    --to=sera@gentoo.org \
    --cc=gentoo-commits@lists.gentoo.org \
    --cc=gentoo-dev@lists.gentoo.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox