mirror of
https://github.com/pyenv/pyenv.git
synced 2025-11-17 15:53:45 -05:00
Support missing versions being present and set in a local .python-version (#3134)
Some checks are pending
macos_build / macos_build (3.10) (push) Waiting to run
macos_build / macos_build (3.11) (push) Waiting to run
macos_build / macos_build (3.12) (push) Waiting to run
macos_build / macos_build (3.13) (push) Waiting to run
macos_build / macos_build (3.9) (push) Waiting to run
pyenv_tests / pyenv_tests (macos-13) (push) Waiting to run
pyenv_tests / pyenv_tests (macos-14) (push) Waiting to run
pyenv_tests / pyenv_tests (ubuntu-20.04) (push) Waiting to run
pyenv_tests / pyenv_tests (ubuntu-22.04) (push) Waiting to run
ubuntu_build / ubuntu_build (3.10) (push) Waiting to run
ubuntu_build / ubuntu_build (3.11) (push) Waiting to run
ubuntu_build / ubuntu_build (3.12) (push) Waiting to run
ubuntu_build / ubuntu_build (3.13) (push) Waiting to run
ubuntu_build / ubuntu_build (3.9) (push) Waiting to run
Some checks are pending
macos_build / macos_build (3.10) (push) Waiting to run
macos_build / macos_build (3.11) (push) Waiting to run
macos_build / macos_build (3.12) (push) Waiting to run
macos_build / macos_build (3.13) (push) Waiting to run
macos_build / macos_build (3.9) (push) Waiting to run
pyenv_tests / pyenv_tests (macos-13) (push) Waiting to run
pyenv_tests / pyenv_tests (macos-14) (push) Waiting to run
pyenv_tests / pyenv_tests (ubuntu-20.04) (push) Waiting to run
pyenv_tests / pyenv_tests (ubuntu-22.04) (push) Waiting to run
ubuntu_build / ubuntu_build (3.10) (push) Waiting to run
ubuntu_build / ubuntu_build (3.11) (push) Waiting to run
ubuntu_build / ubuntu_build (3.12) (push) Waiting to run
ubuntu_build / ubuntu_build (3.13) (push) Waiting to run
ubuntu_build / ubuntu_build (3.9) (push) Waiting to run
Requested in https://github.com/pyenv/pyenv/issues/2680 for deployments with a stock `.pyenv-version` that can use any of a number of Python versions and for compatibility with `uv`. * Support `pyenv local --force` * Support `pyenv-version-file-write --force` * Support `pyenv version-name --force` * Ignore missing versions when searching for executables * Display "commmand not found" even when there are nonexistent versions * exec.bats: replace `python` and `rspec` with something that doesn't exist globally, either in Ubuntu Github CI, `python` exists globally
This commit is contained in:
@@ -16,16 +16,22 @@ create_executable() {
|
||||
|
||||
@test "fails with invalid version" {
|
||||
export PYENV_VERSION="3.4"
|
||||
run pyenv-exec python -V
|
||||
assert_failure "pyenv: version \`3.4' is not installed (set by PYENV_VERSION environment variable)"
|
||||
run pyenv-exec nonexistent
|
||||
assert_failure <<EOF
|
||||
pyenv: version \`3.4' is not installed (set by PYENV_VERSION environment variable)
|
||||
pyenv: nonexistent: command not found
|
||||
EOF
|
||||
}
|
||||
|
||||
@test "fails with invalid version set from file" {
|
||||
mkdir -p "$PYENV_TEST_DIR"
|
||||
cd "$PYENV_TEST_DIR"
|
||||
echo 2.7 > .python-version
|
||||
run pyenv-exec rspec
|
||||
assert_failure "pyenv: version \`2.7' is not installed (set by $PWD/.python-version)"
|
||||
run pyenv-exec nonexistent
|
||||
assert_failure <<EOF
|
||||
pyenv: version \`2.7' is not installed (set by $PWD/.python-version)
|
||||
pyenv: nonexistent: command not found
|
||||
EOF
|
||||
}
|
||||
|
||||
@test "completes with names of executables" {
|
||||
|
||||
@@ -41,6 +41,18 @@ setup() {
|
||||
assert [ "$(cat .python-version)" = "1.2.3" ]
|
||||
}
|
||||
|
||||
@test "fails to set a nonexistent local version" {
|
||||
run pyenv-local 1.2.3
|
||||
assert_failure "pyenv: version \`1.2.3' not installed"
|
||||
assert [ ! -e .python-version ]
|
||||
}
|
||||
|
||||
@test "sets a nonexistent local version with --force" {
|
||||
run pyenv-local -f 1.2.3
|
||||
assert_success ""
|
||||
assert [ "$(cat .python-version)" = "1.2.3" ]
|
||||
}
|
||||
|
||||
@test "changes local version" {
|
||||
echo "1.0-pre" > .python-version
|
||||
mkdir -p "${PYENV_ROOT}/versions/1.2.3"
|
||||
|
||||
@@ -9,7 +9,7 @@ setup() {
|
||||
|
||||
@test "invocation without 2 arguments prints usage" {
|
||||
run pyenv-version-file-write
|
||||
assert_failure "Usage: pyenv version-file-write <file> <version>"
|
||||
assert_failure "Usage: pyenv version-file-write [-f|--force] <file> <version> [...]"
|
||||
run pyenv-version-file-write "one" ""
|
||||
assert_failure
|
||||
}
|
||||
@@ -21,6 +21,13 @@ setup() {
|
||||
assert [ ! -e ".python-version" ]
|
||||
}
|
||||
|
||||
@test "setting nonexistent version succeeds with force" {
|
||||
assert [ ! -e ".python-version" ]
|
||||
run pyenv-version-file-write --force ".python-version" "2.7.6"
|
||||
assert_success
|
||||
assert [ -e ".python-version" ]
|
||||
}
|
||||
|
||||
@test "writes value to arbitrary file" {
|
||||
mkdir -p "${PYENV_ROOT}/versions/2.7.6"
|
||||
assert [ ! -e "my-version" ]
|
||||
|
||||
@@ -73,6 +73,11 @@ SH
|
||||
assert_failure "pyenv: version \`1.2' is not installed (set by PYENV_VERSION environment variable)"
|
||||
}
|
||||
|
||||
@test "missing version with --force" {
|
||||
PYENV_VERSION=1.2 run pyenv-version-name -f
|
||||
assert_success "1.2"
|
||||
}
|
||||
|
||||
@test "one missing version (second missing)" {
|
||||
create_version "3.5.1"
|
||||
PYENV_VERSION="3.5.1:1.2" run pyenv-version-name
|
||||
|
||||
@@ -71,7 +71,16 @@ create_executable() {
|
||||
@test "version not installed" {
|
||||
create_executable "3.4" "py.test"
|
||||
PYENV_VERSION=3.3 run pyenv-which py.test
|
||||
assert_failure "pyenv: version \`3.3' is not installed (set by PYENV_VERSION environment variable)"
|
||||
assert_failure <<OUT
|
||||
pyenv: version \`3.3' is not installed (set by PYENV_VERSION environment variable)
|
||||
pyenv: py.test: command not found
|
||||
|
||||
The \`py.test' command exists in these Python versions:
|
||||
3.4
|
||||
|
||||
Note: See 'pyenv help global' for tips on allowing both
|
||||
python2 and python3 to be found.
|
||||
OUT
|
||||
}
|
||||
|
||||
@test "versions not installed" {
|
||||
@@ -80,6 +89,13 @@ create_executable() {
|
||||
assert_failure <<OUT
|
||||
pyenv: version \`2.7' is not installed (set by PYENV_VERSION environment variable)
|
||||
pyenv: version \`3.3' is not installed (set by PYENV_VERSION environment variable)
|
||||
pyenv: py.test: command not found
|
||||
|
||||
The \`py.test' command exists in these Python versions:
|
||||
3.4
|
||||
|
||||
Note: See 'pyenv help global' for tips on allowing both
|
||||
python2 and python3 to be found.
|
||||
OUT
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user