-
Notifications
You must be signed in to change notification settings - Fork 10
/
release.sh
executable file
·116 lines (101 loc) · 2.69 KB
/
release.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
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