Compare commits

...

9 Commits

Author SHA1 Message Date
Florian Blanchet
b7470e35aa
Merge 0541b2ce08 into c6ea700cdf 2025-11-04 08:27:34 -03:00
Ivan Pozdeev
c6ea700cdf 2.6.12
Some checks failed
macos_build / macos_build (3.10) (push) Has been cancelled
macos_build / macos_build (3.11) (push) Has been cancelled
macos_build / macos_build (3.12) (push) Has been cancelled
macos_build / macos_build (3.13) (push) Has been cancelled
macos_build / macos_build (3.9) (push) Has been cancelled
pyenv_tests / pyenv_tests (macos-13) (push) Has been cancelled
pyenv_tests / pyenv_tests (macos-14) (push) Has been cancelled
pyenv_tests / pyenv_tests (ubuntu-22.04) (push) Has been cancelled
pyenv_tests / pyenv_tests (ubuntu-24.04) (push) Has been cancelled
ubuntu_build / ubuntu_build (3.10) (push) Has been cancelled
ubuntu_build / ubuntu_build (3.11) (push) Has been cancelled
ubuntu_build / ubuntu_build (3.12) (push) Has been cancelled
ubuntu_build / ubuntu_build (3.13) (push) Has been cancelled
ubuntu_build / ubuntu_build (3.9) (push) Has been cancelled
2025-10-31 23:27:18 +03:00
Ned Batchelder
97fd8f436d
Add CPython 3.9.25 (#3355) 2025-10-31 23:24:35 +03:00
Ivan Pozdeev
0541b2ce08 Merge branch 'master' into pr/origin/2749 2025-05-20 22:18:43 +03:00
Ivan Pozdeev
a2d20cd3c3 Fix test 2025-05-20 22:13:26 +03:00
Florian Blanchet
11b615f709 Add unit tests for pwsh 2023-07-29 03:56:08 +03:00
Florian Blanchet
99c693df39 Add PowerShell autocompletion feature 2023-07-28 22:33:37 +03:00
Florian Blanchet
2ac251faa1 Add instructions for PowerShell in README.md 2023-07-28 22:32:36 +03:00
Florian Blanchet
2df60ca4ea Add Microsoft PowerShell support 2023-07-28 22:31:11 +03:00
12 changed files with 237 additions and 8 deletions

View File

@ -1,5 +1,9 @@
# Version History
## Release v2.6.12
* Add graalpy-25.0.1 by @msimacek in https://github.com/pyenv/pyenv/pull/3350
* Add CPython 3.9.25 by @nedbat in https://github.com/pyenv/pyenv/pull/3355
## Release v2.6.11
* Support building against Homebrew Tcl/Tk 9 by @native-api in https://github.com/pyenv/pyenv/pull/3343
* Add CPython 3.13.9 by @nedbat in https://github.com/pyenv/pyenv/pull/3346

View File

@ -271,6 +271,19 @@ See [Advanced configuration](#advanced-configuration) for details and more confi
</details>
#### Microsoft PowerShell
<details>
Add the commands to `$profile.CurrentUserAllHosts` by running the following in your terminal:
~~~ pwsh
echo '$Env:PYENV_ROOT="$HOME/.pyenv"' >> $profile.CurrentUserAllHosts
echo '$Env:PATH="$Env:PYENV_ROOT/bin:$Env:PATH"' >> $profile.CurrentUserAllHosts
echo 'iex ((pyenv init -) -join "`n")' >> $profile.CurrentUserAllHosts
~~~
</details>
### C. Restart your shell
----
@ -689,7 +702,7 @@ opposed to this idea. Here's what `eval "$(pyenv init -)"` actually does:
3. **Installs autocompletion.** This is entirely optional but pretty
useful. Sourcing `<pyenv installation prefix>/completions/pyenv.bash` will set that
up. There are also completions for Zsh and Fish.
up. There are also completions for Zsh, Fish and PowerShell.
4. **Rehashes shims.** From time to time you'll need to rebuild your
shim files. Doing this on init makes sure everything is up to

17
completions/pyenv.pwsh Normal file
View File

@ -0,0 +1,17 @@
$scriptblock = {
param($wordToComplete, $commandAst, $cursorPosition)
$words = $commandAst.ToString()
if ( $wordToComplete ) {
$matches = (($words[0..$cursorPosition] -join '') | Select-String -Pattern "\s+" -AllMatches).Matches
if ( $matches ) {
$cursorPosition = $matches[-1].Index - 1
}
}
$words = $words[0..$cursorPosition] -join '' -split "\s+"
if ( $words.Count -ge 2 ) {
pyenv completions $words[1] | where { $_ -match $wordToComplete }
} else {
pyenv commands | where { $_ -match $wordToComplete }
}
}
Register-ArgumentCompleter -Native -CommandName pyenv -ScriptBlock $scriptblock

View File

@ -12,7 +12,7 @@
set -e
[ -n "$PYENV_DEBUG" ] && set -x
version="2.6.11"
version="2.6.12"
git_revision=""
if cd "${BASH_SOURCE%/*}" 2>/dev/null && git remote -v 2>/dev/null | grep -q pyenv; then

View File

@ -15,6 +15,7 @@ if [ "$1" = "--complete" ]; then
echo bash
echo fish
echo ksh
echo pwsh
echo zsh
exit
fi
@ -102,6 +103,10 @@ function detect_profile() {
profile_explain="~/.bash_profile if it exists, otherwise ~/.profile"
rc='~/.bashrc'
;;
pwsh )
profile='~/.config/powershell/profile.ps1'
rc='~/.config/powershell/profile.ps1'
;;
zsh )
profile='~/.zprofile'
rc='~/.zshrc'
@ -150,6 +155,21 @@ function help_() {
echo 'pyenv init - fish | source'
echo
;;
pwsh )
echo '# Load pyenv automatically by appending'
echo -n "# the following to "
if [ "$profile" == "$rc" ]; then
echo "$profile :"
else
echo
echo "${profile_explain:-$profile} (for login shells)"
echo "and $rc (for interactive shells) :"
fi
echo
echo '$Env:PYENV_ROOT="$HOME/.pyenv"'
echo '$Env:PATH="$Env:PYENV_ROOT/bin:$Env:PATH"'
echo 'iex ((pyenv init -) -join "`n")'
;;
* )
echo '# Load pyenv automatically by appending'
echo -n "# the following to "
@ -186,6 +206,11 @@ function print_path() {
print_path_prepend_shims
echo 'end'
;;
pwsh )
echo 'if ( $Env:PATH -match "'"${PYENV_ROOT}/shims"'" ) {'
print_path_prepend_shims
echo '}'
;;
* )
echo 'if [[ ":$PATH:" != *'\':"${PYENV_ROOT}"/shims:\''* ]]; then'
print_path_prepend_shims
@ -199,6 +224,10 @@ function print_path() {
echo 'set -eg PATH[$pyenv_index]; end; set -e pyenv_index'
print_path_prepend_shims
;;
pwsh )
echo '$Env:PATH="$(($Env:PATH -split '"':'"' | where { -not ($_ -match '"'${PYENV_ROOT}/shims'"') }) -join '"':'"')"'
print_path_prepend_shims
;;
* )
# Some distros (notably Debian-based) set Bash's SSH_SOURCE_BASHRC compilation option
# that makes it source `bashrc` under SSH even when not interactive.
@ -223,6 +252,9 @@ function print_path_prepend_shims() {
fish )
echo 'set -gx PATH '\'"${PYENV_ROOT}/shims"\'' $PATH'
;;
pwsh )
echo '$Env:PATH="'"${PYENV_ROOT}"'/shims:$Env:PATH"'
;;
* )
echo 'export PATH="'"${PYENV_ROOT}"'/shims:${PATH}"'
;;
@ -234,6 +266,9 @@ function print_env() {
fish )
echo "set -gx PYENV_SHELL $shell"
;;
pwsh )
echo '$Env:PYENV_SHELL="'"$shell"'"'
;;
* )
echo "export PYENV_SHELL=$shell"
;;
@ -243,13 +278,27 @@ function print_env() {
function print_completion() {
completion="${0%/*/*}/completions/pyenv.${shell}"
if [ -r "$completion" ]; then
echo "source '$completion'"
case "$shell" in
pwsh )
echo "iex (gc $completion -Raw)"
;;
* )
echo "source '$completion'"
;;
esac
fi
}
function print_rehash() {
if [ -z "$no_rehash" ]; then
echo 'command pyenv rehash 2>/dev/null'
case "$shell" in
pwsh )
echo '& pyenv rehash 2>/dev/null'
;;
* )
echo 'command pyenv rehash 2>/dev/null'
;;
esac
fi
}
@ -270,6 +319,25 @@ function print_shell_function() {
end
end'
;;
pwsh )
cat <<EOS
function pyenv {
\$command=""
if ( \$args.Count -gt 0 ) {
\$command, \$args = \$args
}
if ( ("${commands[*]}" -split ' ') -contains \$command ) {
\$shell_cmds = & \$Env:PYENV_ROOT/bin/pyenv sh-\$command \$args
if ( \$shell_cmds.Count -gt 0 ) {
iex (\$shell_cmds -join "\`n")
}
} else {
& \$Env:PYENV_ROOT/bin/pyenv \$command \$args
}
}
EOS
;;
ksh | ksh93 | mksh )
echo \
'function pyenv {
@ -281,8 +349,8 @@ end'
local command=${1:-}'
;;
esac
if [ "$shell" != "fish" ]; then
if [ "$shell" != "fish" ] && [ "$shell" != "pwsh" ]; then
IFS="|"
echo \
' [ "$#" -gt 0 ] && shift

View File

@ -14,7 +14,7 @@ shell="$(basename "${PYENV_SHELL:-$SHELL}")"
pyenv-rehash
case "$shell" in
fish )
fish | pwsh )
# no rehash support
;;
* )

View File

@ -48,6 +48,9 @@ if [ "$versions" = "--unset" ]; then
echo 'set -gu PYENV_VERSION_OLD "$PYENV_VERSION"'
echo "set -e PYENV_VERSION"
;;
pwsh )
echo '$Env:PYENV_VERSION, $Env:PYENV_VERSION_OLD = $null, $Env:PYENV_VERSION'
;;
* )
echo 'PYENV_VERSION_OLD="${PYENV_VERSION-}"'
echo "unset PYENV_VERSION"
@ -74,6 +77,16 @@ else
echo "pyenv: PYENV_VERSION_OLD is not set" >&2
false
end
EOS
;;
pwsh )
cat <<EOS
if ( Get-Item -Path Env:\PYENV_VERSION* ) {
\$Env:PYENV_VERSION, \$Env:PYENV_VERSION_OLD = \$Env:PYENV_VERSION_OLD, \$Env:PYENV_VERSION
} else {
Write-Error "pyenv: Env:PYENV_VERSION_OLD is not set"
return \$false
}
EOS
;;
* )
@ -109,6 +122,9 @@ if pyenv-prefix "${versions[@]}" >/dev/null; then
echo 'set -gu PYENV_VERSION_OLD "$PYENV_VERSION"'
echo "set -gx PYENV_VERSION \"$version\""
;;
pwsh )
echo '$Env:PYENV_VERSION, $Env:PYENV_VERSION_OLD = "'"${version}"'", $Env:PYENV_VERSION'
;;
* )
echo 'PYENV_VERSION_OLD="${PYENV_VERSION-}"'
echo "export PYENV_VERSION=\"${version}\""

View File

@ -14,7 +14,7 @@
# -g/--debug Build a debug version
#
PYTHON_BUILD_VERSION="2.6.11"
PYTHON_BUILD_VERSION="2.6.12"
OLDIFS="$IFS"

View File

@ -0,0 +1,12 @@
prefer_openssl3
export PYTHON_BUILD_CONFIGURE_WITH_OPENSSL=1
# Avoid a compilation error when linking against OpenSSL built with SSLv3 support (fixed in 3.10.0) (#2181)
export PYTHON_CFLAGS="-DOPENSSL_NO_SSL3${PYTHON_CFLAGS:+ $PYTHON_CFLAGS}"
install_package "openssl-3.0.16" "https://github.com/openssl/openssl/releases/download/openssl-3.0.16/openssl-3.0.16.tar.gz#57e03c50feab5d31b152af2b764f10379aecd8ee92f16c985983ce4a99f7ef86" mac_openssl --if has_broken_mac_openssl
install_package "readline-8.1" "https://ftpmirror.gnu.org/readline/readline-8.1.tar.gz#f8ceb4ee131e3232226a17f51b164afc46cd0b9e6cef344be87c65962cb82b02" mac_readline --if has_broken_mac_readline
if has_tar_xz_support; then
install_package "Python-3.9.25" "https://www.python.org/ftp/python/3.9.25/Python-3.9.25.tar.xz#00e07d7c0f2f0cc002432d1ee84d2a40dae404a99303e3f97701c10966c91834" standard verify_py39 copy_python_gdb ensurepip
else
install_package "Python-3.9.25" "https://www.python.org/ftp/python/3.9.25/Python-3.9.25.tgz#a7438eabd3a48139f42d4e058096af8d880b0bb6e8fb8c78838892e4ce5583f2" standard verify_py39 copy_python_gdb ensurepip
fi

View File

@ -74,6 +74,19 @@ OUT
assert_line 'pyenv init - fish | source'
}
@test "setup shell completions (pwsh)" {
root="$(cd $BATS_TEST_DIRNAME/.. && pwd)"
run pyenv-init - pwsh
assert_success
assert_line "iex (gc ${root}/test/../libexec/../completions/pyenv.pwsh -Raw)"
}
@test "pwsh instructions" {
run pyenv-init pwsh
assert [ "$status" -eq 1 ]
assert_line 'iex ((pyenv init -) -join "`n")'
}
@test "shell detection for installer" {
run pyenv-init --detect-shell
assert_success
@ -100,6 +113,13 @@ OUT
assert_line "set -gx PATH '${PYENV_ROOT}/shims' \$PATH"
}
@test "adds shims to PATH (pwsh)" {
export PATH="${BATS_TEST_DIRNAME}/../libexec:/usr/bin:/bin:/usr/local/bin"
run pyenv-init - pwsh
assert_success
assert_line '$Env:PATH="'${PYENV_ROOT}'/shims:$Env:PATH"'
}
@test "removes existing shims from PATH" {
OLDPATH="$PATH"
export PATH="${BATS_TEST_DIRNAME}/nonexistent:${PYENV_ROOT}/shims:$PATH"
@ -124,6 +144,19 @@ echo "\$PATH"
assert_output "${PYENV_ROOT}/shims:${BATS_TEST_DIRNAME}/nonexistent:${OLDPATH//${PYENV_ROOT}\/shims:/}"
}
@test "removes existing shims from PATH (pwsh)" {
command -v pwsh >/dev/null || skip "-- pwsh not installed"
OLDPATH="$PATH"
export PATH="${BATS_TEST_DIRNAME}/nonexistent:${PYENV_ROOT}/shims:$PATH"
run pwsh -noni -c - <<!
\$Env:PATH="$PATH"
iex ((pyenv init -) -join "\`n")
echo "\$Env:PATH"
!
assert_success
assert_output "${PYENV_ROOT}/shims:${BATS_TEST_DIRNAME}/nonexistent:${OLDPATH//${PYENV_ROOT}\/shims:/}"
}
@test "adds shims to PATH with --no-push-path if they're not on PATH" {
export PATH="${BATS_TEST_DIRNAME}/../libexec:/usr/bin:/bin:/usr/local/bin"
run bash -e <<!
@ -146,6 +179,18 @@ echo "\$PATH"
assert_output "${PYENV_ROOT}/shims:${PATH}"
}
@test "adds shims to PATH with --no-push-path if they're not on PATH (pwsh)" {
command -v pwsh >/dev/null || skip "-- pwsh not installed"
export PATH="${BATS_TEST_DIRNAME}/../libexec:/usr/bin:/bin:/usr/local/bin"
run pwsh -noni -c - <<!
\$Env:PATH="$PATH"
iex ((pyenv init - --no-push-path) -join "\`n")
echo "\$Env:PATH"
!
assert_success
assert_output "${PYENV_ROOT}/shims:${PATH}"
}
@test "doesn't change PATH with --no-push-path if shims are already on PATH" {
export PATH="${BATS_TEST_DIRNAME}/../libexec:${PYENV_ROOT}/shims:/usr/bin:/bin:/usr/local/bin"
run bash -e <<!
@ -168,6 +213,18 @@ echo "\$PATH"
assert_output "${PATH}"
}
@test "doesn't change PATH with --no-push-path if shims are already on PATH (pwsh)" {
command -v pwsh >/dev/null || skip "-- pwsh not installed"
export PATH="${BATS_TEST_DIRNAME}/../libexec:/usr/bin:${PYENV_ROOT}/shims:/bin:/usr/local/bin"
run pwsh -noni -c - <<!
\$Env:PATH="$PATH"
iex ((pyenv init - --no-push-path) -join "\`n")
echo "\$Env:PATH"
!
assert_success
assert_output "${PATH}"
}
@test "outputs sh-compatible syntax" {
run pyenv-init - bash
assert_success
@ -202,3 +259,10 @@ echo
assert_line ' switch "$command"'
refute_line ' case "$command" in'
}
@test "outputs pwsh-specific syntax (pwsh)" {
run pyenv-init - pwsh
assert_success
refute_line ' switch "$command"'
refute_line ' case "$command" in'
}

View File

@ -120,3 +120,10 @@ SH
assert_success ""
assert [ -x "${PYENV_ROOT}/shims/python" ]
}
@test "sh-rehash in pwsh" {
create_executable "3.4" "python"
PYENV_SHELL=pwsh run pyenv-sh-rehash
assert_success ""
assert [ -x "${PYENV_ROOT}/shims/python" ]
}

View File

@ -31,6 +31,11 @@ load test_helper
assert_success 'echo "$PYENV_VERSION"'
}
@test "shell version (pwsh)" {
PYENV_SHELL=pwsh PYENV_VERSION="1.2.3" run pyenv-sh-shell
assert_success 'echo "$PYENV_VERSION"'
}
@test "shell revert" {
PYENV_SHELL=bash run pyenv-sh-shell -
assert_success
@ -43,6 +48,12 @@ load test_helper
assert_line 0 'if set -q PYENV_VERSION_OLD'
}
@test "shell revert (pwsh)" {
PYENV_SHELL=pwsh run pyenv-sh-shell -
assert_success
assert_line 0 'if ( Get-Item -Path Env:\PYENV_VERSION* ) {'
}
@test "shell unset" {
PYENV_SHELL=bash run pyenv-sh-shell --unset
assert_success
@ -61,6 +72,14 @@ set -e PYENV_VERSION
OUT
}
@test "shell unset (pwsh)" {
PYENV_SHELL=pwsh run pyenv-sh-shell --unset
assert_success
assert_output <<OUT
\$Env:PYENV_VERSION, \$Env:PYENV_VERSION_OLD = \$null, \$Env:PYENV_VERSION
OUT
}
@test "shell change invalid version" {
run pyenv-sh-shell 1.2.3
assert_failure
@ -89,3 +108,12 @@ set -gu PYENV_VERSION_OLD "\$PYENV_VERSION"
set -gx PYENV_VERSION "1.2.3"
OUT
}
@test "shell change version (pwsh)" {
mkdir -p "${PYENV_ROOT}/versions/1.2.3"
PYENV_SHELL=pwsh run pyenv-sh-shell 1.2.3
assert_success
assert_output <<OUT
\$Env:PYENV_VERSION, \$Env:PYENV_VERSION_OLD = "1.2.3", \$Env:PYENV_VERSION
OUT
}