110 lines
3.1 KiB
Plaintext
Raw Normal View History

Add an experimental pyenv-binary plugin with a save command (#3487) * pyenv-binary: add experimental plugin skeleton Adds a new plugin, decoupled from `pyenv install`, for packaging and installing relocatable Python binaries. This commit is just the command dispatcher; the individual subcommands follow. `pyenv binary <command>` dispatches to the matching script under the plugin's libexec, so subcommands stay out of the top-level `pyenv commands` list. Groundwork for the binary distribution support discussed in #2334. * pyenv-binary: add the `save` subcommand `pyenv binary save <version> [<output-dir>]` packs an installed version into a relocatable .tar.gz with relative paths and writes a metadata file recording the build platform, distro, libc version and the external system libraries the build links against (via `ldd` on Linux, `otool -L` on macOS). * pyenv-binary: reject invalid version names and drop readlink -f in save A version is a single directory name under versions/, so refuse names with a slash or a dot-dot component before building the prefix path. Also emit the python paths directly instead of `readlink -f`, which BSD readlink on macOS does not support; ldd/otool follow the symlinks anyway, so the resolved paths were never needed. * pyenv-binary: test the `save` subcommand Cover argument validation, the version-name guard, and packaging an installed version into an archive with matching metadata. * pyenv-binary: test dependency parsing and tighten the version guard Add tests that feed realistic ldd and otool listings through save and check only the libraries resolving outside the prefix end up in the metadata, since that filtering is the fiddliest part of the command. Narrow the version guard to reject `.' and `..' rather than any name containing a dot-dot, now that a slash is already refused, and note why the find still matches *.so.* even though CPython does not produce them.
2026-07-03 11:38:54 +05:30
#!/usr/bin/env bats
load test_helper
create_version() {
mkdir -p "${PYENV_ROOT}/versions/$1/bin"
}
platform() {
echo "$(uname -s | tr '[:upper:]' '[:lower:]')-$(uname -m)"
}
@test "fails with no version given" {
run pyenv-binary-save
assert_failure "Usage: pyenv binary save <version> [<output-dir>]"
}
@test "fails for a version that is not installed" {
run pyenv-binary-save 9.9.9
assert_failure "pyenv-binary: version \`9.9.9' is not installed"
}
@test "rejects a version name containing a slash" {
run pyenv-binary-save "foo/bar"
assert_failure "pyenv-binary: invalid version name \`foo/bar'"
}
@test "rejects the parent directory reference" {
run pyenv-binary-save ".."
assert_failure "pyenv-binary: invalid version name \`..'"
}
@test "packages an installed version" {
create_version "3.12.7"
local out="${BATS_TEST_TMPDIR}/dist"
local archive="${out}/3.12.7-$(platform).tar.gz"
Add an experimental pyenv-binary plugin with a save command (#3487) * pyenv-binary: add experimental plugin skeleton Adds a new plugin, decoupled from `pyenv install`, for packaging and installing relocatable Python binaries. This commit is just the command dispatcher; the individual subcommands follow. `pyenv binary <command>` dispatches to the matching script under the plugin's libexec, so subcommands stay out of the top-level `pyenv commands` list. Groundwork for the binary distribution support discussed in #2334. * pyenv-binary: add the `save` subcommand `pyenv binary save <version> [<output-dir>]` packs an installed version into a relocatable .tar.gz with relative paths and writes a metadata file recording the build platform, distro, libc version and the external system libraries the build links against (via `ldd` on Linux, `otool -L` on macOS). * pyenv-binary: reject invalid version names and drop readlink -f in save A version is a single directory name under versions/, so refuse names with a slash or a dot-dot component before building the prefix path. Also emit the python paths directly instead of `readlink -f`, which BSD readlink on macOS does not support; ldd/otool follow the symlinks anyway, so the resolved paths were never needed. * pyenv-binary: test the `save` subcommand Cover argument validation, the version-name guard, and packaging an installed version into an archive with matching metadata. * pyenv-binary: test dependency parsing and tighten the version guard Add tests that feed realistic ldd and otool listings through save and check only the libraries resolving outside the prefix end up in the metadata, since that filtering is the fiddliest part of the command. Narrow the version guard to reject `.' and `..' rather than any name containing a dot-dot, now that a slash is already refused, and note why the find still matches *.so.* even though CPython does not produce them.
2026-07-03 11:38:54 +05:30
run pyenv-binary-save "3.12.7" "$out"
assert_success "Saved 3.12.7-$(platform).tar.gz and 3.12.7-$(platform).meta to $out"
assert [ -f "$archive" ]
Add an experimental pyenv-binary plugin with a save command (#3487) * pyenv-binary: add experimental plugin skeleton Adds a new plugin, decoupled from `pyenv install`, for packaging and installing relocatable Python binaries. This commit is just the command dispatcher; the individual subcommands follow. `pyenv binary <command>` dispatches to the matching script under the plugin's libexec, so subcommands stay out of the top-level `pyenv commands` list. Groundwork for the binary distribution support discussed in #2334. * pyenv-binary: add the `save` subcommand `pyenv binary save <version> [<output-dir>]` packs an installed version into a relocatable .tar.gz with relative paths and writes a metadata file recording the build platform, distro, libc version and the external system libraries the build links against (via `ldd` on Linux, `otool -L` on macOS). * pyenv-binary: reject invalid version names and drop readlink -f in save A version is a single directory name under versions/, so refuse names with a slash or a dot-dot component before building the prefix path. Also emit the python paths directly instead of `readlink -f`, which BSD readlink on macOS does not support; ldd/otool follow the symlinks anyway, so the resolved paths were never needed. * pyenv-binary: test the `save` subcommand Cover argument validation, the version-name guard, and packaging an installed version into an archive with matching metadata. * pyenv-binary: test dependency parsing and tighten the version guard Add tests that feed realistic ldd and otool listings through save and check only the libraries resolving outside the prefix end up in the metadata, since that filtering is the fiddliest part of the command. Narrow the version guard to reject `.' and `..' rather than any name containing a dot-dot, now that a slash is already refused, and note why the find still matches *.so.* even though CPython does not produce them.
2026-07-03 11:38:54 +05:30
assert [ -f "${out}/3.12.7-$(platform).meta" ]
run tar -tzf "$archive"
assert_success
assert_line 0 "3.12.7/"
Add an experimental pyenv-binary plugin with a save command (#3487) * pyenv-binary: add experimental plugin skeleton Adds a new plugin, decoupled from `pyenv install`, for packaging and installing relocatable Python binaries. This commit is just the command dispatcher; the individual subcommands follow. `pyenv binary <command>` dispatches to the matching script under the plugin's libexec, so subcommands stay out of the top-level `pyenv commands` list. Groundwork for the binary distribution support discussed in #2334. * pyenv-binary: add the `save` subcommand `pyenv binary save <version> [<output-dir>]` packs an installed version into a relocatable .tar.gz with relative paths and writes a metadata file recording the build platform, distro, libc version and the external system libraries the build links against (via `ldd` on Linux, `otool -L` on macOS). * pyenv-binary: reject invalid version names and drop readlink -f in save A version is a single directory name under versions/, so refuse names with a slash or a dot-dot component before building the prefix path. Also emit the python paths directly instead of `readlink -f`, which BSD readlink on macOS does not support; ldd/otool follow the symlinks anyway, so the resolved paths were never needed. * pyenv-binary: test the `save` subcommand Cover argument validation, the version-name guard, and packaging an installed version into an archive with matching metadata. * pyenv-binary: test dependency parsing and tighten the version guard Add tests that feed realistic ldd and otool listings through save and check only the libraries resolving outside the prefix end up in the metadata, since that filtering is the fiddliest part of the command. Narrow the version guard to reject `.' and `..' rather than any name containing a dot-dot, now that a slash is already refused, and note why the find still matches *.so.* even though CPython does not produce them.
2026-07-03 11:38:54 +05:30
}
@test "records the platform in the metadata" {
create_version "3.12.7"
local out="${BATS_TEST_TMPDIR}/dist"
pyenv-binary-save "3.12.7" "$out" >/dev/null
Add an experimental pyenv-binary plugin with a save command (#3487) * pyenv-binary: add experimental plugin skeleton Adds a new plugin, decoupled from `pyenv install`, for packaging and installing relocatable Python binaries. This commit is just the command dispatcher; the individual subcommands follow. `pyenv binary <command>` dispatches to the matching script under the plugin's libexec, so subcommands stay out of the top-level `pyenv commands` list. Groundwork for the binary distribution support discussed in #2334. * pyenv-binary: add the `save` subcommand `pyenv binary save <version> [<output-dir>]` packs an installed version into a relocatable .tar.gz with relative paths and writes a metadata file recording the build platform, distro, libc version and the external system libraries the build links against (via `ldd` on Linux, `otool -L` on macOS). * pyenv-binary: reject invalid version names and drop readlink -f in save A version is a single directory name under versions/, so refuse names with a slash or a dot-dot component before building the prefix path. Also emit the python paths directly instead of `readlink -f`, which BSD readlink on macOS does not support; ldd/otool follow the symlinks anyway, so the resolved paths were never needed. * pyenv-binary: test the `save` subcommand Cover argument validation, the version-name guard, and packaging an installed version into an archive with matching metadata. * pyenv-binary: test dependency parsing and tighten the version guard Add tests that feed realistic ldd and otool listings through save and check only the libraries resolving outside the prefix end up in the metadata, since that filtering is the fiddliest part of the command. Narrow the version guard to reject `.' and `..' rather than any name containing a dot-dot, now that a slash is already refused, and note why the find still matches *.so.* even though CPython does not produce them.
2026-07-03 11:38:54 +05:30
run cat "${out}/3.12.7-$(platform).meta"
assert_success
assert_line "version=3.12.7"
assert_line "platform=$(platform)"
assert_line "archive=3.12.7-$(platform).tar.gz"
Add an experimental pyenv-binary plugin with a save command (#3487) * pyenv-binary: add experimental plugin skeleton Adds a new plugin, decoupled from `pyenv install`, for packaging and installing relocatable Python binaries. This commit is just the command dispatcher; the individual subcommands follow. `pyenv binary <command>` dispatches to the matching script under the plugin's libexec, so subcommands stay out of the top-level `pyenv commands` list. Groundwork for the binary distribution support discussed in #2334. * pyenv-binary: add the `save` subcommand `pyenv binary save <version> [<output-dir>]` packs an installed version into a relocatable .tar.gz with relative paths and writes a metadata file recording the build platform, distro, libc version and the external system libraries the build links against (via `ldd` on Linux, `otool -L` on macOS). * pyenv-binary: reject invalid version names and drop readlink -f in save A version is a single directory name under versions/, so refuse names with a slash or a dot-dot component before building the prefix path. Also emit the python paths directly instead of `readlink -f`, which BSD readlink on macOS does not support; ldd/otool follow the symlinks anyway, so the resolved paths were never needed. * pyenv-binary: test the `save` subcommand Cover argument validation, the version-name guard, and packaging an installed version into an archive with matching metadata. * pyenv-binary: test dependency parsing and tighten the version guard Add tests that feed realistic ldd and otool listings through save and check only the libraries resolving outside the prefix end up in the metadata, since that filtering is the fiddliest part of the command. Narrow the version guard to reject `.' and `..' rather than any name containing a dot-dot, now that a slash is already refused, and note why the find still matches *.so.* even though CPython does not produce them.
2026-07-03 11:38:54 +05:30
}
@test "records only the libraries ldd resolves outside the prefix" {
create_version "3.12.7"
touch "${PYENV_ROOT}/versions/3.12.7/bin/python3.12"
create_path_executable uname <<'STUB'
case "$1" in
-s) echo Linux ;;
-m) echo x86_64 ;;
esac
STUB
create_path_executable ldd <<'STUB'
Add an experimental pyenv-binary plugin with a save command (#3487) * pyenv-binary: add experimental plugin skeleton Adds a new plugin, decoupled from `pyenv install`, for packaging and installing relocatable Python binaries. This commit is just the command dispatcher; the individual subcommands follow. `pyenv binary <command>` dispatches to the matching script under the plugin's libexec, so subcommands stay out of the top-level `pyenv commands` list. Groundwork for the binary distribution support discussed in #2334. * pyenv-binary: add the `save` subcommand `pyenv binary save <version> [<output-dir>]` packs an installed version into a relocatable .tar.gz with relative paths and writes a metadata file recording the build platform, distro, libc version and the external system libraries the build links against (via `ldd` on Linux, `otool -L` on macOS). * pyenv-binary: reject invalid version names and drop readlink -f in save A version is a single directory name under versions/, so refuse names with a slash or a dot-dot component before building the prefix path. Also emit the python paths directly instead of `readlink -f`, which BSD readlink on macOS does not support; ldd/otool follow the symlinks anyway, so the resolved paths were never needed. * pyenv-binary: test the `save` subcommand Cover argument validation, the version-name guard, and packaging an installed version into an archive with matching metadata. * pyenv-binary: test dependency parsing and tighten the version guard Add tests that feed realistic ldd and otool listings through save and check only the libraries resolving outside the prefix end up in the metadata, since that filtering is the fiddliest part of the command. Narrow the version guard to reject `.' and `..' rather than any name containing a dot-dot, now that a slash is already refused, and note why the find still matches *.so.* even though CPython does not produce them.
2026-07-03 11:38:54 +05:30
prefix="${PYENV_ROOT}/versions/3.12.7"
cat <<EOF
linux-vdso.so.1 (0x00007ffd1adfe000)
libpython3.12.so.1.0 => ${prefix}/lib/libpython3.12.so.1.0 (0x00007f4a3c000000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f4a3bc00000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f4a3b800000)
/lib64/ld-linux-x86-64.so.2 (0x00007f4a3c200000)
EOF
STUB
run pyenv-binary-save "3.12.7" "${BATS_TEST_TMPDIR}/dist"
assert_success
run grep '^dep=' "${BATS_TEST_TMPDIR}/dist/"*.meta
assert_output "dep=libc.so.6
dep=libm.so.6"
}
@test "records only the libraries otool resolves outside the prefix" {
create_version "3.12.7"
touch "${PYENV_ROOT}/versions/3.12.7/bin/python3.12"
create_path_executable uname <<'STUB'
Add an experimental pyenv-binary plugin with a save command (#3487) * pyenv-binary: add experimental plugin skeleton Adds a new plugin, decoupled from `pyenv install`, for packaging and installing relocatable Python binaries. This commit is just the command dispatcher; the individual subcommands follow. `pyenv binary <command>` dispatches to the matching script under the plugin's libexec, so subcommands stay out of the top-level `pyenv commands` list. Groundwork for the binary distribution support discussed in #2334. * pyenv-binary: add the `save` subcommand `pyenv binary save <version> [<output-dir>]` packs an installed version into a relocatable .tar.gz with relative paths and writes a metadata file recording the build platform, distro, libc version and the external system libraries the build links against (via `ldd` on Linux, `otool -L` on macOS). * pyenv-binary: reject invalid version names and drop readlink -f in save A version is a single directory name under versions/, so refuse names with a slash or a dot-dot component before building the prefix path. Also emit the python paths directly instead of `readlink -f`, which BSD readlink on macOS does not support; ldd/otool follow the symlinks anyway, so the resolved paths were never needed. * pyenv-binary: test the `save` subcommand Cover argument validation, the version-name guard, and packaging an installed version into an archive with matching metadata. * pyenv-binary: test dependency parsing and tighten the version guard Add tests that feed realistic ldd and otool listings through save and check only the libraries resolving outside the prefix end up in the metadata, since that filtering is the fiddliest part of the command. Narrow the version guard to reject `.' and `..' rather than any name containing a dot-dot, now that a slash is already refused, and note why the find still matches *.so.* even though CPython does not produce them.
2026-07-03 11:38:54 +05:30
case "$1" in
-s) echo Darwin ;;
-m) echo arm64 ;;
esac
STUB
create_path_executable otool <<'STUB'
Add an experimental pyenv-binary plugin with a save command (#3487) * pyenv-binary: add experimental plugin skeleton Adds a new plugin, decoupled from `pyenv install`, for packaging and installing relocatable Python binaries. This commit is just the command dispatcher; the individual subcommands follow. `pyenv binary <command>` dispatches to the matching script under the plugin's libexec, so subcommands stay out of the top-level `pyenv commands` list. Groundwork for the binary distribution support discussed in #2334. * pyenv-binary: add the `save` subcommand `pyenv binary save <version> [<output-dir>]` packs an installed version into a relocatable .tar.gz with relative paths and writes a metadata file recording the build platform, distro, libc version and the external system libraries the build links against (via `ldd` on Linux, `otool -L` on macOS). * pyenv-binary: reject invalid version names and drop readlink -f in save A version is a single directory name under versions/, so refuse names with a slash or a dot-dot component before building the prefix path. Also emit the python paths directly instead of `readlink -f`, which BSD readlink on macOS does not support; ldd/otool follow the symlinks anyway, so the resolved paths were never needed. * pyenv-binary: test the `save` subcommand Cover argument validation, the version-name guard, and packaging an installed version into an archive with matching metadata. * pyenv-binary: test dependency parsing and tighten the version guard Add tests that feed realistic ldd and otool listings through save and check only the libraries resolving outside the prefix end up in the metadata, since that filtering is the fiddliest part of the command. Narrow the version guard to reject `.' and `..' rather than any name containing a dot-dot, now that a slash is already refused, and note why the find still matches *.so.* even though CPython does not produce them.
2026-07-03 11:38:54 +05:30
prefix="${PYENV_ROOT}/versions/3.12.7"
cat <<EOF
${2}:
@rpath/libpython3.12.dylib (compatibility version 3.12.0, current version 3.12.0)
${prefix}/lib/libcrypto.3.dylib (compatibility version 3.0.0, current version 3.0.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1345.0.0)
EOF
STUB
run pyenv-binary-save "3.12.7" "${BATS_TEST_TMPDIR}/dist"
assert_success
run grep '^dep=' "${BATS_TEST_TMPDIR}/dist/"*.meta
assert_output "dep=/usr/lib/libSystem.B.dylib"
}