diff options
author | Zac Medico <zmedico@gentoo.org> | 2010-08-18 06:36:21 -0700 |
---|---|---|
committer | Zac Medico <zmedico@gentoo.org> | 2010-08-18 06:36:21 -0700 |
commit | ebee561758d81d7f3376ce316ff2ea9b6ae13c77 (patch) | |
tree | 72d458b2d93e7c8c41e3335e1f90c38aaa7a06d1 | |
parent | 97d78cd3f204010a1cedef481a52829931435adc (diff) | |
download | portage-ebee561758d81d7f3376ce316ff2ea9b6ae13c77.tar.gz portage-ebee561758d81d7f3376ce316ff2ea9b6ae13c77.tar.bz2 portage-ebee561758d81d7f3376ce316ff2ea9b6ae13c77.zip |
* Replace config._iuse_implicit_re with a callable _iuse_implicit_match
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.
-rwxr-xr-x | bin/repoman | 5 | ||||
-rw-r--r-- | pym/_emerge/Package.py | 12 | ||||
-rw-r--r-- | pym/_emerge/depgraph.py | 9 | ||||
-rw-r--r-- | pym/portage/dbapi/__init__.py | 4 | ||||
-rw-r--r-- | pym/portage/dep/__init__.py | 9 | ||||
-rw-r--r-- | pym/portage/package/ebuild/config.py | 22 | ||||
-rw-r--r-- | pym/portage/tests/dep/testCheckRequiredUse.py | 4 |
7 files changed, 31 insertions, 34 deletions
diff --git a/bin/repoman b/bin/repoman index bfe126f18..4ba227397 100755 --- a/bin/repoman +++ b/bin/repoman @@ -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( diff --git a/pym/_emerge/Package.py b/pym/_emerge/Package.py index 2941b273d..640f8bca1 100644 --- a/pym/_emerge/Package.py +++ b/pym/_emerge/Package.py @@ -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 diff --git a/pym/_emerge/depgraph.py b/pym/_emerge/depgraph.py index 01afa88c1..f4d251478 100644 --- a/pym/_emerge/depgraph.py +++ b/pym/_emerge/depgraph.py @@ -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: diff --git a/pym/portage/dbapi/__init__.py b/pym/portage/dbapi/__init__.py index 99fb55723..3803339d5 100644 --- a/pym/portage/dbapi/__init__.py +++ b/pym/portage/dbapi/__init__.py @@ -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: diff --git a/pym/portage/dep/__init__.py b/pym/portage/dep/__init__.py index 98d248938..ecce5d0c5 100644 --- a/pym/portage/dep/__init__.py +++ b/pym/portage/dep/__init__.py @@ -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) diff --git a/pym/portage/package/ebuild/config.py b/pym/portage/package/ebuild/config.py index b0cd72ce9..3c3d72603 100644 --- a/pym/portage/package/ebuild/config.py +++ b/pym/portage/package/ebuild/config.py @@ -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 diff --git a/pym/portage/tests/dep/testCheckRequiredUse.py b/pym/portage/tests/dep/testCheckRequiredUse.py index f09c963a8..9468ca394 100644 --- a/pym/portage/tests/dep/testCheckRequiredUse.py +++ b/pym/portage/tests/dep/testCheckRequiredUse.py @@ -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__) |