From 80636528e6d5b9bfd78a4d70eeb2fa6a56fcc6c8 Mon Sep 17 00:00:00 2001 From: Felix Moessbauer Date: Wed, 2 Oct 2024 10:22:14 +0200 Subject: [PATCH] repos: cache properties that run external commands Some of our properties internally run external VCS commands. As this can be quite costly, we now cache the result. This is correct, as the repo properties are referential transparent within a single kas invocation. As cached_property is not available for python<3.8, we add a dependency to the retrofit implementation in cached-property. Signed-off-by: Felix Moessbauer Signed-off-by: Jan Kiszka --- kas/repos.py | 9 +++++++-- setup.py | 3 ++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/kas/repos.py b/kas/repos.py index d7677f26..0b07d0b8 100644 --- a/kas/repos.py +++ b/kas/repos.py @@ -36,6 +36,11 @@ from .libkas import run_cmd_async, run_cmd from .kasusererror import KasUserError +if sys.version_info < (3, 8): + from cached_property import cached_property +else: + from functools import cached_property + __license__ = 'MIT' __copyright__ = 'Copyright (c) Siemens AG, 2017-2018' @@ -121,7 +126,7 @@ def effective_url(self): continue return self.url - @property + @cached_property def revision(self): if self.commit: (_, output) = run_cmd(self.get_commit_cmd(), @@ -144,7 +149,7 @@ def revision(self): return branch return None - @property + @cached_property def dirty(self): if not self.url: return True diff --git a/setup.py b/setup.py index 87079a7b..149e89d2 100644 --- a/setup.py +++ b/setup.py @@ -95,7 +95,8 @@ 'distro>=1.0.0,<2', 'jsonschema>=2.5.0,<5', 'kconfiglib>=14.1.0,<15', - 'GitPython>=3.1.0,<4' + 'GitPython>=3.1.0,<4', + "cached-property>=1.0,<2; python_version<'3.8'" ], # At least python 3.6 is needed by now: