Skip to content

Instantly share code, notes, and snippets.

@corentinbettiol
Created January 15, 2020 15:11
  • Star 0 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
Save corentinbettiol/cf29b7a20af7e7eb6757cc3d0ded617b to your computer and use it in GitHub Desktop.
Automatically build & publish package in pypi.
#!/bin/zsh
# 2019 - Corentin Bettiol
# Requires zsh, python3 & twine (python3 -m pip install --user --upgrade twine)
# Licenced under WTFPL v2
trap ctrl_c INT
function ctrl_c() {
echo "Aborting..."
clean_dir
echo "Done."
exit 0
}
function clean_dir() {
echo "Cleaning directories..."
rm -r dist/
rm -r build/
}
echo "+----------------------------------------------------------------------------------------+"
echo "| #//(((( |"
echo "| (////(((((((((( |"
echo "| // (((((((((( |"
echo "| //((((((((((((( |"
echo "| ////((((((((((((((# ,,,,& %###### ####### |"
echo "| /////(((((((((((((((## ,,,,,, ### ### ### ### |"
echo "| #///(((((((((((((((#### ,,,,,,, ### ### ### ## ## ##% ## |"
echo "| ///((((((((((((((##### ,,,,,,,, ### ### ### ## ## ### ## |"
echo "| /(((((((( /////////,,,,,,,,,,, ### ### ### ## ## ### ## |"
echo "| (((((((( ,,,,,,,,,,,,,,,,,,,,,* ### ### ### ## ## ### ## |"
echo "| (((((( ,,,,,,,,,,,,,,,,,,,**** ### ### ### ## ### ### ## |"
echo "| ((((( ,,,,,,,,,,,,,,,,****** ########### ########## ## ####### ## |"
echo "| ,,,,,,,,&&&&&&& ### ## ## |"
echo "| ,,,,,,,,,,,**** ### ## ## |"
echo "| ,,,,,,,,*** ** ### ##### ## |"
echo "| ,,,********, ## # |"
echo "+---------------------------------------------------------- automatic publishing tool ---+"
echo ""
echo ""
echo ""
echo ""
echo ""
if [ "$#" -ne 1 ] || [ "$1" = "--help" ]
then
if [ "$#" -ne 1 ]
then
echo "Wrong number of parameters!"
echo ""
fi
echo "Usage:"
echo " ./pypi.sh folder"
echo " (pypi.sh will cd into folder)"
echo " ./pypi.sh --help"
echo " (will display current help)"
exit 0
fi
cd $1
echo "Generating distribution archives..."
echo ""
echo ""
python3 setup.py sdist bdist_wheel
[ $? -ne 0 ] && echo "setup.py not found. Is $PWD a correct repo?" && exit 1
echo "Done!"
echo ""
echo ""
echo "Testing if all is good without publishing anything..."
python3 -m twine check dist/*
[ $? -ne 0 ] && echo "There was a problem during checks, cancelling..." && clean_dir && exit 1
echo "Done!"
echo ""
echo ""
echo "Do you want to publish your package now ?"
echo "Press Enter to continue, press CTRL+C to cancel upload."
read "?"
python3 -m twine upload dist/*
[ $? -ne 0 ] && echo "There was a problem during upload, cancelling..." && clean_dir && exit 1
echo "✨🎂✨"
echo ""
echo ""
clean_dir
echo "Done!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment