From c5d1e8e2202802e42bb58fdfe36a347d1ec39cbf Mon Sep 17 00:00:00 2001 From: Pieter De Gendt Date: Tue, 3 Jun 2025 08:40:58 +0200 Subject: [PATCH] scripts: west_commands: patch: Support Python 3.10 The west patch command used hashlib.file_digest which was introduced in Python 3.11. Replace with a loop to support Python 3.10 (the current minimum). Signed-off-by: Pieter De Gendt --- scripts/west_commands/patch.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/scripts/west_commands/patch.py b/scripts/west_commands/patch.py index 618a45bc66a..19aa5a4c4a7 100644 --- a/scripts/west_commands/patch.py +++ b/scripts/west_commands/patch.py @@ -530,7 +530,11 @@ class Patch(WestCommand): @staticmethod def get_file_sha256sum(filename: Path) -> str: with open(filename, "rb") as fp: - digest = hashlib.file_digest(fp, "sha256") + # NOTE: If python 3.11 is the minimum, the following can be replaced with: + # digest = hashlib.file_digest(fp, "sha256") + digest = hashlib.new("sha256") + while chunk := fp.read(2**10): + digest.update(chunk) return digest.hexdigest()