Skip to content

Instantly share code, notes, and snippets.

Last active December 5, 2022 21:26
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
#!/usr/bin/env bash
# This is not an ideal solution (currently) to export into production/development specific
# requirements.
# Capture current system time
CURRENT_TIME=$(date +"%Y.%m.%d-%H.%M.%S")
# Capture all Python packages currently installed
pip3 list --not-required --format freeze --exclude lockfile --exclude pip --exclude setuptools >"requirements.txt.${CURRENT_TIME}"
# Install Poetry
pip3 install poetry
# Verify that Poetry has been initialized
if [ ! -f pyproject.toml ]; then
poetry init -n
# Add all currently install Python packages to Poetry
cat "requirements.txt.${CURRENT_TIME}" | grep -E '^[^# ]' | cut -d= -f1 | xargs -n 1 poetry add
# Make a backup copy of an existing requirements.txt file for future reference
if [ -f requirements.txt ]; then
mv requirements.txt "requirements.txt.${CURRENT_TIME}.old"
# Export Poetry packages back out to a new requirements.txt
poetry export --without-hashes >requirements.txt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment