-
Notifications
You must be signed in to change notification settings - Fork 14
/
release.bash
executable file
·156 lines (124 loc) · 3.4 KB
/
release.bash
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#!/bin/bash
SCRIPT=`readlink -f "$0"`
SCRIPTPATH=`dirname "$SCRIPT"` # directory that contains this script
VENV_PY_2_DIR=$SCRIPTPATH/venv_py2;
VENV_PY_3_DIR=$SCRIPTPATH/venv_py3;
USE_PY_VERSION="python3"
usage="
Usage:
release.bash [options]
Available options:
-n|--dry-run - do not do release, just build doc, and build packages
--test-index - upload to test pypi site
--py2 - use python 2
--py3 - use python 3 (default)
--reuse-venv - do not remove virtual environment, and reusse it on next call
--no-docs - do not generate and upload docs
"
# Disable doc generation
NO_DOCS=1;
# process cmdline options
while [[ $# -gt 0 ]]
do
key="$1";
case $key in
-h|--help|help)
echo "$usage";
exit 0;
;;
-n|--dry-run)
DRY_RUN=1;
;;
--test-index)
TEST_PYPI_INDEX=1;
;;
--py2)
USE_PY_VERSION='python2';
;;
--py3)
USE_PY_VERSION='python3';
;;
--no-docs)
NO_DOCS=1;
;;
--reuse-venv)
REUSE_VENV=1;
;;
*)
echo "Unknown option $key";
exit 1;
;;
esac
shift
done
set -e # fail on any error
# make_venv <python-version> <dest dir>
function make_venv {
local py_version=$1;
local dest_dir=$2;
if [ -d $dest_dir ] && [ -z $REUSE_VENV ]; then
echo "Removing dest dir '$dest_dir'...";
rm -rf $dest_dir;
virtualenv -p $py_version $dest_dir;
elif [ ! -d $dest_dir ]; then
virtualenv -p $py_version $dest_dir;
fi
$dest_dir/bin/pip install --upgrade setuptools pip twine;
}
function build_docs {
pip install --upgrade sphinx[all];
(cp -f $SCRIPTPATH/README.rst $SCRIPTPATH/docs/source/intro.rst)
python $SCRIPTPATH/setup.py build_sphinx;
}
function release_implementation {
# install this project in virtual environment
python $SCRIPTPATH/setup.py develop
# Build options. if no dry run, then upload to pypi
local setup_options=" sdist bdist_wheel ";
# Build [and upload to pypi] project
python $SCRIPTPATH/setup.py $setup_options;
# If using test index, add it to upload options
if [ -z "$TEST_PYPI_INDEX" ]; then
python -m twine upload dist/*;
else
python -m twine upload --repository-url https://test.pypi.org/legacy/ dist/*;
fi
if [ -z $NO_DOCS ]; then
build_docs;
fi
}
function release_python_2 {
local py_version=python2;
local venv_dir=$VENV_PY_2_DIR;
make_venv $py_version $venv_dir;
source $venv_dir/bin/activate;
release_implementation;
deactivate;
if [ -z $REUSE_VENV ]; then
rm -r $venv_dir;
fi
}
function release_python_3 {
local py_version=python3;
local venv_dir=$VENV_PY_3_DIR;
make_venv $py_version $venv_dir;
source $venv_dir/bin/activate;
release_implementation;
deactivate;
if [ -z $REUSE_VENV ]; then
rm -r $venv_dir;
fi
}
function do_release {
if [ ! -z $DRY_RUN ]; then
echo "Running in 'dry-run' mode.";
fi
if [ "$USE_PY_VERSION" == "python3" ]; then
release_python_3;
elif [ "$USE_PY_VERSION" == "python2" ]; then
release_python_2;
else
echo "Error";
fi
}
do_release;