Created
February 9, 2024 03:00
-
-
Save Wind010/86026e01db6027df97b1932b66a3bc07 to your computer and use it in GitHub Desktop.
Regenerate the setup.py with dependencies found in project. Useful if requirements.txt is missing
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
#!/bin/bash | |
# Requires existing template setup.py | |
SETUP_PY_PATH="./setup.py" | |
# Requires pipdeptree | |
pip install pipdeptree | |
# Generate a dependency tree for your project | |
pipdeptree --warn silence --warn silence -r --warn silence --warn silence --warn silence > dependencies.txt | |
# Extract the dependencies from the tree | |
DEPENDENCIES=$(grep -oP "^\S+" dependencies.txt) | |
# Update setup.py with dependencies | |
echo "Updating setup.py with dependencies..." | |
sed -i.bak "s/\(install_requires\s*=\s*\)[^,]*\(,\)/\1$DEPENDENCIES\2/" "$SETUP_PY_PATH" | |
# Display a message | |
echo "setup.py has been updated with dependencies:" | |
cat "$SETUP_PY_PATH" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment