Skip to content

Install prism with non superuser account #364

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 22, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,8 @@ addons:
apt_packages:
- pandoc
before_script:
- mkdir prism
- mkdir prism/bin
- export PATH=$PATH:$PWD/prism/bin/
- ./test/prism.sh
- . ./test/prism.sh
- prism version
script:
- if [[ $TRAVIS_PYTHON_VERSION == '2.6' ]]; then unit2 discover; else python -m unittest
discover; fi
Expand Down
3 changes: 3 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,9 @@ The above local "Initial setup" is complete

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

#### Initial setup: ####

Expand Down
13 changes: 10 additions & 3 deletions test/prism.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,24 @@ elif [ "$UNAME" = "Linux" ] ; then
fi

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

if [ -z $LATEST ] ; then
echo "Error requesting. Download binary from ${URL}"
exit 1
else
mkdir -p $DESTDIR
curl -L $URL -o $DEST
chmod +x $DEST
export PATH=$PATH:$DESTDIR
prism version
fi
}

install
install

# this is needed for travis internal scripts
set +u
48 changes: 31 additions & 17 deletions test/test_sendgrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,37 +24,51 @@ def setUpClass(cls):
cls.sg = sendgrid.SendGridAPIClient(
host=host, path=cls.path,
api_key=os.environ.get('SENDGRID_API_KEY'))
if os.path.isfile('/usr/local/bin/prism') is False:
cls.devnull = open(os.devnull, 'w')
prism_cmd = None
try:
# check for prism in the PATH
if subprocess.call('prism version'.split(), stdout=cls.devnull) == 0:
prism_cmd = 'prism'
except OSError:
prism_cmd = None

if not prism_cmd:
# check for known prism locations
for path in ('/usr/local/bin/prism', os.path.expanduser(os.path.join('~', 'bin', 'prism')),
os.path.abspath(os.path.join(os.getcwd(), 'prism', 'bin', 'prism'))):
prism_cmd = path if os.path.isfile(path) else None
if prism_cmd:
break

if not prism_cmd:
if sys.platform != 'win32':
# try to install with prism.sh
try:
p1 = subprocess.Popen(
[
"curl",
"https://github.com/raw/stoplightio/"
"prism/master/install.sh"],
stdout=subprocess.PIPE)
prisminstaller = subprocess.Popen(
["sh"], stdin=p1.stdout, stdout=subprocess.PIPE)
prisminstaller.wait()
print("Warning: no prism detected, I will try to install it locally")
prism_sh = os.path.abspath(os.path.join(cls.path, 'test', 'prism.sh'))
if subprocess.call(prism_sh) == 0:
prism_cmd = os.path.expanduser(os.path.join('~', 'bin', 'prism'))
else:
raise RuntimeError()
except Exception as e:
print(
"Error downloading the prism binary, you can try "
"Error installing the prism binary, you can try "
"downloading directly here "
"(https://github.com/stoplightio/prism/releases) "
"and place in your /usr/local/bin directory",
e.read())
"and place in your $PATH", e)
sys.exit()
else:
print("Please download the Windows binary "
"(https://github.com/stoplightio/prism/releases) "
"and place it in your /usr/local/bin directory")
"and place it in your %PATH% ")
sys.exit()

print("Activating Prism (~20 seconds)")
devnull = open(os.devnull, 'w')
cls.p = subprocess.Popen([
"prism", "run", "-s",
prism_cmd, "run", "-s",
"https://github.com/raw/sendgrid/sendgrid-oai/master/"
"oai_stoplight.json"], stdout=devnull, stderr=subprocess.STDOUT)
"oai_stoplight.json"], stdout=cls.devnull, stderr=subprocess.STDOUT)
time.sleep(15)
print("Prism Started")

Expand Down