Last active
November 18, 2024 21:39
-
-
Save jaysin586/63cde4167bcd30f933588ce24260326f to your computer and use it in GitHub Desktop.
Pip Tools helper functions
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
# Compile all requirements.in files in current directory | |
# Usage: pipcompile [--quiet|-q] [--verbose|-v] | |
pipcompile() { | |
local quiet=false | |
# Parse arguments | |
while [[ "$#" -gt 0 ]]; do | |
case $1 in | |
--quiet|-q) quiet=true ;; | |
--verbose|-v) quiet=false ;; | |
*) echo "Unknown parameter: $1"; return 1 ;; | |
esac | |
shift | |
done | |
# Check pip-tools version and update if needed | |
echo "π Checking pip-tools version..." | |
local current_version=$(pip freeze | grep pip-tools | cut -d'=' -f3) | |
if [ "$quiet" = true ]; then | |
pip install --upgrade pip-tools >/dev/null 2>&1 | |
else | |
pip install --upgrade pip-tools | |
fi | |
local new_version=$(pip freeze | grep pip-tools | cut -d'=' -f3) | |
if [ "$current_version" != "$new_version" ]; then | |
echo "π Updated pip-tools from $current_version to $new_version" | |
else | |
echo "β¨ pip-tools is already at the latest version ($current_version)" | |
fi | |
# Check if any .in files exist | |
if ! compgen -G "*.in" > /dev/null; then | |
echo "β No .in files found in current directory" | |
return 1 | |
fi | |
echo "π¦ Compiling requirements files..." | |
for f in *.in; do | |
if [ "$quiet" = true ]; then | |
echo "π Compiling $f..." | |
pip-compile "$f" --upgrade >/dev/null 2>&1 | |
echo "β Done $f" | |
else | |
echo "π Compiling $f..." | |
pip-compile "$f" --upgrade | |
echo "β Done $f" | |
fi | |
done | |
echo "π All requirements files compiled!" | |
} | |
# Sync all requirements*.txt files in current directory | |
# Usage: pipsync [--verbose|-v] | |
pipsync() { | |
local quiet=true | |
# Parse arguments | |
while [[ "$#" -gt 0 ]]; do | |
case $1 in | |
--verbose|-v) quiet=false ;; | |
*) echo "Unknown parameter: $1"; return 1 ;; | |
esac | |
shift | |
done | |
# Check pip-tools version and update if needed | |
echo "π Checking pip-tools version..." | |
local current_version=$(pip freeze | grep pip-tools | cut -d'=' -f3) | |
if [ "$quiet" = true ]; then | |
pip install --upgrade pip-tools >/dev/null 2>&1 | |
else | |
pip install --upgrade pip-tools | |
fi | |
local new_version=$(pip freeze | grep pip-tools | cut -d'=' -f3) | |
if [ "$current_version" != "$new_version" ]; then | |
echo "π Updated pip-tools from $current_version to $new_version" | |
else | |
echo "β¨ pip-tools is already at the latest version ($current_version)" | |
fi | |
# Check if any requirements*.txt files exist | |
if ! compgen -G "requirements*.txt" > /dev/null; then | |
echo "β No requirements*.txt files found in current directory" | |
return 1 | |
fi | |
echo "π¦ Syncing requirements files..." | |
for f in requirements*.txt; do | |
echo "π Syncing $f..." | |
if [ "$quiet" = true ]; then | |
pip-sync "$f" >/dev/null 2>&1 | |
else | |
pip-sync "$f" | |
fi | |
echo "β Done $f" | |
done | |
echo "π All requirements files synced!" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment