Skip to content

Instantly share code, notes, and snippets.

@Wind010
Created February 9, 2024 03:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Wind010/86026e01db6027df97b1932b66a3bc07 to your computer and use it in GitHub Desktop.
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
#!/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