Skip to content

Instantly share code, notes, and snippets.

@RobertKolner
Created November 11, 2021 10:22
Show Gist options
  • Save RobertKolner/f97871624323c00902a72326886557a0 to your computer and use it in GitHub Desktop.
Save RobertKolner/f97871624323c00902a72326886557a0 to your computer and use it in GitHub Desktop.
Use poetry to write requirements.txt. Potentially useful with pre-commit in cases when the project is deployed to a service that assumes existence of requirements.txt (for instance Google Cloud Functions).
#!/usr/bin/env bash
NEW_REQUIREMENTS=$(poetry export -f requirements.txt --without-hashes | cut -d';' -f1)
if [ ! -f requirements.txt ]; then
echo "requirements.txt does not exist!"
poetry export --without-hashes | cut -d';' -f1 > requirements.txt
exit 1
fi
REQUIREMENTS=$(cat requirements.txt)
if [ "$NEW_REQUIREMENTS" = "$REQUIREMENTS" ]; then
exit 0
else
echo "requirements.txt is not up to date!"
poetry export --without-hashes | cut -d';' -f1 > requirements.txt
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment