-
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.
Requirements.txt writer adds hashes and a way to remember to update c…
…odemodder deps (#273) * bump security version * update tests to reference dependencies * requirements writer can write dependency hashes * add get_hashes script * add codemod_dependencies.txt * add timeout to request
- Loading branch information
1 parent
f5c8d5e
commit f58f46d
Showing
14 changed files
with
178 additions
and
58 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
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
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
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
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
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
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
9 changes: 9 additions & 0 deletions
9
src/codemodder/dependency_management/codemod_dependencies.txt
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,9 @@ | ||
# This is a temporary solution to use dependabot to alert us | ||
# when the dependencies our codemods inject (for example `security`, `defusedxml`, etc) have a version update. | ||
|
||
# If this file gets a dependabot update PR, we must also update the corresponding | ||
# dependency in dependency.py. Be sure to update the version AND the hashes. | ||
# Run `get-hashes pkg==version` to get the hashes. | ||
defusedxml==0.7.1 | ||
flask-wtf==1.2.0 | ||
security==1.2.1 |
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
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, timeout=60) | ||
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() |
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
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
Oops, something went wrong.