-
Notifications
You must be signed in to change notification settings - Fork 2
feat(sha): add multiple SHA algorithm for the user to chose #13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Rignchen
wants to merge
3
commits into
Stoupy51:main
Choose a base branch
from
Rignchen:feature/sha
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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
19
python_package/stewbeet/plugins/compute_sha/sha1/__init__.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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")) | ||
|
|
File renamed without changes.
19 changes: 19 additions & 0 deletions
19
python_package/stewbeet/plugins/compute_sha/sha224/__init__.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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
11
python_package/stewbeet/plugins/compute_sha/sha224/silent.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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
19
python_package/stewbeet/plugins/compute_sha/sha256/__init__.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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
11
python_package/stewbeet/plugins/compute_sha/sha256/silent.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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
19
python_package/stewbeet/plugins/compute_sha/sha384/__init__.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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
11
python_package/stewbeet/plugins/compute_sha/sha384/silent.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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
19
python_package/stewbeet/plugins/compute_sha/sha512/__init__.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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
11
python_package/stewbeet/plugins/compute_sha/sha512/silent.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) | ||
|
|
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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