From: "Wolfgang E. Sanyer" <wolfgangesan...@gmail.com> Reviewed-by: Matt Turner <matts...@gentoo.org> Signed-off-by: Wolfgang E. Sanyer <wolfgangesan...@gmail.com> --- lib/portage/eapi.py | 155 ++++++++++++++++++++------------------------ 1 file changed, 72 insertions(+), 83 deletions(-)
diff --git a/lib/portage/eapi.py b/lib/portage/eapi.py index 56e64620a..efcc6c2a0 100644 --- a/lib/portage/eapi.py +++ b/lib/portage/eapi.py @@ -2,12 +2,10 @@ # Distributed under the terms of the GNU General Public License v2 import collections -import operator -import types - -from portage import eapi_is_supported +from functools import lru_cache +@lru_cache(None) def eapi_has_iuse_defaults(eapi): if eapi is None: return True @@ -15,6 +13,7 @@ def eapi_has_iuse_defaults(eapi): return eapi != "0" +@lru_cache(None) def eapi_has_iuse_effective(eapi): if eapi is None: return False @@ -22,6 +21,7 @@ def eapi_has_iuse_effective(eapi): return eapi not in ("0", "1", "2", "3", "4", "4-python", "4-slot-abi") +@lru_cache(None) def eapi_has_slot_deps(eapi): if eapi is None: return True @@ -29,6 +29,7 @@ def eapi_has_slot_deps(eapi): return eapi != "0" +@lru_cache(None) def eapi_has_slot_operator(eapi): if eapi is None: return True @@ -36,6 +37,7 @@ def eapi_has_slot_operator(eapi): return eapi not in ("0", "1", "2", "3", "4", "4-python") +@lru_cache(None) def eapi_has_src_uri_arrows(eapi): if eapi is None: return True @@ -43,6 +45,7 @@ def eapi_has_src_uri_arrows(eapi): return eapi not in ("0", "1") +@lru_cache(None) def eapi_has_selective_src_uri_restriction(eapi): if eapi is None: return True @@ -62,6 +65,7 @@ def eapi_has_selective_src_uri_restriction(eapi): ) +@lru_cache(None) def eapi_has_use_deps(eapi): if eapi is None: return True @@ -69,6 +73,7 @@ def eapi_has_use_deps(eapi): return eapi not in ("0", "1") +@lru_cache(None) def eapi_has_strong_blocks(eapi): if eapi is None: return True @@ -76,10 +81,12 @@ def eapi_has_strong_blocks(eapi): return eapi not in ("0", "1") +@lru_cache(None) def eapi_has_src_prepare_and_src_configure(eapi): return eapi not in ("0", "1") +@lru_cache(None) def eapi_supports_prefix(eapi): if eapi is None: return True @@ -87,6 +94,7 @@ def eapi_supports_prefix(eapi): return eapi not in ("0", "1", "2") +@lru_cache(None) def eapi_exports_AA(eapi): if eapi is None: return False @@ -94,6 +102,7 @@ def eapi_exports_AA(eapi): return eapi in ("0", "1", "2", "3") +@lru_cache(None) def eapi_exports_KV(eapi): if eapi is None: return False @@ -101,6 +110,7 @@ def eapi_exports_KV(eapi): return eapi in ("0", "1", "2", "3") +@lru_cache(None) def eapi_exports_merge_type(eapi): if eapi is None: return True @@ -108,6 +118,7 @@ def eapi_exports_merge_type(eapi): return eapi not in ("0", "1", "2", "3") +@lru_cache(None) def eapi_exports_replace_vars(eapi): if eapi is None: return True @@ -115,6 +126,7 @@ def eapi_exports_replace_vars(eapi): return eapi not in ("0", "1", "2", "3") +@lru_cache(None) def eapi_exports_EBUILD_PHASE_FUNC(eapi): if eapi is None: return True @@ -122,6 +134,7 @@ def eapi_exports_EBUILD_PHASE_FUNC(eapi): return eapi not in ("0", "1", "2", "3", "4", "4-python", "4-slot-abi") +@lru_cache(None) def eapi_exports_PORTDIR(eapi): if eapi is None: return True @@ -140,6 +153,7 @@ def eapi_exports_PORTDIR(eapi): ) +@lru_cache(None) def eapi_exports_ECLASSDIR(eapi): if eapi is None: return False @@ -158,22 +172,27 @@ def eapi_exports_ECLASSDIR(eapi): ) +@lru_cache(None) def eapi_exports_REPOSITORY(eapi): return eapi in ("4-python", "5-progress") +@lru_cache(None) def eapi_has_pkg_pretend(eapi): return eapi not in ("0", "1", "2", "3") +@lru_cache(None) def eapi_has_implicit_rdepend(eapi): return eapi in ("0", "1", "2", "3") +@lru_cache(None) def eapi_has_dosed_dohard(eapi): return eapi in ("0", "1", "2", "3") +@lru_cache(None) def eapi_has_required_use(eapi): if eapi is None: return True @@ -181,6 +200,7 @@ def eapi_has_required_use(eapi): return eapi not in ("0", "1", "2", "3") +@lru_cache(None) def eapi_has_required_use_at_most_one_of(eapi): if eapi is None: return True @@ -188,6 +208,7 @@ def eapi_has_required_use_at_most_one_of(eapi): return eapi not in ("0", "1", "2", "3", "4", "4-python", "4-slot-abi") +@lru_cache(None) def eapi_has_use_dep_defaults(eapi): if eapi is None: return True @@ -195,6 +216,7 @@ def eapi_has_use_dep_defaults(eapi): return eapi not in ("0", "1", "2", "3") +@lru_cache(None) def eapi_requires_posixish_locale(eapi): if eapi is None: return False @@ -212,6 +234,7 @@ def eapi_requires_posixish_locale(eapi): ) +@lru_cache(None) def eapi_has_repo_deps(eapi): if eapi is None: return True @@ -219,6 +242,7 @@ def eapi_has_repo_deps(eapi): return eapi in ("4-python", "5-progress") +@lru_cache(None) def eapi_allows_dots_in_PN(eapi): if eapi is None: return True @@ -226,6 +250,7 @@ def eapi_allows_dots_in_PN(eapi): return eapi in ("4-python", "5-progress") +@lru_cache(None) def eapi_allows_dots_in_use_flags(eapi): if eapi is None: return True @@ -233,22 +258,27 @@ def eapi_allows_dots_in_use_flags(eapi): return eapi in ("4-python", "5-progress") +@lru_cache(None) def eapi_supports_stable_use_forcing_and_masking(eapi): return eapi not in ("0", "1", "2", "3", "4", "4-python", "4-slot-abi") +@lru_cache(None) def eapi_allows_directories_on_profile_level_and_repository_level(eapi): return eapi not in ("0", "1", "2", "3", "4", "4-slot-abi", "5", "6") +@lru_cache(None) def eapi_has_use_aliases(eapi): return eapi in ("4-python", "5-progress") +@lru_cache(None) def eapi_has_automatic_unpack_dependencies(eapi): return eapi in ("5-progress",) +@lru_cache(None) def eapi_allows_package_provided(eapi): if eapi is None: return True @@ -267,6 +297,7 @@ def eapi_allows_package_provided(eapi): ) +@lru_cache(None) def eapi_has_bdepend(eapi): if eapi is None: return False @@ -285,6 +316,7 @@ def eapi_has_bdepend(eapi): ) +@lru_cache(None) def eapi_has_idepend(eapi): if eapi is None: return False @@ -304,6 +336,7 @@ def eapi_has_idepend(eapi): ) +@lru_cache(None) def eapi_empty_groups_always_true(eapi): if eapi is None: return False @@ -322,6 +355,7 @@ def eapi_empty_groups_always_true(eapi): ) +@lru_cache(None) def eapi_path_variables_end_with_trailing_slash(eapi): if eapi is None: return False @@ -340,6 +374,7 @@ def eapi_path_variables_end_with_trailing_slash(eapi): ) +@lru_cache(None) def eapi_has_broot(eapi): if eapi is None: return True @@ -358,6 +393,7 @@ def eapi_has_broot(eapi): ) +@lru_cache(None) def eapi_has_sysroot(eapi): if eapi is None: return True @@ -423,43 +459,7 @@ _eapi_attr_func_prefixes = ( ) -def _eapi_func_decorator(func, attr_getter): - def wrapper(eapi): - return attr_getter(_get_eapi_attrs(eapi)) - - wrapper.func = func - wrapper.__doc__ = func.__doc__ - return wrapper - - -def _decorate_eapi_funcs(): - """ - Decorate eapi_* functions so that they use _get_eapi_attrs(eapi) - to cache results. - """ - decorated = {} - for k, v in globals().items(): - if not ( - isinstance(v, types.FunctionType) and k.startswith(_eapi_attr_func_prefixes) - ): - continue - for prefix in _eapi_attr_func_prefixes: - if k.startswith(prefix): - attr_name = k[len(prefix) :] - if hasattr(_eapi_attrs, attr_name): - decorated[k] = _eapi_func_decorator( - v, operator.attrgetter(attr_name) - ) - break - globals().update(decorated) - - -_decorate_eapi_funcs() - - -_eapi_attrs_cache = {} - - +@lru_cache(None) def _get_eapi_attrs(eapi): """ When eapi is None then validation is not as strict, since we want the @@ -468,49 +468,38 @@ def _get_eapi_attrs(eapi): be helpful for handling of corrupt EAPI metadata in essential functions such as pkgsplit. """ - eapi_attrs = _eapi_attrs_cache.get(eapi) - if eapi_attrs is not None: - return eapi_attrs - - orig_eapi = eapi - if eapi is not None and not eapi_is_supported(eapi): - eapi = None - - eapi_attrs = _eapi_attrs( - allows_package_provided=eapi_allows_package_provided.func(eapi), - bdepend=eapi_has_bdepend.func(eapi), - broot=eapi_has_broot.func(eapi), - dots_in_PN=eapi_allows_dots_in_PN.func(eapi), - dots_in_use_flags=eapi_allows_dots_in_use_flags.func(eapi), - empty_groups_always_true=eapi_empty_groups_always_true.func(eapi), - exports_AA=eapi_exports_AA.func(eapi), - exports_EBUILD_PHASE_FUNC=eapi_exports_EBUILD_PHASE_FUNC.func(eapi), - exports_ECLASSDIR=eapi_exports_ECLASSDIR.func(eapi), - exports_KV=eapi_exports_KV.func(eapi), - exports_merge_type=eapi_exports_merge_type.func(eapi), - exports_PORTDIR=eapi_exports_PORTDIR.func(eapi), - exports_replace_vars=eapi_exports_replace_vars.func(eapi), + return _eapi_attrs( + allows_package_provided=eapi_allows_package_provided(eapi), + bdepend=eapi_has_bdepend(eapi), + broot=eapi_has_broot(eapi), + dots_in_PN=eapi_allows_dots_in_PN(eapi), + dots_in_use_flags=eapi_allows_dots_in_use_flags(eapi), + empty_groups_always_true=eapi_empty_groups_always_true(eapi), + exports_AA=eapi_exports_AA(eapi), + exports_EBUILD_PHASE_FUNC=eapi_exports_EBUILD_PHASE_FUNC(eapi), + exports_ECLASSDIR=eapi_exports_ECLASSDIR(eapi), + exports_KV=eapi_exports_KV(eapi), + exports_merge_type=eapi_exports_merge_type(eapi), + exports_PORTDIR=eapi_exports_PORTDIR(eapi), + exports_replace_vars=eapi_exports_replace_vars(eapi), feature_flag_test=False, - idepend=eapi_has_idepend.func(eapi), - iuse_defaults=eapi_has_iuse_defaults.func(eapi), - iuse_effective=eapi_has_iuse_effective.func(eapi), - path_variables_end_with_trailing_slash=eapi_path_variables_end_with_trailing_slash.func( + idepend=eapi_has_idepend(eapi), + iuse_defaults=eapi_has_iuse_defaults(eapi), + iuse_effective=eapi_has_iuse_effective(eapi), + path_variables_end_with_trailing_slash=eapi_path_variables_end_with_trailing_slash( eapi ), - posixish_locale=eapi_requires_posixish_locale.func(eapi), - prefix=eapi_supports_prefix.func(eapi), - repo_deps=eapi_has_repo_deps.func(eapi), - required_use=eapi_has_required_use.func(eapi), - required_use_at_most_one_of=eapi_has_required_use_at_most_one_of.func(eapi), - selective_src_uri_restriction=eapi_has_selective_src_uri_restriction.func(eapi), - slot_deps=eapi_has_slot_deps.func(eapi), - slot_operator=eapi_has_slot_operator.func(eapi), - src_uri_arrows=eapi_has_src_uri_arrows.func(eapi), - strong_blocks=eapi_has_strong_blocks.func(eapi), - sysroot=eapi_has_sysroot.func(eapi), - use_deps=eapi_has_use_deps.func(eapi), - use_dep_defaults=eapi_has_use_dep_defaults.func(eapi), + posixish_locale=eapi_requires_posixish_locale(eapi), + prefix=eapi_supports_prefix(eapi), + repo_deps=eapi_has_repo_deps(eapi), + required_use=eapi_has_required_use(eapi), + required_use_at_most_one_of=eapi_has_required_use_at_most_one_of(eapi), + selective_src_uri_restriction=eapi_has_selective_src_uri_restriction(eapi), + slot_deps=eapi_has_slot_deps(eapi), + slot_operator=eapi_has_slot_operator(eapi), + src_uri_arrows=eapi_has_src_uri_arrows(eapi), + strong_blocks=eapi_has_strong_blocks(eapi), + sysroot=eapi_has_sysroot(eapi), + use_deps=eapi_has_use_deps(eapi), + use_dep_defaults=eapi_has_use_dep_defaults(eapi), ) - - _eapi_attrs_cache[orig_eapi] = eapi_attrs - return eapi_attrs -- 2.34.1