* Replace config._iuse_implicit_re with a callable _iuse_implicit_match
authorZac Medico <zmedico@gentoo.org>
Wed, 18 Aug 2010 13:36:21 +0000 (06:36 -0700)
committerZac Medico <zmedico@gentoo.org>
Wed, 18 Aug 2010 13:36:21 +0000 (06:36 -0700)
  object that simply returns boolean, and update consumers.
* Make check_required_use() take a callable for the iuse parameter,
  and pass in Package.use.is_valid_flag or iuse.__contains__ as
   appropriate.

bin/repoman
pym/_emerge/Package.py
pym/_emerge/depgraph.py
pym/portage/dbapi/__init__.py
pym/portage/dep/__init__.py
pym/portage/package/ebuild/config.py
pym/portage/tests/dep/testCheckRequiredUse.py

index bfe126f1885d462226c736fb80bf78ef003877d8..4ba22739781a7b114e3148176dc2a3941ccf667e 100755 (executable)
@@ -1780,9 +1780,8 @@ for x in scanlist:
                                        relative_path + ": REQUIRED_USE" + \
                                        " not supported with EAPI='%s'" % (eapi,))
                        try:
-                               iuse = repoman_settings._get_implicit_iuse()
-                               iuse.update(myaux["IUSE"].split())
-                               portage.dep.check_required_use(required_use, "", iuse)
+                               portage.dep.check_required_use(required_use, (),
+                                       pkg.iuse.is_valid_flag)
                        except portage.exception.InvalidDependString as e:
                                stats["REQUIRED_USE.syntax"] = stats["REQUIRED_USE.syntax"] + 1
                                fails["REQUIRED_USE.syntax"].append(
index 2941b273ddba08ec4fb1d7d9bb5196753ed42788..640f8bca1b821638f04da21796088f7d976fcf9b 100644 (file)
@@ -201,11 +201,11 @@ class Package(Task):
        class _iuse(object):
 
                __slots__ = ("__weakref__", "all", "enabled", "disabled",
-                       "tokens") + ("_iuse_implicit_regex",)
+                       "tokens") + ("_iuse_implicit_match",)
 
-               def __init__(self, tokens, iuse_implicit_regex):
+               def __init__(self, tokens, iuse_implicit_match):
                        self.tokens = tuple(tokens)
-                       self._iuse_implicit_regex = iuse_implicit_regex
+                       self._iuse_implicit_match = iuse_implicit_match
                        enabled = []
                        disabled = []
                        other = []
@@ -231,7 +231,7 @@ class Package(Task):
 
                        for flag in flags:
                                if not flag in self.all and \
-                                       self._iuse_implicit_regex.match(flag) is None:
+                                       not self._iuse_implicit_match(flag):
                                        return False
                        return True
                
@@ -244,7 +244,7 @@ class Package(Task):
                        missing_iuse = []
                        for flag in flags:
                                if not flag in self.all and \
-                                       self._iuse_implicit_regex.match(flag) is None:
+                                       not self._iuse_implicit_match(flag):
                                        missing_iuse.append(flag)
                        return missing_iuse
 
@@ -362,7 +362,7 @@ class _PackageMetadataWrapper(_PackageMetadataWrapperBase):
 
        def _set_iuse(self, k, v):
                self._pkg.iuse = self._pkg._iuse(
-                       v.split(), self._pkg.root_config.settings._iuse_implicit_re)
+                       v.split(), self._pkg.root_config.settings._iuse_implicit_match)
 
        def _set_slot(self, k, v):
                self._pkg.slot = v
index 01afa88c1701a78e9390879d018e5762962e20aa..f4d2514786e951247e6fac146c37bd6b2849b2e1 100644 (file)
@@ -2036,7 +2036,6 @@ class depgraph(object):
                missing_licenses = []
                have_eapi_mask = False
                pkgsettings = self._frozen_config.pkgsettings[root]
-               implicit_iuse = pkgsettings._get_implicit_iuse()
                root_config = self._frozen_config.roots[root]
                portdb = self._frozen_config.roots[root].trees["porttree"].dbapi
                dbs = self._dynamic_config._filtered_trees[root]["dbs"]
@@ -2672,11 +2671,9 @@ class depgraph(object):
                                                eapi_has_required_use(pkg.metadata["EAPI"]):
                                                required_use = pkg.metadata["REQUIRED_USE"]
                                                use = pkg.use.enabled
-                                               iuse = self._frozen_config.settings._get_implicit_iuse()
-                                               iuse.update(pkg.iuse.all)
                                                try:
                                                        required_use_is_sat = portage.dep.check_required_use(
-                                                               pkg.metadata["REQUIRED_USE"], use, iuse)
+                                                               pkg.metadata["REQUIRED_USE"], use, pkg.iuse.is_valid_flag)
                                                except portage.exception.InvalidDependString as e:
                                                        portage.writemsg("!!! Invalid REQUIRED_USE specified by " + \
                                                                "'%s': %s\n" % (pkg.cpv, str(e)), noiselevel=-1)
@@ -6058,11 +6055,9 @@ def _get_masking_status(pkg, pkgsettings, root_config):
                        eapi_has_required_use(pkg.metadata["EAPI"]):
                        required_use = pkg.metadata["REQUIRED_USE"]
                        use = pkg.use.enabled
-                       iuse = pkgsettings._get_implicit_iuse()
-                       iuse.update(pkg.iuse.all)
                        try:
                                required_use_is_sat = portage.dep.check_required_use(
-                                       required_use, use, iuse)
+                                       required_use, use, pkg.iuse.is_valid_flag)
                        except portage.exception.InvalidDependString:
                                mreasons.append("invalid: REQUIRED_USE")
                        else:
index 99fb55723fc1883e1d30bb5032e7bd4afc0a1ee6..3803339d59bf71b89cbf5783d2ca9d21f7d9c845 100644 (file)
@@ -145,7 +145,7 @@ class dbapi(object):
                2) Check enabled/disabled flag states.
                """
 
-               iuse_implicit_re = self.settings._iuse_implicit_re
+               iuse_implicit_match = self.settings._iuse_implicit_match
                for cpv in cpv_iter:
                        try:
                                iuse, slot, use = self.aux_get(cpv, ["IUSE", "SLOT", "USE"])
@@ -156,7 +156,7 @@ class dbapi(object):
                        missing_iuse = False
                        for x in atom.use.required:
                                if x not in iuse and x not in atom.use.missing_enabled \
-                                       and x not in atom.use.missing_disabled and iuse_implicit_re.match(x) is None:
+                                       and x not in atom.use.missing_disabled and not iuse_implicit_match(x):
                                        missing_iuse = True
                                        break
                        if missing_iuse:
index 98d248938245c007e964ac53e8d408b62336f528..ecce5d0c52ecd8571657124b36df3d1d942d734f 100644 (file)
@@ -1635,7 +1635,7 @@ def match_from_list(mydep, candidate_list):
                        mylist.append(x)
        return mylist
 
-def check_required_use(required_use, use, iuse):
+def check_required_use(required_use, use, iuse_match):
        """
        Checks if the use flags listed in 'use' satisfy all
        constraints specified in 'constraints'.
@@ -1644,8 +1644,9 @@ def check_required_use(required_use, use, iuse):
        @type constraints: String
        @param use: Enabled use flags
        @param use: List
-       @param iuse: Referenceable use flags
-       @param iuse: List
+       @param iuse_match: Callable that takes a single flag argument and returns
+               True if the flag is matched, false otherwise,
+       @param iuse_match: Callable
        @rtype: Bool
        @return: Indicates if REQUIRED_USE constraints are satisfied
        """
@@ -1658,7 +1659,7 @@ def check_required_use(required_use, use, iuse):
                        flag = token
                        is_negated = False
 
-               if not flag or not flag in iuse:
+               if not flag or not iuse_match(flag):
                        raise portage.exception.InvalidDependString(
                                _("malformed syntax: '%s'") % required_use)
 
index b0cd72ce93152a18c1253f53a056607c4bd4d8f4..3c3d7260385128ff22bc210a4129a3968df27d9e 100644 (file)
@@ -110,15 +110,19 @@ def _lazy_iuse_regex(iuse_implicit):
 
 class _iuse_implicit_match_cache(object):
 
-       def __init__(self, iuse_implicit_re):
-               self._iuse_implicit_re = iuse_implicit_re
+       def __init__(self, settings):
+               self._iuse_implicit_re = re.compile("^(%s)$" % \
+                       "|".join(settings._get_implicit_iuse()))
                self._cache = {}
 
-       def match(self, flag):
+       def __call__(self, flag):
+               """
+               Returns True if the flag is matched, False otherwise.
+               """
                try:
                        return self._cache[flag]
                except KeyError:
-                       m = self._iuse_implicit_re.match(flag)
+                       m = self._iuse_implicit_re.match(flag) is not None
                        self._cache[flag] = m
                        return m
 
@@ -388,7 +392,7 @@ class config(object):
                        self.packages = clone.packages
                        self.useforce_list = clone.useforce_list
                        self.usemask_list = clone.usemask_list
-                       self._iuse_implicit_re = clone._iuse_implicit_re
+                       self._iuse_implicit_match = clone._iuse_implicit_match
 
                        self.user_profile_dir = copy.deepcopy(clone.user_profile_dir)
                        self.local_config = copy.deepcopy(clone.local_config)
@@ -1060,9 +1064,7 @@ class config(object):
                        if 'parse-eapi-ebuild-head' in self.features:
                                _validate_cache_for_unsupported_eapis = False
 
-                       self._iuse_implicit_re = _iuse_implicit_match_cache(
-                               re.compile("^(%s)$" % \
-                               "|".join(self._get_implicit_iuse())))
+                       self._iuse_implicit_match = _iuse_implicit_match_cache(self)
 
                for k in self._case_insensitive_vars:
                        if k in self:
@@ -1587,7 +1589,7 @@ class config(object):
                use = set(self["USE"].split())
                if explicit_iuse is None:
                        explicit_iuse = frozenset(x.lstrip("+-") for x in iuse.split())
-               implicit_iuse_re = self._iuse_implicit_re
+               iuse_implicit_match = self._iuse_implicit_match
                portage_iuse = self._get_implicit_iuse()
                portage_iuse.update(explicit_iuse)
 
@@ -1616,7 +1618,7 @@ class config(object):
                # Allow _* flags from USE_EXPAND wildcards to pass through here.
                use.difference_update([x for x in use \
                        if (x not in explicit_iuse and \
-                       implicit_iuse_re.match(x) is None) and x[-2:] != '_*'])
+                       not iuse_implicit_match(x)) and x[-2:] != '_*'])
 
                # Use the calculated USE flags to regenerate the USE_EXPAND flags so
                # that they are consistent. For optimal performance, use slice
index f09c963a86d4820fc61112266e83300c87e261d3..9468ca394d72f3bc17a3e761f4e5e2dedcf0f55c 100644 (file)
@@ -85,9 +85,9 @@ class TestCheckRequiredUse(TestCase):
                )
 
                for required_use, use, iuse, expected in test_cases:
-                       self.assertEqual(check_required_use(required_use, use, iuse), \
+                       self.assertEqual(check_required_use(required_use, use, iuse.__contains__), \
                                expected, required_use + ", USE = " + " ".join(use))
 
                for required_use, use, iuse in test_cases_xfail:
                        self.assertRaisesMsg(required_use + ", USE = " + " ".join(use), \
-                               InvalidDependString, check_required_use, required_use, use, iuse)
+                               InvalidDependString, check_required_use, required_use, use, iuse.__contains__)