Skip to content

Instantly share code, notes, and snippets.

@u8sand
Last active June 29, 2020 14:58
Show Gist options
  • Save u8sand/41c3e15e28d9f3ca71cb9e77defe69ac to your computer and use it in GitHub Desktop.
Save u8sand/41c3e15e28d9f3ca71cb9e77defe69ac to your computer and use it in GitHub Desktop.
One-liners for ensuring requirements.txt / system deps match
# Produce a unified requirements.txt (no guarantees this comparison works properly for all versioning cases)
cat requirements.txt <(pip freeze) | awk 'BEGIN { FS="=="; OFS="==" } { if (V[tolower($1)] != "") { if ($2 != V[tolower($1)]) { print $1, $2 } else { print $1, V[tolower($1)] } } else { V[tolower($1)]=$2 } }'
# Produce a diff for manual inspection
cat requirements.txt <(pip freeze) | awk 'BEGIN { FS="=="; OFS="==" } { if (V[tolower($1)] != "") { if ($2 != V[tolower($1)]) { print "- "$1, V[tolower($1)]; print "+ "$1, $2 } else { print " "$1, $2 } } else { V[tolower($1)]=$2 } }'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment