From 8ca66119da487c97c9508fda3a78106163a59724 Mon Sep 17 00:00:00 2001 From: Adam Souzis Date: Wed, 30 Oct 2024 09:54:19 -0700 Subject: [PATCH] fix package digest when running from source tree --- unfurl/server/serve.py | 2 +- unfurl/util.py | 15 +++++++++------ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/unfurl/server/serve.py b/unfurl/server/serve.py index b58a5d71..cbdc2e4b 100644 --- a/unfurl/server/serve.py +++ b/unfurl/server/serve.py @@ -500,7 +500,7 @@ class CacheValue(NamedTuple): last_commit_date: int def make_etag(self) -> str: - etag = int(self.last_commit, 16) ^ int(get_package_digest(True), 16) + etag = int(self.last_commit, 16) ^ int(get_package_digest(True) or "0", 16) for dep in self.deps.values(): for last_commit in dep.last_commits: if last_commit: diff --git a/unfurl/util.py b/unfurl/util.py index b4d270f6..efce2fbc 100644 --- a/unfurl/util.py +++ b/unfurl/util.py @@ -87,13 +87,16 @@ def get_package_digest(commit_only=False) -> str: _package_digest = repo.git.log(n=1, pretty="format:%h") else: _package_digest = repo.git.describe("--dirty", "--always", "--match=v*") - - try: - pbr = [p for p in files("unfurl") if "pbr.json" in str(p)][0] # type: ignore # Ignored because of the try/except - _package_digest = json.loads(pbr.read_text())["git_version"] - except Exception: + else: _package_digest = "" - return cast(str, _package_digest) + pkg_files = files("unfurl") + if pkg_files: + try: + pbr = [p for p in pkg_files if "pbr.json" in str(p)][0] + _package_digest = json.loads(pbr.read_text())["git_version"] + except Exception: + _package_digest = "" + return str(_package_digest) class UnfurlError(Exception):