Re: [gentoo-portage-dev] [PATCH 4/4] portage.eapi: use functools @lru_cache decorator instead of custom implementation

2022-02-26 Thread Zac Medico

On 2/26/22 10:04, Zac Medico wrote:

On 2/23/22 20:14, Matt Turner wrote:

From: "Wolfgang E. Sanyer" 

Reviewed-by: Matt Turner 
Signed-off-by: Wolfgang E. Sanyer 
---
  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"


I think this patch misses the point of the original caching mechanism. 
It doesn't make sense to cache results of the individual eapi_* 
functions if they no longer contribute to the _eapi_attrs cache.


To clarify, the only reason that the eapi_* functions were cached was so 
that they would trigger population of the _eapi_attrs cache. In the 
absence of this_eapi_attrs cache population feature, I doubt that it's 
very useful to put the lru_cache on the indivdual eapi_* functions.

--
Thanks,
Zac


OpenPGP_signature
Description: OpenPGP digital signature


Re: [gentoo-portage-dev] [PATCH 4/4] portage.eapi: use functools @lru_cache decorator instead of custom implementation

2022-02-26 Thread Zac Medico

On 2/23/22 20:14, Matt Turner wrote:

From: "Wolfgang E. Sanyer" 

Reviewed-by: Matt Turner 
Signed-off-by: Wolfgang E. Sanyer 
---
  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"


I think this patch misses the point of the original caching mechanism. 
It doesn't make sense to cache results of the individual eapi_* 
functions if they no longer contribute to the _eapi_attrs cache.

--
Thanks,
Zac


OpenPGP_signature
Description: OpenPGP digital signature


[gentoo-portage-dev] [PATCH 4/4] portage.eapi: use functools @lru_cache decorator instead of custom implementation

2022-02-23 Thread Matt Turner
From: "Wolfgang E. Sanyer" 

Reviewed-by: Matt Turner 
Signed-off-by: Wolfgang E. Sanyer 
---
 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):
 )