forked from Qiskit/qiskit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pypi.sh
executable file
·194 lines (177 loc) · 4.86 KB
/
pypi.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
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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
#!/bin/bash
# This is a helper script to upload new versions of the SDK
# Author: Juan Gomez
# Please provide a valid username and password to connect to PyPi for uploading
# the Qiskit SDK distributable packaged
USERNAME=""
PASSWORD=""
usage(){
echo "Usage:"
echo "$0 [OPTION]"
echo "Helper script to create and upload Qiskit SDK distributable package"
echo "to PyPi severs."
echo ""
echo "Options:"
echo "-u <username> Specify a registered PyPi username"
echo "-p <password> The password of the username"
echo "-h Shows this help"
echo ""
exit 1
}
while getopts "u:p:h" optname
do
case "$optname" in
"h")
usage
;;
"u")
USERNAME=$OPTARG
;;
"p")
PASSWORD=$OPTARG
;;
":")
echo "No argument value for option $OPTARG"
usage
;;
*)
# Should not occur
echo "Unknown error while processing options"
usage
;;
esac
done
self=$0
date > $self.log
echo "**********************" >> $self.log
confirm() {
# call with a prompt string or use a default
read -r -p "${1:-Are you sure? [y/N]} " response
case "$response" in
[yY])
return 1
;;
*)
return 0
;;
esac
}
check_twine() {
twine upload -h &>> $self.log
if [[ $? != 0 ]]
then
return 0
else
return 1
fi
}
install_twine() {
pip install twine &>> $self.log
if [[ $? != 0 ]]
then
return 0
else
return 1
fi
}
diagnose() {
echo "Let's see if I can figure out what happened..."
echo -n "Is there a USERNAME?..."
if [[ $USERNAME == "" ]]
then
echo -e "[NO]"
echo "-----------------------"
echo "Seems like you haven't provide a USERNAME!"
echo "Please edit $self and add a registered username and password"
echo "or use the command options: -u <USERNAME> -p <PASSWORD>"
return
fi
echo -e "[YES]"
echo -n "Is there a PASSWORD?..."
if [[ $PASSWORD == "" ]]
then
echo -e "[NO]"
echo "-----------------------"
echo "Ok, so you provided a USERNAME but I can't seem to find the"
echo "the corresponding PASSWORD."
echo "Please edit $self and add the correct password"
echo "or use the command options: -u <USERNAME> -p <PASSWORD>"
return
fi
echo -e "[YES]"
echo -n "Is there connection to upload.pypi.org?..."
wget -q https://upload.pypi.org/ -O /dev/null &>> $self.log
if [[ $? != 0 ]]
then
echo -e "[NO]"
echo "-----------------------"
echo "Seems like there's no connection to PyPi, or PyPi is down."
echo "Please make sure there's a working internet connection."
echo "If you have internet connection, the PyPi site may be down."
echo "Please try again later."
return
fi
echo -e "[YES]"
echo "Seems like your credentials may be incorrect."
echo "Please make sure you have introduced the correct username and "
echo "password in the $self script."
}
echo -n "Clobbering build..."
# Clobbering build to rebuild it later
rm -rf qiskit.egg-info build dist
echo -e "[OK]"
export USER_FLAGS="-static"
echo "Setting USER_FLAGS env variable for C++ compilation to: $USER_FLAGS"
echo -n "Building distributable package..."
# Let's build the wheel package
python setup.py sdist bdist_wheel -p manylinux1_x86_64 &>> $self.log
if [ $? != 0 ]
then
echo -e "[ERROR]"
echo "--------------------------"
echo "Something wrong has happened!!. Please make sure that you are in the "
echo "project root directory and there's a setup.py file in there."
exit 2
fi
echo -e "[OK]"
echo -n "Checking for twine tool..."
check_twine
if [[ $? == 0 ]] # if it's ... false :)
then
echo -e "[ERROR]"
echo "Seems like you don't have Twine installed in yout system."
echo "Twine tool is necessary for uploading the package to PyPi."
echo ""
confirm "Do you want to install Twine? [Y/n]"
if [[ $? == 1 ]]
then
install_twine
if [[ $? == 0 ]]
then
echo "Couldn't install Twine, please try to install twine by yourself:"
echo "$ pip install twine"
exit 3
else
echo "Twine successfully installed!"
fi
else
echo "Install Twine by yourself and try again later!"
exit 4
fi
fi
echo -e "[OK]"
echo -n "Uploading distributable package to PyPi..."
twine upload -u $USERNAME -p $PASSWORD dist/* &>> $self.log
if [[ $? != 0 ]]
then
echo -e "[ERROR]"
echo "--------------------------"
echo "Error! Couldn't upload the distributed package to PyPi!!"
diagnose
exit 5
fi
echo -e "[OK]"
echo "Done!"
echo "Remember to create a TAG in the repo with the same version you just uploaded!"
rm -f $self.log
exit 0