Skip to content

Instantly share code, notes, and snippets.

@mastrobirraio
Last active April 21, 2020 14:05
Show Gist options
  • Save mastrobirraio/a354b3805432834aa23329ccdc947085 to your computer and use it in GitHub Desktop.
Save mastrobirraio/a354b3805432834aa23329ccdc947085 to your computer and use it in GitHub Desktop.
Recreate project requirements script
Color_Off='\033[0m' # Text Reset
Red='\033[0;31m' # Red
Green='\033[0;32m' # Green
REQUIREMENTS_PATH="${PWD}/requirements.txt"
function print_out {
COLOR=$1
MESSAGE=$2
echo "${COLOR}${MESSAGE}${Color_Off}"
}
# Informations
echo "Local: $PWD"
echo "Python version: $(which python3)"
echo "PIP version: $(which pip3)"
echo "Target file: ${REQUIREMENTS_PATH}"
# Requirements recreation
unlink $REQUIREMENTS_PATH
pip3 freeze > $REQUIREMENTS_PATH
# Final check
if [ -f "$REQUIREMENTS_PATH" ]; then
print_out $Green "Requirements succesfully created at: ${REQUIREMENTS_PATH}"
else
print_out $Red "Error during requirements creation"
fi
@mastrobirraio
Copy link
Author

mastrobirraio commented Apr 18, 2020

mkrequirements

This script allows to create/rewrite using only a command a requirements.txt for a python project.

Getting Started

These instructions will get you a copy of the script running on your local machine.

Setup

Create a directory in your home

mkdir ~/.devtools

Get the script

cd ~/.devtools
wget https://gist.githubusercontent.com/mastrobirraio/a354b3805432834aa23329ccdc947085/raw/c7b5c6dc94ae16efa49006cc3ee48f60c766983c/mkrequirements.sh

Create an alias in your .bashrc or .zshrc and load it

echo 'alias mkrequirements="sh ~/.devtools/mkrequirements.sh"' >> ~/.bashrc
source ~/.bashrc  # or ~/.zshrc

Usage

Go to the directory containing requirements.txt or directory you want to create it. And start command:

$ mkrequirements
Local: /home/user/my-awasome-project
Python version: /home/user/my-awasome-project/venv/bin/python3
PIP version: /home/user/my-awasome-project/venv/bin/pip3
Target file: /home/user/my-awasome-project/requirements.txt
Requirements succesfully created at: /home/user/my-awasome-project/requirements.txt

Author

Giuseppe "mastrobirraio" Matranga - mastrobirraio

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment