From 86cdb1fc3bc5937c04a5f09e2d46defe0c5239d7 Mon Sep 17 00:00:00 2001 From: Ben Zhang Date: Sun, 30 Jun 2024 01:54:40 +0000 Subject: [PATCH] Implement deduplication for WATcloud URI --- src/agent.py | 2 +- src/watcloud_uri.py | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/agent.py b/src/agent.py index a72fc97..93e1435 100644 --- a/src/agent.py +++ b/src/agent.py @@ -16,7 +16,7 @@ def run_agent(): logging.info("Extracting WATcloud URIs") watcloud_uris = list( # sorting to ensure consistent order for testing - sorted(flatten([get_watcloud_uris(repo.working_dir) for repo in repos])) + sorted(set(flatten([get_watcloud_uris(repo.working_dir) for repo in repos]))) ) logging.info(f"Found {len(watcloud_uris)} WATcloud URIs:") diff --git a/src/watcloud_uri.py b/src/watcloud_uri.py index 991740e..c7be275 100644 --- a/src/watcloud_uri.py +++ b/src/watcloud_uri.py @@ -47,6 +47,12 @@ def __repr__(self) -> str: def __lt__(self, other): return self.sha256 < other.sha256 + def __eq__(self, other): + return self.sha256 == other.sha256 + + def __hash__(self): + return hash(self.sha256) + if __name__ == "__main__": # Example usage uri = WATcloudURI("watcloud://v1/sha256:906f98c1d660a70a6b36ad14c559a9468fe7712312beba1d24650cc379a62360?name=cloud-light.avif")