pyenv/plugins/pyenv-binary/bin/pyenv-binary

66 lines
1.6 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 bash
#
# Summary: Package an installed Python version as a relocatable binary (experimental)
#
# Usage: pyenv binary <command> [<args>]
#
# `pyenv binary` packages an already-installed Python version into a relocatable
# archive that can be installed on another machine. It is experimental and does
# not touch `pyenv install' or any other command.
#
# Run `pyenv binary' to list its commands, or `pyenv binary <command> --help'
# for command-specific help.
#
set -e
[ -n "$PYENV_DEBUG" ] && set -x
libexec="${BASH_SOURCE%/*}/../libexec"
# The pyenv launcher only puts a plugin's bin on PATH, but `pyenv-help' looks a
# command up there. Add our libexec so the subcommands, and the help text they
# print, can be found.
export PATH="${libexec}:${PATH}"
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
list_commands() {
local path
for path in "$libexec"/pyenv-binary-*; do
[ -e "$path" ] && echo "${path##*/pyenv-binary-}"
done
}
# Provide pyenv completions
if [ "$1" = "--complete" ]; then
shift
if [ -z "$1" ]; then
list_commands
else
command_path="${libexec}/pyenv-binary-$1"
shift
[ -x "$command_path" ] && exec "$command_path" --complete "$@"
fi
exit
fi
subcommand="$1"
if [ -z "$subcommand" ]; then
{ pyenv-help binary
echo
echo "Commands:"
list_commands | sed 's/^/ /'
} >&2
exit 1
fi
shift
command_path="${libexec}/pyenv-binary-${subcommand}"
if [ ! -x "$command_path" ]; then
echo "pyenv-binary: no such command \`${subcommand}'" >&2
exit 1
fi
if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
exec pyenv-help "binary-${subcommand}"
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
fi
exec "$command_path" "$@"