mirror of
https://github.com/pyenv/pyenv.git
synced 2024-11-21 20:47:00 -05:00
Merge pull request #2610 from native-api/version_skip_envs
Ignore virtualenvs in `pyenv latest' in a clean way
This commit is contained in:
commit
c8c324afb4
3 changed files with 43 additions and 19 deletions
|
@ -31,7 +31,7 @@ exitcode=0
|
||||||
IFS=$'\n'
|
IFS=$'\n'
|
||||||
|
|
||||||
if [[ -z $FROM_KNOWN ]]; then
|
if [[ -z $FROM_KNOWN ]]; then
|
||||||
DEFINITION_CANDIDATES=( $(pyenv-versions --bare) )
|
DEFINITION_CANDIDATES=( $(pyenv-versions --bare --skip-envs) )
|
||||||
else
|
else
|
||||||
DEFINITION_CANDIDATES=( $(python-build --definitions ) )
|
DEFINITION_CANDIDATES=( $(python-build --definitions ) )
|
||||||
fi
|
fi
|
||||||
|
@ -48,10 +48,9 @@ IFS=$'\n'
|
||||||
$(printf '%s\n' "${DEFINITION_CANDIDATES[@]}" | \
|
$(printf '%s\n' "${DEFINITION_CANDIDATES[@]}" | \
|
||||||
grep -Ee "^$prefix_re[-.]" || true))
|
grep -Ee "^$prefix_re[-.]" || true))
|
||||||
|
|
||||||
#FIXME: <version>/envs/<virtualenv> should be excluded in Pyenv-Virtualenv via a hook
|
|
||||||
DEFINITION_CANDIDATES=(\
|
DEFINITION_CANDIDATES=(\
|
||||||
$(printf '%s\n' "${DEFINITION_CANDIDATES[@]}" | \
|
$(printf '%s\n' "${DEFINITION_CANDIDATES[@]}" | \
|
||||||
sed -E -e '/-dev$/d' -e '/-src$/d' -e '/-latest$/d' -e '/(a|b|rc)[0-9]+$/d' -e '/\/envs\//d'));
|
sed -E -e '/-dev$/d' -e '/-src$/d' -e '/-latest$/d' -e '/(a|b|rc)[0-9]+$/d'));
|
||||||
|
|
||||||
# Compose a sorting key, followed by | and original value
|
# Compose a sorting key, followed by | and original value
|
||||||
DEFINITION_CANDIDATES=(\
|
DEFINITION_CANDIDATES=(\
|
||||||
|
|
|
@ -1,23 +1,24 @@
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
# Summary: List all Python versions available to pyenv
|
# Summary: List all Python versions available to pyenv
|
||||||
# Usage: pyenv versions [--bare] [--skip-aliases]
|
# Usage: pyenv versions [--bare] [--skip-aliases] [--skip-envs]
|
||||||
#
|
#
|
||||||
# Lists all Python versions found in `$PYENV_ROOT/versions/*'.
|
# Lists all Python versions found in `$PYENV_ROOT/versions/*'.
|
||||||
|
|
||||||
set -e
|
set -e
|
||||||
[ -n "$PYENV_DEBUG" ] && set -x
|
[ -n "$PYENV_DEBUG" ] && set -x
|
||||||
|
|
||||||
unset bare
|
unset bare skip_aliases skip_envs
|
||||||
unset skip_aliases
|
|
||||||
# Provide pyenv completions
|
# Provide pyenv completions
|
||||||
for arg; do
|
for arg; do
|
||||||
case "$arg" in
|
case "$arg" in
|
||||||
--complete )
|
--complete )
|
||||||
echo --bare
|
echo --bare
|
||||||
echo --skip-aliases
|
echo --skip-aliases
|
||||||
|
echo --skip-envs
|
||||||
exit ;;
|
exit ;;
|
||||||
--bare ) bare=1 ;;
|
--bare ) bare=1 ;;
|
||||||
--skip-aliases ) skip_aliases=1 ;;
|
--skip-aliases ) skip_aliases=1 ;;
|
||||||
|
--skip-envs ) skip_envs=1 ;;
|
||||||
* )
|
* )
|
||||||
pyenv-help --usage versions >&2
|
pyenv-help --usage versions >&2
|
||||||
exit 1
|
exit 1
|
||||||
|
@ -70,8 +71,6 @@ else
|
||||||
current_versions=()
|
current_versions=()
|
||||||
fi
|
fi
|
||||||
if [ -n "$bare" ]; then
|
if [ -n "$bare" ]; then
|
||||||
hit_prefix=""
|
|
||||||
miss_prefix=""
|
|
||||||
include_system=""
|
include_system=""
|
||||||
else
|
else
|
||||||
hit_prefix="* "
|
hit_prefix="* "
|
||||||
|
@ -105,11 +104,15 @@ exists() {
|
||||||
|
|
||||||
print_version() {
|
print_version() {
|
||||||
local version="${1:?}"
|
local version="${1:?}"
|
||||||
|
if [[ -n $bare ]]; then
|
||||||
|
echo "$version"
|
||||||
|
return
|
||||||
|
fi
|
||||||
local path="${2:?}"
|
local path="${2:?}"
|
||||||
if [[ -z "$bare" && -L "$path" ]]; then
|
if [[ -L "$path" ]]; then
|
||||||
# Only resolve the link itself for printing, do not resolve further.
|
# Only resolve the link itself for printing, do not resolve further.
|
||||||
# Doing otherwise would misinform the user of what the link contains.
|
# Doing otherwise would misinform the user of what the link contains.
|
||||||
version_repr="$version --> $(resolve_link "$version")"
|
version_repr="$version --> $(resolve_link "$path")"
|
||||||
else
|
else
|
||||||
version_repr="$version"
|
version_repr="$version"
|
||||||
fi
|
fi
|
||||||
|
@ -152,13 +155,15 @@ for path in "${versions_dir_entries[@]}"; do
|
||||||
[ "${target%/*/envs/*}" == "$versions_dir" ] && continue
|
[ "${target%/*/envs/*}" == "$versions_dir" ] && continue
|
||||||
fi
|
fi
|
||||||
print_version "${path##*/}" "$path"
|
print_version "${path##*/}" "$path"
|
||||||
# virtual environments created by anaconda/miniconda
|
# virtual environments created by anaconda/miniconda/pyenv-virtualenv
|
||||||
|
if [[ -z $skip_envs ]]; then
|
||||||
for env_path in "${path}/envs/"*; do
|
for env_path in "${path}/envs/"*; do
|
||||||
if [ -d "${env_path}" ]; then
|
if [ -d "${env_path}" ]; then
|
||||||
print_version "${env_path#${PYENV_ROOT}/versions/}" "${env_path}"
|
print_version "${env_path#${PYENV_ROOT}/versions/}" "${env_path}"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
|
fi
|
||||||
done
|
done
|
||||||
shopt -u dotglob nullglob
|
shopt -u dotglob nullglob
|
||||||
|
|
||||||
|
|
|
@ -66,18 +66,38 @@ OUT
|
||||||
assert_success "3.3"
|
assert_success "3.3"
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "multiple versions" {
|
@test "multiple versions and envs" {
|
||||||
stub_system_python
|
stub_system_python
|
||||||
create_version "2.7.6"
|
create_version "2.7.6"
|
||||||
create_version "3.3.3"
|
|
||||||
create_version "3.4.0"
|
create_version "3.4.0"
|
||||||
|
create_version "3.4.0/envs/foo"
|
||||||
|
create_version "3.4.0/envs/bar"
|
||||||
|
create_version "3.5.2"
|
||||||
run pyenv-versions
|
run pyenv-versions
|
||||||
assert_success
|
assert_success
|
||||||
assert_output <<OUT
|
assert_output <<OUT
|
||||||
* system (set by ${PYENV_ROOT}/version)
|
* system (set by ${PYENV_ROOT}/version)
|
||||||
2.7.6
|
2.7.6
|
||||||
|
3.4.0
|
||||||
|
3.4.0/envs/bar
|
||||||
|
3.4.0/envs/foo
|
||||||
|
3.5.2
|
||||||
|
OUT
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "skips envs with --skip-envs" {
|
||||||
|
create_version "3.3.3"
|
||||||
|
create_version "3.4.0"
|
||||||
|
create_version "3.4.0/envs/foo"
|
||||||
|
create_version "3.4.0/envs/bar"
|
||||||
|
create_version "3.5.0"
|
||||||
|
|
||||||
|
run pyenv-versions --skip-envs
|
||||||
|
assert_success <<OUT
|
||||||
|
* system (set by ${PYENV_ROOT}/version)
|
||||||
3.3.3
|
3.3.3
|
||||||
3.4.0
|
3.4.0
|
||||||
|
3.5.0
|
||||||
OUT
|
OUT
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -216,7 +236,7 @@ SH
|
||||||
OUT
|
OUT
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "non-bare output resolves links" {
|
@test "non-bare output shows symlink contents" {
|
||||||
create_version "1.9.0"
|
create_version "1.9.0"
|
||||||
create_alias "link" "foo/bar"
|
create_alias "link" "foo/bar"
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue