Skip to content

Commit e6532ef

Browse files
Merge pull request #364 from meahow/issue_311_prism
Install prism with non superuser account
2 parents a99eb14 + 42f19e6 commit e6532ef

File tree

4 files changed

+46
-24
lines changed

4 files changed

+46
-24
lines changed

.travis.yml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,8 @@ addons:
1919
apt_packages:
2020
- pandoc
2121
before_script:
22-
- mkdir prism
23-
- mkdir prism/bin
24-
- export PATH=$PATH:$PWD/prism/bin/
25-
- ./test/prism.sh
22+
- . ./test/prism.sh
23+
- prism version
2624
script:
2725
- if [[ $TRAVIS_PYTHON_VERSION == '2.6' ]]; then unit2 discover; else python -m unittest discover; fi
2826
before_deploy:

CONTRIBUTING.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,9 @@ The above local "Initial setup" is complete
137137

138138
* [pyenv](https://github.com/yyuu/pyenv)
139139
* [tox](https://pypi.python.org/pypi/tox)
140+
* [prism](https://github.com/stoplightio/prism) v0.6 - It should be available in your PATH, but unittest script
141+
will try to install it locally if not found. Apart from PATH env variable it will check in `~/bin` and `/usr/local/bin`.
142+
You can install by yourself it in user dir by calling `source test/prism.sh`.
140143

141144
#### Initial setup: ####
142145

test/prism.sh

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,24 @@ elif [ "$UNAME" = "Linux" ] ; then
2626
fi
2727

2828
#LATEST=$(curl -s https://api.github.com/repos/stoplightio/prism/tags | grep -Eo '"name":.*?[^\\]",' | head -n 1 | sed 's/[," ]//g' | cut -d ':' -f 2)
29-
LATEST="v0.1.5"
29+
LATEST="v0.6.21"
3030
URL="https://github.com/stoplightio/prism/releases/download/$LATEST/prism_$PLATFORM"
31-
DEST=./prism/bin/prism
31+
DESTDIR=~/bin
32+
DEST=$DESTDIR/prism
3233

3334
if [ -z $LATEST ] ; then
3435
echo "Error requesting. Download binary from ${URL}"
3536
exit 1
3637
else
38+
mkdir -p $DESTDIR
3739
curl -L $URL -o $DEST
3840
chmod +x $DEST
41+
export PATH=$PATH:$DESTDIR
42+
prism version
3943
fi
4044
}
4145

42-
install
46+
install
47+
48+
# this is needed for travis internal scripts
49+
set +u

test/test_sendgrid.py

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -24,37 +24,51 @@ def setUpClass(cls):
2424
cls.sg = sendgrid.SendGridAPIClient(
2525
host=host, path=cls.path,
2626
api_key=os.environ.get('SENDGRID_API_KEY'))
27-
if os.path.isfile('/usr/local/bin/prism') is False:
27+
cls.devnull = open(os.devnull, 'w')
28+
prism_cmd = None
29+
try:
30+
# check for prism in the PATH
31+
if subprocess.call('prism version'.split(), stdout=cls.devnull) == 0:
32+
prism_cmd = 'prism'
33+
except OSError:
34+
prism_cmd = None
35+
36+
if not prism_cmd:
37+
# check for known prism locations
38+
for path in ('/usr/local/bin/prism', os.path.expanduser(os.path.join('~', 'bin', 'prism')),
39+
os.path.abspath(os.path.join(os.getcwd(), 'prism', 'bin', 'prism'))):
40+
prism_cmd = path if os.path.isfile(path) else None
41+
if prism_cmd:
42+
break
43+
44+
if not prism_cmd:
2845
if sys.platform != 'win32':
46+
# try to install with prism.sh
2947
try:
30-
p1 = subprocess.Popen(
31-
[
32-
"curl",
33-
"https://raw.githubusercontent.com/stoplightio/"
34-
"prism/master/install.sh"],
35-
stdout=subprocess.PIPE)
36-
prisminstaller = subprocess.Popen(
37-
["sh"], stdin=p1.stdout, stdout=subprocess.PIPE)
38-
prisminstaller.wait()
48+
print("Warning: no prism detected, I will try to install it locally")
49+
prism_sh = os.path.abspath(os.path.join(cls.path, 'test', 'prism.sh'))
50+
if subprocess.call(prism_sh) == 0:
51+
prism_cmd = os.path.expanduser(os.path.join('~', 'bin', 'prism'))
52+
else:
53+
raise RuntimeError()
3954
except Exception as e:
4055
print(
41-
"Error downloading the prism binary, you can try "
56+
"Error installing the prism binary, you can try "
4257
"downloading directly here "
4358
"(https://github.com/stoplightio/prism/releases) "
44-
"and place in your /usr/local/bin directory",
45-
e.read())
59+
"and place in your $PATH", e)
4660
sys.exit()
4761
else:
4862
print("Please download the Windows binary "
4963
"(https://github.com/stoplightio/prism/releases) "
50-
"and place it in your /usr/local/bin directory")
64+
"and place it in your %PATH% ")
5165
sys.exit()
66+
5267
print("Activating Prism (~20 seconds)")
53-
devnull = open(os.devnull, 'w')
5468
cls.p = subprocess.Popen([
55-
"prism", "run", "-s",
69+
prism_cmd, "run", "-s",
5670
"https://raw.githubusercontent.com/sendgrid/sendgrid-oai/master/"
57-
"oai_stoplight.json"], stdout=devnull, stderr=subprocess.STDOUT)
71+
"oai_stoplight.json"], stdout=cls.devnull, stderr=subprocess.STDOUT)
5872
time.sleep(15)
5973
print("Prism Started")
6074

0 commit comments

Comments
 (0)