Skip to content

Commit

Permalink
repos: cache properties that run external commands
Browse files Browse the repository at this point in the history
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 <[email protected]>
Signed-off-by: Jan Kiszka <[email protected]>
  • Loading branch information
fmoessbauer authored and jan-kiszka committed Oct 2, 2024
1 parent 58cba07 commit 8063652
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
9 changes: 7 additions & 2 deletions kas/repos.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down Expand Up @@ -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(),
Expand All @@ -144,7 +149,7 @@ def revision(self):
return branch
return None

@property
@cached_property
def dirty(self):
if not self.url:
return True
Expand Down
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 8063652

Please sign in to comment.