Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions python_package/stewbeet/plugins/compute_sha/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@

# Imports
import hashlib
import os
from typing import Callable

import stouputils as stp
from beet import Context

from ...core.__memory__ import Mem

def compute_hashes(ctx: Context, algorithm: tuple[Callable[[bytes],str],str]) -> None:
""" Main entry point for the compute SHA plugin.
This plugin computes SHA hashes for each zip file in the build folder.

Args:
ctx (Context): The beet context.
algorithm (tuple[Callable[[bytes],str],str]): A tuple containing the hashing function and the name of the algorithm.
"""
if Mem.ctx is None: # pyright: ignore[reportUnnecessaryComparison]
Mem.ctx = ctx

# Assertions
assert Mem.ctx.output_directory, "Output directory must be specified in the project configuration."

# Get SHA hash for each zip file in build folder
sha_hashes: dict[str, str] = {}
for file in os.listdir(Mem.ctx.output_directory):
if file.endswith(".zip"):
with open(f"{Mem.ctx.output_directory}/{file}", "rb") as f:
sha_hashes[file] = algorithm[0](f.read())

# Write SHA hashes to JSON file
stp.json_dump(sha_hashes, f"{Mem.ctx.output_directory}/{algorithm[1]}_hashes.json")

# Main entry point
@stp.measure_time(message="Execution time of 'stewbeet.plugins.compute_sha'")
def beet_default(ctx: Context) -> None:
""" Main entry point for the compute SHA plugin.
This plugin computes sha1 hashes for each zip file in the build folder.

Args:
ctx (Context): The beet context.
"""
return compute_hashes(ctx, (lambda f: hashlib.sha1(f).hexdigest(), "sha1"))

19 changes: 19 additions & 0 deletions python_package/stewbeet/plugins/compute_sha/sha1/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@

# Imports
import hashlib

import stouputils as stp
from beet import Context
from ..__init__ import compute_hashes

# Main entry point
@stp.measure_time(message="Execution time of 'stewbeet.plugins.compute_sha.sha1")
def beet_default(ctx: Context) -> None:
""" Main entry point for the compute SHA.sha1 plugin.
This plugin computes sha1 hashes for each zip file in the build folder.

Args:
ctx (Context): The beet context.
"""
return compute_hashes(ctx, (lambda f: hashlib.sha1(f).hexdigest(), "sha1"))

19 changes: 19 additions & 0 deletions python_package/stewbeet/plugins/compute_sha/sha224/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@

# Imports
import hashlib

import stouputils as stp
from beet import Context
from ..__init__ import compute_hashes

# Main entry point
@stp.measure_time(message="Execution time of 'stewbeet.plugins.compute_sha.sha224")
def beet_default(ctx: Context) -> None:
""" Main entry point for the compute SHA.sha224 plugin.
This plugin computes sha224 hashes for each zip file in the build folder.

Args:
ctx (Context): The beet context.
"""
return compute_hashes(ctx, (lambda f: hashlib.sha224(f).hexdigest(), "sha224"))

11 changes: 11 additions & 0 deletions python_package/stewbeet/plugins/compute_sha/sha224/silent.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

# Imports
import stouputils as stp
from beet import Context


# Silent mode entry point
def beet_default(ctx: Context) -> None:
from .__init__ import beet_default
return stp.silent(beet_default)(ctx)

19 changes: 19 additions & 0 deletions python_package/stewbeet/plugins/compute_sha/sha256/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@

# Imports
import hashlib

import stouputils as stp
from beet import Context
from ..__init__ import compute_hashes

# Main entry point
@stp.measure_time(message="Execution time of 'stewbeet.plugins.compute_sha.sha256")
def beet_default(ctx: Context) -> None:
""" Main entry point for the compute SHA.sha256 plugin.
This plugin computes sha256 hashes for each zip file in the build folder.

Args:
ctx (Context): The beet context.
"""
return compute_hashes(ctx, (lambda f: hashlib.sha256(f).hexdigest(), "sha256"))

11 changes: 11 additions & 0 deletions python_package/stewbeet/plugins/compute_sha/sha256/silent.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

# Imports
import stouputils as stp
from beet import Context


# Silent mode entry point
def beet_default(ctx: Context) -> None:
from .__init__ import beet_default
return stp.silent(beet_default)(ctx)

19 changes: 19 additions & 0 deletions python_package/stewbeet/plugins/compute_sha/sha384/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@

# Imports
import hashlib

import stouputils as stp
from beet import Context
from ..__init__ import compute_hashes

# Main entry point
@stp.measure_time(message="Execution time of 'stewbeet.plugins.compute_sha.sha384")
def beet_default(ctx: Context) -> None:
""" Main entry point for the compute SHA.sha384 plugin.
This plugin computes sha384 hashes for each zip file in the build folder.

Args:
ctx (Context): The beet context.
"""
return compute_hashes(ctx, (lambda f: hashlib.sha384(f).hexdigest(), "sha384"))

11 changes: 11 additions & 0 deletions python_package/stewbeet/plugins/compute_sha/sha384/silent.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

# Imports
import stouputils as stp
from beet import Context


# Silent mode entry point
def beet_default(ctx: Context) -> None:
from .__init__ import beet_default
return stp.silent(beet_default)(ctx)

19 changes: 19 additions & 0 deletions python_package/stewbeet/plugins/compute_sha/sha512/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@

# Imports
import hashlib

import stouputils as stp
from beet import Context
from ..__init__ import compute_hashes

# Main entry point
@stp.measure_time(message="Execution time of 'stewbeet.plugins.compute_sha.sha512")
def beet_default(ctx: Context) -> None:
""" Main entry point for the compute SHA.sha512 plugin.
This plugin computes sha512 hashes for each zip file in the build folder.

Args:
ctx (Context): The beet context.
"""
return compute_hashes(ctx, (lambda f: hashlib.sha512(f).hexdigest(), "sha512"))

11 changes: 11 additions & 0 deletions python_package/stewbeet/plugins/compute_sha/sha512/silent.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

# Imports
import stouputils as stp
from beet import Context


# Silent mode entry point
def beet_default(ctx: Context) -> None:
from .__init__ import beet_default
return stp.silent(beet_default)(ctx)

11 changes: 11 additions & 0 deletions python_package/stewbeet/plugins/compute_sha/silent.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

# Imports
import stouputils as stp
from beet import Context


# Silent mode entry point
def beet_default(ctx: Context) -> None:
from .__init__ import beet_default
return stp.silent(beet_default)(ctx)

36 changes: 0 additions & 36 deletions python_package/stewbeet/plugins/compute_sha1/__init__.py

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What I don't like is that this introduce a breaking change

This file was deleted.

2 changes: 1 addition & 1 deletion templates/basic/beet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ pipeline:
- "stewbeet.plugins.archive"
- "stewbeet.plugins.merge_smithed_weld"
- "stewbeet.plugins.copy_to_destination"
- "stewbeet.plugins.compute_sha1"
- "stewbeet.plugins.compute_sha"

# Generic dict which holds extra information usable by plugins
meta:
Expand Down
2 changes: 1 addition & 1 deletion templates/extensive/beet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ pipeline:
- "stewbeet.plugins.archive"
- "stewbeet.plugins.merge_smithed_weld"
- "stewbeet.plugins.copy_to_destination"
- "stewbeet.plugins.compute_sha1"
- "stewbeet.plugins.compute_sha"

# Generic dict which holds extra information usable by plugins
meta:
Expand Down
Loading