Skip to content

Instantly share code, notes, and snippets.

@mrlesmithjr
Last active December 5, 2022 21:26
Show Gist options
  • Save mrlesmithjr/e77cf4b2dfe70fcc39013a0052fb66e4 to your computer and use it in GitHub Desktop.
Save mrlesmithjr/e77cf4b2dfe70fcc39013a0052fb66e4 to your computer and use it in GitHub Desktop.
#!/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
fi
# 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"
fi
# 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