Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: automatic pypi release script #18

Merged
merged 1 commit into from
Sep 9, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
feat: automatic pypi release script
  • Loading branch information
yxlao committed Sep 9, 2023
commit bf2d4c7c72e1c8a74bf5238769e8518a7130688f
116 changes: 116 additions & 0 deletions release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
#!/usr/bin/env bash

script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" &>/dev/null && pwd)"

# Check that the setup.py file exists.
if [ ! -f "$script_dir/setup.py" ]; then
echo "setup.py does not exist."
echo "Please run this script in the root directory of the project."
exit 1
fi

# Check that the camtools dir exists.
if [ ! -d "$script_dir/camtools" ]; then
echo "camtools dir does not exist."
echo "Please run this script in the root directory of the project."
exit 1
fi

# Check that conda is installed.
if ! [ -x "$(command -v conda)" ]; then
echo "conda is not installed."
echo "Please install conda first."
exit 1
fi

# Check that conda is not activated.
if [ ! -z "$CONDA_DEFAULT_ENV" ]; then
echo "$CONDA_DEFAULT_ENV is activated."
echo "Please deactivate conda environment first."
exit 1
fi

# Check that ~/.pypirc exists.
if [ ! -f "$HOME/.pypirc" ]; then
echo "$HOME/.pypirc does not exist."
echo "Please configure the .pypirc file first:"
echo "######"
echo "[distutils]"
echo "index-servers ="
echo " pypi"
echo " testpypi"
echo ""
echo "[pypi]"
echo "repository = https://upload.pypi.org/legacy/"
echo "username = __token__"
echo "password = pypi-xxxx"
echo ""
echo "[testpypi]"
echo "repository = https://test.pypi.org/legacy/"
echo "username = __token__"
echo "password = pypi-xxxx"
echo "######"
exit 1
fi

clear_up_dirs=(
.pytest_cache
build
camtools.egg-info
dist
)
for dir in "${clear_up_dirs[@]}"; do
if [ -d "$script_dir/$dir" ]; then
echo "Removing: $script_dir/$dir"
rm -rf "$script_dir/$dir"
fi
done

# Create conda env.
rm -rf /tmp/ct
conda create --prefix /tmp/ct python=3.9 -y

# Activate conda env.
eval "$(conda shell.bash hook)"
conda activate /tmp/ct

# Check that conda is activated.
if [ "$CONDA_DEFAULT_ENV" != "/tmp/ct" ]; then
echo "Conda environment ct is not activated. Erorr."
exit 1
else
echo "Conda environment ct is activated."
fi

# Check that python is from the conda env.
if [ "$(which python)" != "/tmp/ct/bin/python" ]; then
echo "python is not /tmp/ct/bin/python."
echo "Please activate conda environment ct first."
exit 1
else
echo "Python: $(which python)"
fi

# Install requirements.
python -m pip install build twine

# Build.
python -m build

# List files in dist.
echo "Going to upload the following files:"
for file in dist/*; do
echo "> $file: $(du -h $file | cut -f1)"
done

# Upload.
read -r -p "Run twine upload? [y/N] " response
case "$response" in
[yY][eE][sS] | [yY])
echo "twine upload -r pypi dist/*"
twine upload -r pypi dist/*
;;
*)
echo "Aborted."
;;
esac