forked from rosette-api/python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_python.sh
More file actions
93 lines (86 loc) · 2.63 KB
/
run_python.sh
File metadata and controls
93 lines (86 loc) · 2.63 KB
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
#!/bin/bash
#Gets called when the user doesn't provide any args
function HELP {
echo -e "\nusage: source_file.py --key API_KEY [--url ALT_URL]"
echo " API_KEY - Rosette API key (required)"
echo " FILENAME - Python source file (optional)"
echo " ALT_URL - Alternate service URL (optional)"
echo " GIT_USERNAME - Git username where you would like to push regenerated gh-pages (optional)"
echo " VERSION - Build version (optional)"
echo "Compiles and runs the source file(s) using the local development source."
exit 1
}
#Gets API_KEY, FILENAME and ALT_URL if present
while getopts ":API_KEY:FILENAME:ALT_URL:GIT_USERNAME:VERSION" arg; do
case "${arg}" in
API_KEY)
API_KEY=${OPTARG}
usage
;;
ALT_URL)
ALT_URL=${OPTARG}
usage
;;
FILENAME)
FILENAME=${OPTARG}
usage
;;
GIT_USERNAME)
GIT_USERNAME=${OPTARG}
usage
;;
VERSION)
VERSION={OPTARG}
usage
;;
esac
done
#Checks if Rosette API key is valid
function checkAPI {
match=$(curl "https://api.rosette.com/rest/v1/ping" -H "user_key: ${API_KEY}" | grep -o "forbidden")
if [ ! -z $match ]; then
echo -e "\nInvalid Rosette API Key"
exit 1
fi
}
#Copy the mounted content in /source to current WORKDIR
cp -r -n /source/* .
#Run the examples
if [ ! -z ${API_KEY} ]; then
checkAPI
#Prerequisite
python /python-dev/setup.py install
cd /python-dev/examples
if [ ! -z ${FILENAME} ]; then
if [ ! -z ${ALT_URL} ]; then
python ${FILENAME} --key ${API_KEY} --url ${ALT_URL}
else
python ${FILENAME} --key ${API_KEY}
fi
elif [ ! -z ${ALT_URL} ]; then
find -maxdepth 1 -name '*.py' -print -exec python {} --key ${API_KEY} --url ${ALT_URL} \;
else
find -maxdepth 1 -name '*.py' -print -exec python {} --key ${API_KEY} \;
fi
else
HELP
fi
#Run unit tests
cd /python-dev
tox
#Generate gh-pages and push them to git account (if git username is provided)
if [ ! -z ${GIT_USERNAME} ] && [ ! -z ${VERSION} ]; then
#clone python git repo
cd /
git clone git@github.com:${GIT_USERNAME}/python.git
cd python
git checkout origin/gh-pages -b gh-pages
git branch -d develop
#generate gh-pages and set ouput dir to git repo (gh-pages branch)
cd /python-dev
.tox/py27/bin/epydoc -v --no-private --no-frames --css epydoc.css -o /python rosette/*.py
cd /python
git add .
git commit -a -m "publish python apidocs ${VERSION}"
git push
fi