Last active
December 26, 2025 05:21
-
-
Save maxswjeon/bb343dee39ceb114f7b21932a8cdee40 to your computer and use it in GitHub Desktop.
Update requirements.txt to include built wheel hash
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
| #!/bin/bash | |
| HASH_UPDATE_COUNT=0 | |
| TOTAL_WHEEL_COUNT=0 | |
| WHEEL_PATH="$1" | |
| REQUIREMENTS_FILE="$2" | |
| for whl in "$WHEEL_PATH"/*.whl; do | |
| TOTAL_WHEEL_COUNT=$((TOTAL_WHEEL_COUNT + 1)) | |
| pkg_name=$(basename "$whl" | sed 's/-[0-9].*//' | tr '[:upper:]' '[:lower:]' | tr '_' '-'); | |
| new_hash=$(sha256sum "$whl" | awk '{print $1}'); | |
| if ! grep -q "^${pkg_name}==" "$REQUIREMENTS_FILE"; then | |
| echo "Package ${pkg_name} not found in ${REQUIREMENTS_FILE}, skipping..." | |
| continue | |
| fi | |
| if grep -q "$new_hash" "$REQUIREMENTS_FILE"; then | |
| continue | |
| fi | |
| # Wheel was built from source (hash mismatch) | |
| # Check the requirements entry for the package is multiline | |
| HASH_UPDATE_COUNT=$((HASH_UPDATE_COUNT + 1)) | |
| if ! grep -q "^${pkg_name}==.*\\\\$" "$REQUIREMENTS_FILE"; then | |
| # Single line entry, convert to multiline with the new hash | |
| sed -i "/^${pkg_name}==/s/\$/ \\\\/" "$REQUIREMENTS_FILE" | |
| fi | |
| sed -i "/^${pkg_name}==/a --hash=sha256:${new_hash} # built from source\\\\" "$REQUIREMENTS_FILE" | |
| echo "Updated hash for package: ${pkg_name}" | |
| done | |
| echo "Updated hashes: ${HASH_UPDATE_COUNT}/${TOTAL_WHEEL_COUNT}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment