Skip to content

Commit

Permalink
Merge remote-tracking branch 'rbenv/master' into rbenv-1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
yyuu committed Mar 2, 2016
2 parents 0c4392b + 29b4da7 commit 41ce3aa
Show file tree
Hide file tree
Showing 26 changed files with 240 additions and 217 deletions.
2 changes: 2 additions & 0 deletions .agignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
./versions
./cache
1 change: 1 addition & 0 deletions .vimrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
set wildignore+=versions/*,cache/*
80 changes: 80 additions & 0 deletions CONDUCT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# Contributor Covenant Code of Conduct

## Our Pledge

In the interest of fostering an open and welcoming environment, we as
contributors and maintainers pledge to making participation in our project and
our community a harassment-free experience for everyone, regardless of age, body
size, disability, ethnicity, gender identity and expression, level of experience,
nationality, personal appearance, race, religion, or sexual identity and
orientation.

## Our Standards

Examples of behavior that contributes to creating a positive environment
include:

* Using welcoming and inclusive language
* Being respectful of differing viewpoints and experiences
* Gracefully accepting constructive criticism
* Focusing on what is best for the community
* Showing empathy towards other community members

Examples of unacceptable behavior by participants include:

* The use of sexualized language or imagery and unwelcome sexual attention or
advances
* Trolling, insulting/derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or electronic
address, without explicit permission
* Other conduct which could reasonably be considered inappropriate in a
professional setting

## Our Responsibilities

Project maintainers are responsible for clarifying the standards of acceptable
behavior and are expected to take appropriate and fair corrective action in
response to any instances of unacceptable behavior.

Project maintainers have the right and responsibility to remove, edit, or
reject comments, commits, code, wiki edits, issues, and other contributions
that are not aligned to this Code of Conduct, or to ban temporarily or
permanently any contributor for other behaviors that they deem inappropriate,
threatening, offensive, or harmful.

## Scope

This Code of Conduct applies both within project spaces and in public spaces
when an individual is representing the project or its community. Examples of
representing a project or community include using an official project e-mail
address, posting via an official social media account, or acting as an appointed
representative at an online or offline event. Representation of a project may be
further defined and clarified by project maintainers.

## Enforcement

Instances of abusive, harassing, or otherwise unacceptable behavior may be
reported by contacting one of the project maintainers listed below. All
complaints will be reviewed and investigated and will result in a response that
is deemed necessary and appropriate to the circumstances. The project team is
obligated to maintain confidentiality with regard to the reporter of an incident.
Further details of specific enforcement policies may be posted separately.

Project maintainers who do not follow or enforce the Code of Conduct in good
faith may face temporary or permanent repercussions as determined by other
members of the project's leadership.

## Project Maintainers

* Sam Stephenson <<sstephenson@gmail.com>>
* Mislav Marohnić <<mislav.marohnic@gmail.com>>
* Erik Michaels-Ober <<sferik@gmail.com>>

## Attribution

This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
available at [http://contributor-covenant.org/version/1/4][version]

[homepage]: http://contributor-covenant.org
[version]: http://contributor-covenant.org/version/1/4/
23 changes: 0 additions & 23 deletions bin/python-local-exec

This file was deleted.

1 change: 1 addition & 0 deletions libexec/pyenv
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ PYENV_HOOK_PATH="${PYENV_HOOK_PATH}:/usr/local/etc/pyenv.d:/etc/pyenv.d:/usr/lib
for plugin_hook in "${PYENV_ROOT}/plugins/"*/etc/pyenv.d; do
PYENV_HOOK_PATH="${PYENV_HOOK_PATH}:${plugin_hook}"
done
PYENV_HOOK_PATH="${PYENV_HOOK_PATH#:}"
export PYENV_HOOK_PATH

shopt -u nullglob
Expand Down
11 changes: 4 additions & 7 deletions libexec/pyenv---version
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,9 @@ set -e
version="20160202"
git_revision=""

for source_dir in "${BASH_SOURCE%/*}" "$PYENV_ROOT"; do
if cd "$source_dir" 2>/dev/null && git remote -v 2>/dev/null | grep -q pyenv; then
git_revision="$(git describe --tags HEAD 2>/dev/null || true)"
git_revision="${git_revision#v}"
[ -z "$git_revision" ] || break
fi
done
if cd "${BASH_SOURCE%/*}" 2>/dev/null && git remote -v 2>/dev/null | grep -q pyenv; then
git_revision="$(git describe --tags HEAD 2>/dev/null || true)"
git_revision="${git_revision#v}"
fi

echo "pyenv ${git_revision:-$version}"
2 changes: 2 additions & 0 deletions libexec/pyenv-hooks
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ set -e
if [ "$1" = "--complete" ]; then
echo exec
echo rehash
echo version-name
echo version-origin
echo which
exit
fi
Expand Down
4 changes: 2 additions & 2 deletions libexec/pyenv-init
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ done

shell="$1"
if [ -z "$shell" ]; then
shell="$(ps c -p "$PPID" -o 'ucomm=' 2>/dev/null || true)"
shell="${shell##-}"
shell="$(ps -p "$PPID" -o 'args=' 2>/dev/null || true)"
shell="${shell%% *}"
shell="${shell##-}"
shell="${shell:-$SHELL}"
shell="${shell##*/}"
fi
Expand Down
4 changes: 0 additions & 4 deletions libexec/pyenv-local
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@
# `PYENV_VERSION' environment variable takes precedence over local
# and global versions.
#
# For backwards compatibility, pyenv will also read version
# specifications from `.pyenv-version' files, but a `.python-version'
# file in the same directory takes precedence.
#
# <version> should be a string matching a Python version known to pyenv.
# The special version string `system' will use your default system Python.
# Run `pyenv versions' for a list of available Python versions.
Expand Down
29 changes: 11 additions & 18 deletions libexec/pyenv-version-file
Original file line number Diff line number Diff line change
@@ -1,35 +1,28 @@
#!/usr/bin/env bash
# Usage: pyenv version-file [<dir>]
# Summary: Detect the file that sets the current pyenv version
set -e
[ -n "$PYENV_DEBUG" ] && set -x

target_dir="$1"

find_local_version_file() {
local root="$1"
while true; do
[[ "$root" =~ ^//[^/]*$ ]] && break
while ! [[ "$root" =~ ^//[^/]*$ ]]; do
if [ -e "${root}/.python-version" ]; then
echo "${root}/.python-version"
exit
elif [ -e "${root}/.pyenv-version" ]; then
echo "${root}/.pyenv-version"
exit
return 0
fi
[ -n "$root" ] || break
root="${root%/*}"
done
return 1
}

find_local_version_file "$PYENV_DIR"
[ "$PYENV_DIR" = "$PWD" ] || find_local_version_file "$PWD"

global_version_file="${PYENV_ROOT}/version"

if [ -e "$global_version_file" ]; then
echo "$global_version_file"
elif [ -e "${PYENV_ROOT}/global" ]; then
echo "${PYENV_ROOT}/global"
elif [ -e "${PYENV_ROOT}/default" ]; then
echo "${PYENV_ROOT}/default"
if [ -n "$target_dir" ]; then
find_local_version_file "$target_dir"
else
echo "$global_version_file"
find_local_version_file "$PYENV_DIR" || {
[ "$PYENV_DIR" != "$PWD" ] && find_local_version_file "$PWD"
} || echo "${PYENV_ROOT}/version"
fi
7 changes: 7 additions & 0 deletions libexec/pyenv-version-name
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@ if [ -z "$PYENV_VERSION" ]; then
PYENV_VERSION="$(pyenv-version-file-read "$PYENV_VERSION_FILE" || true)"
fi

OLDIFS="$IFS"
IFS=$'\n' scripts=(`pyenv-hooks version-name`)
IFS="$OLDIFS"
for script in "${scripts[@]}"; do
source "$script"
done

if [ -z "$PYENV_VERSION" ] || [ "$PYENV_VERSION" = "system" ]; then
echo "system"
exit
Expand Down
13 changes: 12 additions & 1 deletion libexec/pyenv-version-origin
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,18 @@
set -e
[ -n "$PYENV_DEBUG" ] && set -x

if [ -n "$PYENV_VERSION" ]; then
unset PYENV_VERSION_ORIGIN

OLDIFS="$IFS"
IFS=$'\n' scripts=(`pyenv-hooks version-origin`)
IFS="$OLDIFS"
for script in "${scripts[@]}"; do
source "$script"
done

if [ -n "$PYENV_VERSION_ORIGIN" ]; then
echo "$PYENV_VERSION_ORIGIN"
elif [ -n "$PYENV_VERSION" ]; then
echo "PYENV_VERSION environment variable"
else
pyenv-version-file
Expand Down
2 changes: 1 addition & 1 deletion libexec/pyenv-versions
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ done

versions_dir="${PYENV_ROOT}/versions"

if ! enable -f "${BASH_SOURCE%/*}"/../libexec/pyenv-realpath.dylib realpath 2>/dev/null; then
if ! enable -f "${BASH_SOURCE%/*}"/pyenv-realpath.dylib realpath 2>/dev/null; then
if [ -n "$PYENV_NATIVE_EXT" ]; then
echo "pyenv: failed to load \`realpath' builtin" >&2
exit 1
Expand Down
35 changes: 8 additions & 27 deletions test/--version.bats
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,13 @@

load test_helper

export GIT_DIR="${PYENV_TEST_DIR}/.git"

setup() {
mkdir -p "$HOME"
git config --global user.name "Tester"
git config --global user.email "tester@test.local"

mkdir -p "${PYENV_TEST_DIR}/bin"
cat > "${PYENV_TEST_DIR}/bin/git" <<CMD
#!$BASH
if [[ \$1 == remote && \$PWD != "\$PYENV_TEST_DIR"/* ]]; then
echo "not allowed" >&2
exit 1
else
exec $(which git) "\$@"
fi
CMD
chmod +x "${PYENV_TEST_DIR}/bin/git"
cd "$PYENV_TEST_DIR"
}

git_commit() {
Expand All @@ -28,47 +19,37 @@ git_commit() {
assert [ ! -e "$PYENV_ROOT" ]
run pyenv---version
assert_success
[[ $output == "pyenv 20"* ]]
[[ $output == "ybenv "?.?.? ]]
}

@test "doesn't read version from non-pyenv repo" {
mkdir -p "$PYENV_ROOT"
cd "$PYENV_ROOT"
git init
git remote add origin https://github.com/homebrew/homebrew.git
git_commit
git tag v1.0

cd "$PYENV_TEST_DIR"
run pyenv---version
assert_success
[[ $output == "pyenv 20"* ]]
[[ $output == "pyenv "?.?.? ]]
}

@test "reads version from git repo" {
mkdir -p "$PYENV_ROOT"
cd "$PYENV_ROOT"
git init
git remote add origin https://github.com/yyuu/pyenv.git
git_commit
git tag v20380119
git tag v0.4.1
git_commit
git_commit

cd "$PYENV_TEST_DIR"
run pyenv---version
assert_success
[[ $output == "pyenv 20380119-2-g"* ]]
assert_success "pyenv 0.4.1-2-g$(git rev-parse --short HEAD)"
}

@test "prints default version if no tags in git repo" {
mkdir -p "$PYENV_ROOT"
cd "$PYENV_ROOT"
git init
git remote add origin https://github.com/yyuu/pyenv.git
git_commit

cd "$PYENV_TEST_DIR"
run pyenv---version
[[ $output == "pyenv 20"* ]]
[[ $output == "pyenv "?.?.? ]]
}
17 changes: 2 additions & 15 deletions test/exec.bats
Original file line number Diff line number Diff line change
Expand Up @@ -43,27 +43,14 @@ python
OUT
}

@test "supports hook path with spaces" {
hook_path="${PYENV_TEST_DIR}/custom stuff/pyenv hooks"
mkdir -p "${hook_path}/exec"
echo "export HELLO='from hook'" > "${hook_path}/exec/hello.bash"

export PYENV_VERSION=system
PYENV_HOOK_PATH="$hook_path" run pyenv-exec env
assert_success
assert_line "HELLO=from hook"
}

@test "carries original IFS within hooks" {
hook_path="${PYENV_TEST_DIR}/pyenv.d"
mkdir -p "${hook_path}/exec"
cat > "${hook_path}/exec/hello.bash" <<SH
create_hook exec hello.bash <<SH
hellos=(\$(printf "hello\\tugly world\\nagain"))
echo HELLO="\$(printf ":%s" "\${hellos[@]}")"
SH

export PYENV_VERSION=system
PYENV_HOOK_PATH="$hook_path" IFS=$' \t\n' run pyenv-exec env
IFS=$' \t\n' run pyenv-exec env
assert_success
assert_line "HELLO=:hello:ugly:world:again"
}
Expand Down
4 changes: 2 additions & 2 deletions test/global.bats
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
load test_helper

@test "default" {
run pyenv global
run pyenv-global
assert_success
assert_output "system"
}
Expand All @@ -20,7 +20,7 @@ load test_helper
mkdir -p "$PYENV_ROOT/versions/1.2.3"
run pyenv-global "1.2.3"
assert_success
run pyenv global
run pyenv-global
assert_success "1.2.3"
}

Expand Down
Loading

0 comments on commit 41ce3aa

Please sign in to comment.