This repository has been archived by the owner on Feb 20, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
428 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
install: git clone https://github.com/sstephenson/bats.git | ||
script: bats/bin/bats --tap test | ||
language: c | ||
notifications: | ||
email: | ||
on_success: never |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#!/bin/sh | ||
# Usage: PREFIX=/usr/local ./install.sh | ||
# | ||
# Installs pyenv-virtualenv under $PREFIX. | ||
|
||
set -e | ||
|
||
cd "$(dirname "$0")" | ||
|
||
if [ -z "${PREFIX}" ]; then | ||
PREFIX="/usr/local" | ||
fi | ||
|
||
ETC_PATH="${PREFIX}/etc/pyenv.d" | ||
LIBEXEC_PATH="${PREFIX}/libexec" | ||
|
||
mkdir -p "$ETC_PATH" | ||
mkdir -p "$LIBEXEC_PATH" | ||
|
||
cp -RPp etc/pyenv.d/* "$ETC_PATH" | ||
install -p libexec/* "$LIBEXEC_PATH" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#!/usr/bin/env bats | ||
|
||
load test_helper | ||
|
||
@test "installs pyenv-pip-rehash into PREFIX" { | ||
cd "$TMP" | ||
PREFIX="${PWD}/usr" run "${BATS_TEST_DIRNAME}/../install.sh" | ||
assert_success "" | ||
|
||
cd usr | ||
|
||
assert [ -x libexec/pip ] | ||
assert [ -f etc/pyenv.d/exec/pip.bash ] | ||
} | ||
|
||
@test "overwrites old installation" { | ||
cd "$TMP" | ||
mkdir -p libexec | ||
touch libexec/pip | ||
|
||
PREFIX="$PWD" run "${BATS_TEST_DIRNAME}/../install.sh" | ||
assert_success "" | ||
|
||
assert [ -x libexec/pip ] | ||
run grep "pyenv-rehash" libexec/pip | ||
assert_success | ||
} | ||
|
||
@test "unrelated files are untouched" { | ||
cd "$TMP" | ||
mkdir -p libexec share/bananas | ||
chmod g-w libexec | ||
touch libexec/bananas | ||
|
||
PREFIX="$PWD" run "${BATS_TEST_DIRNAME}/../install.sh" | ||
assert_success "" | ||
|
||
assert [ -e libexec/bananas ] | ||
|
||
run ls -ld libexec | ||
assert_equal "r-x" "${output:4:3}" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -e | ||
|
||
PYENV_COMMAND="$1" | ||
PYENV_COMMAND_PATH="$(pyenv-which "$PYENV_COMMAND")" | ||
PYENV_BIN_PATH="${PYENV_COMMAND_PATH%/*}" | ||
|
||
shopt -s nullglob | ||
for script in "$(dirname "${BASH_SOURCE[0]}")/../../etc/pyenv.d/exec/"*.bash; do | ||
source "${script}" | ||
done | ||
shopt -u nullglob | ||
|
||
shift 1 | ||
echo PYENV_BIN_PATH="${PYENV_BIN_PATH}" exec -a "${PYENV_COMMAND}" "$PYENV_COMMAND_PATH" "$@" | ||
exec -a "${PYENV_COMMAND}" "$PYENV_COMMAND_PATH" "$@" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
#!/usr/bin/env bats | ||
|
||
load test_helper | ||
|
||
setup() { | ||
export PYENV_PIP_REHASH_ROOT="$(abs_dirname "${BATS_TEST_DIRNAME}/../..")" | ||
} | ||
|
||
resolve_link() { | ||
$(type -p greadlink readlink | head -1) "$1" | ||
} | ||
|
||
abs_dirname() { | ||
local cwd="$(pwd)" | ||
local path="$1" | ||
|
||
while [ -n "$path" ]; do | ||
cd "${path%/*}" | ||
local name="${path##*/}" | ||
path="$(resolve_link "$name" || true)" | ||
done | ||
|
||
pwd | ||
cd "$cwd" | ||
} | ||
|
||
@test "should not invoke rehash after pip freeze" { | ||
stub pyenv-which "pip : echo \"${TMP}/bin/pip\"" \ | ||
"pip : echo \"${TMP}/bin/pip\"" | ||
stub pyenv-rehash "echo rehashed" | ||
stub pip "echo \"pip \$@\"" | ||
|
||
run pyenv-exec pip freeze | ||
|
||
assert_success | ||
assert_output <<EOS | ||
PYENV_BIN_PATH=${PYENV_PIP_REHASH_ROOT}/libexec exec -a pip ${PYENV_PIP_REHASH_ROOT}/libexec/pip freeze | ||
pip freeze | ||
EOS | ||
} | ||
|
||
@test "should invoke rehash after successful pip install" { | ||
stub pyenv-which "pip : echo \"${TMP}/bin/pip\"" \ | ||
"pip : echo \"${TMP}/bin/pip\"" | ||
stub pyenv-rehash "echo rehashed" | ||
stub pip "echo \"pip \$@\"" | ||
|
||
run pyenv-exec pip install -U tornado | ||
|
||
assert_success | ||
assert_output <<EOS | ||
PYENV_BIN_PATH=${PYENV_PIP_REHASH_ROOT}/libexec exec -a pip ${PYENV_PIP_REHASH_ROOT}/libexec/pip install -U tornado | ||
pip install -U tornado | ||
rehashed | ||
EOS | ||
} | ||
|
||
@test "should invoke rehash after unsuccessful pip install" { | ||
stub pyenv-which "pip : echo \"${TMP}/bin/pip\"" \ | ||
"pip : echo \"${TMP}/bin/pip\"" | ||
stub pyenv-rehash "echo rehashed" | ||
stub pip "echo \"pip \$@\"; false" | ||
|
||
run pyenv-exec pip install tornado | ||
|
||
assert_failure | ||
assert_output <<EOS | ||
PYENV_BIN_PATH=${PYENV_PIP_REHASH_ROOT}/libexec exec -a pip ${PYENV_PIP_REHASH_ROOT}/libexec/pip install tornado | ||
pip install tornado | ||
EOS | ||
} | ||
|
||
@test "should invoke rehash after successful pip uninstall" { | ||
stub pyenv-which "pip : echo \"${TMP}/bin/pip\"" \ | ||
"pip : echo \"${TMP}/bin/pip\"" | ||
stub pyenv-rehash "echo rehashed" | ||
stub pip "echo \"pip \$@\"" | ||
|
||
run pyenv-exec pip uninstall --yes tornado | ||
|
||
assert_success | ||
assert_output <<EOS | ||
PYENV_BIN_PATH=${PYENV_PIP_REHASH_ROOT}/libexec exec -a pip ${PYENV_PIP_REHASH_ROOT}/libexec/pip uninstall --yes tornado | ||
pip uninstall --yes tornado | ||
rehashed | ||
EOS | ||
} | ||
|
||
@test "should not invoke rehash after unsuccessful pip uninstall" { | ||
stub pyenv-which "pip : echo \"${TMP}/bin/pip\"" \ | ||
"pip : echo \"${TMP}/bin/pip\"" | ||
stub pyenv-rehash "echo rehashed" | ||
stub pip "echo \"pip \$@\"; false" | ||
|
||
run pyenv-exec pip uninstall tornado | ||
|
||
assert_failure | ||
assert_output <<EOS | ||
PYENV_BIN_PATH=${PYENV_PIP_REHASH_ROOT}/libexec exec -a pip ${PYENV_PIP_REHASH_ROOT}/libexec/pip uninstall tornado | ||
pip uninstall tornado | ||
EOS | ||
} | ||
|
||
@test "should invoke rehash after successful easy_install" { | ||
stub pyenv-which "easy_install : echo \"${TMP}/bin/easy_install\"" \ | ||
"easy_install : echo \"${TMP}/bin/easy_install\"" | ||
stub pyenv-rehash "echo rehashed" | ||
stub easy_install "echo \"easy_install \$@\"" | ||
|
||
run pyenv-exec easy_install tornado | ||
|
||
assert_success | ||
assert_output <<EOS | ||
PYENV_BIN_PATH=${PYENV_PIP_REHASH_ROOT}/libexec exec -a easy_install ${PYENV_PIP_REHASH_ROOT}/libexec/easy_install tornado | ||
easy_install tornado | ||
rehashed | ||
EOS | ||
} | ||
|
||
@test "should not invoke rehash after unsuccessful easy_install" { | ||
stub pyenv-which "easy_install : echo \"${TMP}/bin/easy_install\"" \ | ||
"easy_install : echo \"${TMP}/bin/easy_install\"" | ||
stub pyenv-rehash "echo rehashed" | ||
stub easy_install "echo \"easy_install \$@\"; false" | ||
|
||
run pyenv-exec easy_install -U tornado | ||
|
||
assert_failure | ||
assert_output <<EOS | ||
PYENV_BIN_PATH=${PYENV_PIP_REHASH_ROOT}/libexec exec -a easy_install ${PYENV_PIP_REHASH_ROOT}/libexec/easy_install -U tornado | ||
easy_install -U tornado | ||
EOS | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
#!/usr/bin/env bash | ||
set -e | ||
|
||
status=0 | ||
program="${0##*/}" | ||
PROGRAM="$(echo "$program" | tr a-z- A-Z_)" | ||
[ -n "$TMPDIR" ] || TMPDIR="/tmp" | ||
|
||
_STUB_PLAN="${PROGRAM}_STUB_PLAN" | ||
_STUB_RUN="${PROGRAM}_STUB_RUN" | ||
_STUB_INDEX="${PROGRAM}_STUB_INDEX" | ||
_STUB_RESULT="${PROGRAM}_STUB_RESULT" | ||
_STUB_END="${PROGRAM}_STUB_END" | ||
_STUB_DEBUG="${PROGRAM}_STUB_DEBUG" | ||
|
||
if [ -n "${!_STUB_DEBUG}" ]; then | ||
echo "$program" "$@" >&${!_STUB_DEBUG} | ||
fi | ||
|
||
[ -e "${!_STUB_PLAN}" ] || exit 1 | ||
[ -n "${!_STUB_RUN}" ] || eval "${_STUB_RUN}"="${TMPDIR}/${program}-stub-run" | ||
|
||
|
||
# Initialize or load the stub run information. | ||
eval "${_STUB_INDEX}"=1 | ||
eval "${_STUB_RESULT}"=0 | ||
[ ! -e "${!_STUB_RUN}" ] || source "${!_STUB_RUN}" | ||
|
||
|
||
# Loop over each line in the plan. | ||
index=0 | ||
while IFS= read -r line; do | ||
index=$(($index + 1)) | ||
|
||
if [ -z "${!_STUB_END}" ] && [ $index -eq "${!_STUB_INDEX}" ]; then | ||
# We found the plan line we're interested in. | ||
# Start off by assuming success. | ||
result=0 | ||
|
||
# Split the line into an array of arguments to | ||
# match and a command to run to produce output. | ||
command=" $line" | ||
if [ "$command" != "${command/ : }" ]; then | ||
patterns="${command%% : *}" | ||
command="${command#* : }" | ||
fi | ||
|
||
# Naively split patterns by whitespace for now. | ||
# In the future, use a sed script to split while | ||
# respecting quoting. | ||
set -f | ||
patterns=($patterns) | ||
set +f | ||
arguments=("$@") | ||
|
||
# Match the expected argument patterns to actual | ||
# arguments. | ||
for (( i=0; i<${#patterns[@]}; i++ )); do | ||
pattern="${patterns[$i]}" | ||
argument="${arguments[$i]}" | ||
|
||
case "$argument" in | ||
$pattern ) ;; | ||
* ) result=1 ;; | ||
esac | ||
done | ||
|
||
# If the arguments matched, evaluate the command | ||
# in a subshell. Otherwise, log the failure. | ||
if [ $result -eq 0 ] ; then | ||
set +e | ||
( eval "$command" ) | ||
status="$?" | ||
set -e | ||
else | ||
eval "${_STUB_RESULT}"=1 | ||
fi | ||
fi | ||
done < "${!_STUB_PLAN}" | ||
|
||
|
||
if [ -n "${!_STUB_END}" ]; then | ||
# Clean up the run file. | ||
rm -f "${!_STUB_RUN}" | ||
|
||
# If the number of lines in the plan is larger than | ||
# the requested index, we failed. | ||
if [ $index -ge "${!_STUB_INDEX}" ]; then | ||
eval "${_STUB_RESULT}"=1 | ||
fi | ||
|
||
# Return the result. | ||
exit "${!_STUB_RESULT}" | ||
|
||
else | ||
# If the requested index is larger than the number | ||
# of lines in the plan file, we failed. | ||
if [ "${!_STUB_INDEX}" -gt $index ]; then | ||
eval "${_STUB_RESULT}"=1 | ||
fi | ||
|
||
# Write out the run information. | ||
{ echo "${_STUB_INDEX}=$((${!_STUB_INDEX} + 1))" | ||
echo "${_STUB_RESULT}=${!_STUB_RESULT}" | ||
} > "${!_STUB_RUN}" | ||
|
||
exit "$status" | ||
|
||
fi |
Oops, something went wrong.