Skip to content

Commit c5d1e8e

Browse files
pdgendtkartben
authored andcommitted
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 <pieter.degendt@basalte.be>
1 parent a8d44c3 commit c5d1e8e

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

scripts/west_commands/patch.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -530,7 +530,11 @@ def gh_fetch(self, args, yml, mods=None):
530530
@staticmethod
531531
def get_file_sha256sum(filename: Path) -> str:
532532
with open(filename, "rb") as fp:
533-
digest = hashlib.file_digest(fp, "sha256")
533+
# NOTE: If python 3.11 is the minimum, the following can be replaced with:
534+
# digest = hashlib.file_digest(fp, "sha256")
535+
digest = hashlib.new("sha256")
536+
while chunk := fp.read(2**10):
537+
digest.update(chunk)
534538

535539
return digest.hexdigest()
536540

0 commit comments

Comments
 (0)