-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
32238ce
commit f9ef0f3
Showing
2 changed files
with
49 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
|
@@ -37,4 +37,5 @@ repos: | |
"types-mock==5.0.*", | ||
"types-PyYAML==6.0", | ||
"types-toml~=0.10", | ||
"types-requests~=2.13", | ||
] |
This file contains 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,48 @@ | ||
import requests | ||
import sys | ||
|
||
|
||
def get_package_hashes(package_name: str, version: str) -> list[str]: | ||
""" | ||
Fetch the SHA256 hashes for a given package version from PyPI. | ||
""" | ||
url = f"https://pypi.org/pypi/{package_name}/{version}/json" | ||
response = requests.get(url) | ||
hashes = [] | ||
|
||
if response.status_code == 200: | ||
data = response.json() | ||
for release in data.get("urls", []): | ||
sha256 = release.get("digests", {}).get("sha256") | ||
if sha256: | ||
hashes.append(sha256) | ||
else: | ||
print(f"Failed to fetch data for {package_name}=={version}", file=sys.stderr) | ||
|
||
return hashes | ||
|
||
|
||
def main(): | ||
if len(sys.argv) < 2: | ||
print("Usage: python script.py package1==version package2==version") | ||
sys.exit(1) | ||
for arg in sys.argv[1:]: | ||
if "==" not in arg: | ||
print( | ||
f"Invalid format '{arg}'. Expected format: PackageName==Version", | ||
file=sys.stderr, | ||
) | ||
continue | ||
|
||
package_name, version = arg.split("==", 1) | ||
hashes = get_package_hashes(package_name, version) | ||
if hashes: | ||
print(f"SHA256 hashes for {package_name}=={version}:") | ||
for hash_value in hashes: | ||
print(hash_value) | ||
else: | ||
print(f"No hashes found for {package_name}=={version}") | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |