Compare commits

...

12 Commits

Author SHA1 Message Date
dependabot[bot]
bdf8d254fe
Bump actions/setup-python from 6 to 7 in the github-actions group (#3505)
Bumps the github-actions group with 1 update: [actions/setup-python](https://github.com/actions/setup-python).


Updates `actions/setup-python` from 6 to 7
- [Release notes](https://github.com/actions/setup-python/releases)
- [Commits](https://github.com/actions/setup-python/compare/v6...v7)

---
updated-dependencies:
- dependency-name: actions/setup-python
  dependency-version: '7'
  dependency-type: direct:production
  update-type: version-update:semver-major
  dependency-group: github-actions
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-08-01 16:38:32 +03:00
Michael Šimáček
f5915fc866
Add graalpy3.12-25.2.4 (#3502) 2026-07-29 05:53:27 +03:00
Michael Newman
84e0f3a887
Fix typos 2026-07-29 05:49:46 +03:00
Ayush
7126870320
pyenv-binary: add the package subcommand; add pyenv install --list --bare (#3498)
Co-authored-by: native-api <vano@mail.mipt.ru>
Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com>
2026-07-28 14:31:20 +03:00
Michael Newman
26dd5d9dda
Fix typo 2026-07-27 21:57:58 +03:00
Michael Newman
bac39a0ef8
Fix typo 2026-07-27 08:30:33 +03:00
Ivan Pozdeev
bec9a562a5 2.8.1 2026-07-18 22:02:09 +03:00
pyenv-bot[bot]
ae9e6594d6
Add CPython 3.15.0b4 (#3495)
Co-authored-by: native-api <2670332+native-api@users.noreply.github.com>
2026-07-18 21:59:23 +03:00
native-api
16c7cc6de4
Merge pull request #3488 from macayu17/feat/2334-pyenv-binary-installer
pyenv-binary: add the `generate-installer` subcommand
2026-07-16 10:51:36 +03:00
Ivan Pozdeev
017ad4a573 Add pyenv-binary tests to CI
* README: fix tests instructions
* test/README: -duplicating and unnecessary stuff
* Makefile: Build Docker images and replace bats link conditionally
* Makefile: fix indent irregularity
2026-07-16 10:39:55 +03:00
macayu17
6188e9efa9 pyenv-binary: add the generate-installer subcommand
* Relocation only implemented for Linux (requires patchelf + ldconfig -p)
* Shell-completing file name is not possible with current Pyenv completion logic:
  `pyenv-complete` does not pass info about the word being completed
* Fix `save`-produced tarball to be compatible with Python-Build fetch_tarball()
* Reuse test_helper from core

--

Co-authored-by: Ivan Pozdeev <vano@mail.mipt.ru>
2026-07-16 10:39:50 +03:00
Ivan Pozdeev
286a167cf0 gitignore Vim swap files 2026-07-16 10:22:39 +03:00
26 changed files with 981 additions and 217 deletions

View File

@ -15,7 +15,7 @@ jobs:
runs-on: ubuntu-slim runs-on: ubuntu-slim
steps: steps:
- uses: actions/checkout@v7 - uses: actions/checkout@v7
- uses: actions/setup-python@v6 - uses: actions/setup-python@v7
with: with:
python-version: 3 python-version: 3
cache: 'pip' cache: 'pip'

1
.gitignore vendored
View File

@ -11,3 +11,4 @@
/default-packages /default-packages
.idea .idea
*.un~ *.un~
*.swp

View File

@ -1,5 +1,9 @@
# Version History # Version History
## Release v2.8.1
* pyenv-binary: add the `generate-installer` subcommand by @macayu17 in https://github.com/pyenv/pyenv/pull/3488
* Add CPython 3.15.0b4 by @pyenv-bot[bot] in https://github.com/pyenv/pyenv/pull/3495
## Release v2.8.0 ## Release v2.8.0
* CI: add_version enhancements by @native-api in https://github.com/pyenv/pyenv/pull/3480 * CI: add_version enhancements by @native-api in https://github.com/pyenv/pyenv/pull/3480
* Add miniforge3-26.3.2-2, 26.3.2-3 by @native-api in https://github.com/pyenv/pyenv/pull/3481 * Add miniforge3-26.3.2-2, 26.3.2-3 by @native-api in https://github.com/pyenv/pyenv/pull/3481
@ -383,7 +387,7 @@
* Add CPython 3.13.0a4 by @saaketp in https://github.com/pyenv/pyenv/pull/2903 * Add CPython 3.13.0a4 by @saaketp in https://github.com/pyenv/pyenv/pull/2903
* Handle the case where `pyenv-commands --sh` returns nothing by @aphedges in https://github.com/pyenv/pyenv/pull/2908 * Handle the case where `pyenv-commands --sh` returns nothing by @aphedges in https://github.com/pyenv/pyenv/pull/2908
* Document default build configuration customizations by @native-api in https://github.com/pyenv/pyenv/pull/2911 * Document default build configuration customizations by @native-api in https://github.com/pyenv/pyenv/pull/2911
* Use Homebrew in Linux if Pyenv is installled with Homebrew by @native-api in https://github.com/pyenv/pyenv/pull/2906 * Use Homebrew in Linux if Pyenv is installed with Homebrew by @native-api in https://github.com/pyenv/pyenv/pull/2906
* Add miniforge and mambaforge 22.11.1-3, 22.11.1-4, 23.1.0-0 to 23.11.0-0 by @aphedges in https://github.com/pyenv/pyenv/pull/2909 * Add miniforge and mambaforge 22.11.1-3, 22.11.1-4, 23.1.0-0 to 23.11.0-0 by @aphedges in https://github.com/pyenv/pyenv/pull/2909
* Add miniconda3-24.1.2 by @binbjz in https://github.com/pyenv/pyenv/pull/2915 * Add miniconda3-24.1.2 by @binbjz in https://github.com/pyenv/pyenv/pull/2915
* Minor grammar fix in libffi backport patch in 2.5.x by @cuinix in https://github.com/pyenv/pyenv/pull/2922 * Minor grammar fix in libffi backport patch in 2.5.x by @cuinix in https://github.com/pyenv/pyenv/pull/2922
@ -1519,7 +1523,7 @@
* pyenv: Prefer gawk over awk if both are available. * pyenv: Prefer gawk over awk if both are available.
* python-build: Add new PyPy release; pypy-2.3, pypy-2.3-src (#162) * python-build: Add new PyPy release; pypy-2.3, pypy-2.3-src (#162)
* python-build: Add new Anaconda release; anaconda-1.9.2 (#155) * python-build: Add new Anaconda release; anaconda-1.9.2 (#155)
* python-build: Add new Miniconda releases; miniconda-3.3.0, minoconda-3.4.2, miniconda3-3.3.0, miniconda3-3.4.2 * python-build: Add new Miniconda releases; miniconda-3.3.0, miniconda-3.4.2, miniconda3-3.3.0, miniconda3-3.4.2
* python-build: Add new Stackless releases; stackless-2.7.3, stackless-2.7.4, stackless-2.7.5, stackless-2.7.6, stackless-3.2.5, stackless-3.3.5 (#164) * python-build: Add new Stackless releases; stackless-2.7.3, stackless-2.7.4, stackless-2.7.5, stackless-2.7.6, stackless-3.2.5, stackless-3.3.5 (#164)
* python-build: Add IronPython versions (setuptools and pip will work); ironpython-2.7.4, ironpython-dev * python-build: Add IronPython versions (setuptools and pip will work); ironpython-2.7.4, ironpython-dev
* python-build: Add new Jython beta release; jython-2.7-beta2 * python-build: Add new Jython beta release; jython-2.7-beta2

View File

@ -1,16 +1,21 @@
TEST_BATS_VERSION = v1.10.0 TEST_BATS_VERSION = v1.10.0
TEST_BASH_VERSIONS = 3.2.57 4.1.17 TEST_BASH_VERSIONS = 3.2.57 4.1.17
TEST_UNIT_DOCKER_PREFIX = test-unit-docker TEST_UNIT_DOCKER_PREFIX = test-unit-docker
TEST_UNIT_DOCKER_TARGETS = $(foreach bash,$(TEST_BASH_VERSIONS),$(addsuffix -$(bash),$(TEST_UNIT_DOCKER_PREFIX)) $(addsuffix -gnu-$(bash),$(TEST_UNIT_DOCKER_PREFIX))) TEST_UNIT_DOCKER_TARGETS = $(foreach bash,$(TEST_BASH_VERSIONS),$(addsuffix -$(bash),$(TEST_UNIT_DOCKER_PREFIX)) $(addsuffix -gnu-$(bash),$(TEST_UNIT_DOCKER_PREFIX)))
TEST_PLUGIN_DOCKER_PREFIX = test-plugin-docker
TEST_PLUGIN_DOCKER_TARGETS = $(foreach bash,$(TEST_BASH_VERSIONS),$(addsuffix -$(bash),$(TEST_PLUGIN_DOCKER_PREFIX)) $(addsuffix -gnu-$(bash),$(TEST_PLUGIN_DOCKER_PREFIX))) TEST_PYTHON_BUILD_DOCKER_PREFIX = test-python-build-docker
TEST_PYTHON_BUILD_DOCKER_TARGETS = $(foreach bash,$(TEST_BASH_VERSIONS),$(addsuffix -$(bash),$(TEST_PYTHON_BUILD_DOCKER_PREFIX)) $(addsuffix -gnu-$(bash),$(TEST_PYTHON_BUILD_DOCKER_PREFIX)))
TEST_BINARY_DOCKER_PREFIX = test-binary-docker
TEST_BINARY_DOCKER_TARGETS = $(foreach bash,$(TEST_BASH_VERSIONS),$(addsuffix -$(bash),$(TEST_BINARY_DOCKER_PREFIX)) $(addsuffix -gnu-$(bash),$(TEST_BINARY_DOCKER_PREFIX)))
TEST_BATS_IMAGE_PREFIX = test-pyenv-docker-image TEST_BATS_IMAGE_PREFIX = test-pyenv-docker-image
TEST_BATS_IMAGE_TARGETS = $(foreach bash,$(TEST_BASH_VERSIONS),$(addsuffix -$(bash),$(TEST_BATS_IMAGE_PREFIX)) $(addsuffix -gnu-$(bash),$(TEST_BATS_IMAGE_PREFIX))) TEST_BATS_IMAGE_TARGETS = $(foreach bash,$(TEST_BASH_VERSIONS),$(addsuffix -$(bash),$(TEST_BATS_IMAGE_PREFIX)) $(addsuffix -gnu-$(bash),$(TEST_BATS_IMAGE_PREFIX)))
.PHONY: .PHONY: test-docker
test-docker: $(TEST_UNIT_DOCKER_PREFIX) $(TEST_PLUGIN_DOCKER_PREFIX) test-docker: $(TEST_UNIT_DOCKER_PREFIX) $(TEST_PYTHON_BUILD_DOCKER_PREFIX) $(TEST_BINARY_DOCKER_PREFIX)
# Run all unit test under bats docker
.PHONY: $(TEST_UNIT_DOCKER_PREFIX) .PHONY: $(TEST_UNIT_DOCKER_PREFIX)
$(TEST_UNIT_DOCKER_PREFIX): $(TEST_UNIT_DOCKER_TARGETS) $(TEST_UNIT_DOCKER_PREFIX): $(TEST_UNIT_DOCKER_TARGETS)
@ -31,23 +36,22 @@ $(TEST_UNIT_DOCKER_TARGETS): $(TEST_UNIT_DOCKER_PREFIX)-% : $(TEST_BATS_IMAGE_PR
-u "$$(id -u $$(whoami)):$$(id -g $$(whoami))" \ -u "$$(id -u $$(whoami)):$$(id -g $$(whoami))" \
$${BATS_TEST_FILTER:+-e BATS_TEST_FILTER="$${BATS_TEST_FILTER}"} \ $${BATS_TEST_FILTER:+-e BATS_TEST_FILTER="$${BATS_TEST_FILTER}"} \
$${BATS_FILE_FILTER:+-e BATS_FILE_FILTER="$${BATS_FILE_FILTER}"} \ $${BATS_FILE_FILTER:+-e BATS_FILE_FILTER="$${BATS_FILE_FILTER}"} \
$${CI+-e CI="$${CI}"} \ $${CI+-e CI="$${CI}"} \
$(INTERACTIVE) \ $(INTERACTIVE) \
$(DOCKER_IMAGE):$(DOCKER_TAG) \ $(DOCKER_IMAGE):$(DOCKER_TAG) \
test/run test/run
# Run all plugin test under bats docker .PHONY: $(TEST_PYTHON_BUILD_DOCKER_PREFIX)
.PHONY: $(TEST_PLUGIN_DOCKER_PREFIX) $(TEST_PYTHON_BUILD_DOCKER_PREFIX): $(TEST_PYTHON_BUILD_DOCKER_TARGETS)
$(TEST_PLUGIN_DOCKER_PREFIX): $(TEST_PLUGIN_DOCKER_TARGETS)
# Run each plugin test under bats docker # Run each plugin test under bats docker
.PHONY: $(TEST_PLUGIN_DOCKER_TARGETS) .PHONY: $(TEST_PYTHON_BUILD_DOCKER_TARGETS)
$(TEST_PLUGIN_DOCKER_TARGETS): DOCKER_IMAGE = $(TEST_BATS_IMAGE_PREFIX) $(TEST_PYTHON_BUILD_DOCKER_TARGETS): DOCKER_IMAGE = $(TEST_BATS_IMAGE_PREFIX)
$(TEST_PLUGIN_DOCKER_TARGETS): GNU = $(if $(findstring -gnu-,$@),True,False) $(TEST_PYTHON_BUILD_DOCKER_TARGETS): GNU = $(if $(findstring -gnu-,$@),True,False)
$(TEST_PLUGIN_DOCKER_TARGETS): BASH = $(filter $(TEST_BASH_VERSIONS),$(subst -, ,$@)) $(TEST_PYTHON_BUILD_DOCKER_TARGETS): BASH = $(filter $(TEST_BASH_VERSIONS),$(subst -, ,$@))
$(TEST_PLUGIN_DOCKER_TARGETS): DOCKER_TAG = bash-$(BASH)-gnu-$(GNU) $(TEST_PYTHON_BUILD_DOCKER_TARGETS): DOCKER_TAG = bash-$(BASH)-gnu-$(GNU)
$(TEST_PLUGIN_DOCKER_TARGETS): INTERACTIVE = $(if $(findstring true,$(CI)),,-ti) $(TEST_PYTHON_BUILD_DOCKER_TARGETS): INTERACTIVE = $(if $(findstring true,$(CI)),,-ti)
$(TEST_PLUGIN_DOCKER_TARGETS): $(TEST_PLUGIN_DOCKER_PREFIX)-% : $(TEST_BATS_IMAGE_PREFIX)-% $(TEST_PYTHON_BUILD_DOCKER_TARGETS): $(TEST_PYTHON_BUILD_DOCKER_PREFIX)-% : $(TEST_BATS_IMAGE_PREFIX)-%
$(info Running test with docker image '$(DOCKER_IMAGE):$(DOCKER_TAG)') $(info Running test with docker image '$(DOCKER_IMAGE):$(DOCKER_TAG)')
docker run \ docker run \
--init \ --init \
@ -55,11 +59,33 @@ $(TEST_PLUGIN_DOCKER_TARGETS): $(TEST_PLUGIN_DOCKER_PREFIX)-% : $(TEST_BATS_IMAG
-v /etc/passwd:/etc/passwd:ro \ -v /etc/passwd:/etc/passwd:ro \
-v /etc/group:/etc/group:ro \ -v /etc/group:/etc/group:ro \
-u "$$(id -u $$(whoami)):$$(id -g $$(whoami))" \ -u "$$(id -u $$(whoami)):$$(id -g $$(whoami))" \
$${CI+-e CI="$${CI}"} \ $${CI+-e CI="$${CI}"} \
$(INTERACTIVE) \ $(INTERACTIVE) \
$(DOCKER_IMAGE):$(DOCKER_TAG) \ $(DOCKER_IMAGE):$(DOCKER_TAG) \
bats $${BATS_TEST_FILTER:+--filter "$${BATS_TEST_FILTER}"} plugins/python-build/test/$${BATS_FILE_FILTER} bats $${BATS_TEST_FILTER:+--filter "$${BATS_TEST_FILTER}"} plugins/python-build/test/$${BATS_FILE_FILTER}
.PHONY: $(TEST_BINARY_DOCKER_PREFIX)
$(TEST_BINARY_DOCKER_PREFIX): $(TEST_BINARY_DOCKER_TARGETS)
.PHONY: $(TEST_BINARY_DOCKER_TARGETS)
$(TEST_BINARY_DOCKER_TARGETS): DOCKER_IMAGE = $(TEST_BATS_IMAGE_PREFIX)
$(TEST_BINARY_DOCKER_TARGETS): GNU = $(if $(findstring -gnu-,$@),True,False)
$(TEST_BINARY_DOCKER_TARGETS): BASH = $(filter $(TEST_BASH_VERSIONS),$(subst -, ,$@))
$(TEST_BINARY_DOCKER_TARGETS): DOCKER_TAG = bash-$(BASH)-gnu-$(GNU)
$(TEST_BINARY_DOCKER_TARGETS): INTERACTIVE = $(if $(findstring true,$(CI)),,-ti)
$(TEST_BINARY_DOCKER_TARGETS): $(TEST_BINARY_DOCKER_PREFIX)-% : $(TEST_BATS_IMAGE_PREFIX)-%
$(info Running test with docker image '$(DOCKER_IMAGE):$(DOCKER_TAG)')
docker run \
--init \
-v $(PWD):/code:ro \
-v /etc/passwd:/etc/passwd:ro \
-v /etc/group:/etc/group:ro \
-u "$$(id -u $$(whoami)):$$(id -g $$(whoami))" \
$${CI+-e CI="$${CI}"} \
$(INTERACTIVE) \
$(DOCKER_IMAGE):$(DOCKER_TAG) \
bats $${BATS_TEST_FILTER:+--filter "$${BATS_TEST_FILTER}"} plugins/pyenv-binary/test/$${BATS_FILE_FILTER}
# Build all images needed for bats under docker # Build all images needed for bats under docker
.PHONY: $(TEST_BATS_IMAGE_PREFIX) .PHONY: $(TEST_BATS_IMAGE_PREFIX)
$(TEST_BATS_IMAGE_PREFIX): $(TEST_BATS_IMAGE_TARGETS) $(TEST_BATS_IMAGE_PREFIX): $(TEST_BATS_IMAGE_TARGETS)
@ -71,7 +97,7 @@ $(TEST_BATS_IMAGE_TARGETS): GNU = $(if $(findstring -gnu-,$@),True,False)
$(TEST_BATS_IMAGE_TARGETS): BASH = $(filter $(TEST_BASH_VERSIONS),$(subst -, ,$@)) $(TEST_BATS_IMAGE_TARGETS): BASH = $(filter $(TEST_BASH_VERSIONS),$(subst -, ,$@))
$(TEST_BATS_IMAGE_TARGETS): DOCKER_TAG = bash-$(BASH)-gnu-$(GNU) $(TEST_BATS_IMAGE_TARGETS): DOCKER_TAG = bash-$(BASH)-gnu-$(GNU)
$(TEST_BATS_IMAGE_TARGETS): $(TEST_BATS_IMAGE_TARGETS):
$(info Building docker image '$(DOCKER_IMAGE):$(DOCKER_TAG)') if [ -z "$$(docker images -q '$(DOCKER_IMAGE):$(DOCKER_TAG)')" ]]; then \
docker build \ docker build \
--quiet \ --quiet \
-f "$(PWD)/test/Dockerfile" \ -f "$(PWD)/test/Dockerfile" \
@ -79,41 +105,32 @@ $(TEST_BATS_IMAGE_TARGETS):
--build-arg BASH="$(BASH)" \ --build-arg BASH="$(BASH)" \
--build-arg BATS_VERSION="$(TEST_BATS_VERSION)" \ --build-arg BATS_VERSION="$(TEST_BATS_VERSION)" \
-t $(DOCKER_IMAGE):$(DOCKER_TAG) \ -t $(DOCKER_IMAGE):$(DOCKER_TAG) \
./ ./ ; \
fi
.PHONY: test test-build test-unit test-plugin .PHONY: test test-unit test-python-build test-binary
# Do not pass in user flags to build tests. # Do not pass in user flags to build tests.
unexport PYTHON_CFLAGS unexport PYTHON_CFLAGS
unexport PYTHON_CONFIGURE_OPTS unexport PYTHON_CONFIGURE_OPTS
test: test-unit test-plugin test: test-unit test-python-build test-binary
test-unit: bats test-unit: bats
PATH="./bats/bin:$$PATH" test/run PATH="./bats/bin:$$PATH" test/run
test-plugin: bats test-python-build: bats
cd plugins/python-build && $(PWD)/bats/bin/bats $${CI:+--tap} $${BATS_TEST_FILTER:+--filter "$${BATS_TEST_FILTER}"} test/$${BATS_FILE_FILTER} cd plugins/python-build && $(PWD)/bats/bin/bats $${CI:+--tap} $${BATS_TEST_FILTER:+--filter "$${BATS_TEST_FILTER}"} test/$${BATS_FILE_FILTER}
PYTHON_BUILD_ROOT := $(CURDIR)/plugins/python-build test-binary: bats
PYTHON_BUILD_OPTS ?= --verbose cd plugins/pyenv-binary && $(PWD)/bats/bin/bats $${CI:+--tap} $${BATS_TEST_FILTER:+--filter "$${BATS_TEST_FILTER}"} test/$${BATS_FILE_FILTER}
PYTHON_BUILD_VERSION ?= 3.8-dev
PYTHON_BUILD_TEST_PREFIX ?= $(PYTHON_BUILD_ROOT)/test/build/tmp/dist
test-build:
$(RM) -r $(PYTHON_BUILD_TEST_PREFIX)
$(PYTHON_BUILD_ROOT)/bin/python-build $(PYTHON_BUILD_OPTS) $(PYTHON_BUILD_VERSION) $(PYTHON_BUILD_TEST_PREFIX)
[ -e $(PYTHON_BUILD_TEST_PREFIX)/bin/python ]
$(PYTHON_BUILD_TEST_PREFIX)/bin/python -V
[ -e $(PYTHON_BUILD_TEST_PREFIX)/bin/pip ]
$(PYTHON_BUILD_TEST_PREFIX)/bin/pip -V
.SECONDARY: bats-$(TEST_BATS_VERSION) .SECONDARY: bats-$(TEST_BATS_VERSION)
bats-$(TEST_BATS_VERSION): bats-$(TEST_BATS_VERSION):
rm -rf bats
ln -sf bats-$(TEST_BATS_VERSION) bats
git clone --depth 1 --branch $(TEST_BATS_VERSION) https://github.com/bats-core/bats-core.git bats-$(TEST_BATS_VERSION) git clone --depth 1 --branch $(TEST_BATS_VERSION) https://github.com/bats-core/bats-core.git bats-$(TEST_BATS_VERSION)
.PHONY: bats .PHONY: bats
bats: bats-$(TEST_BATS_VERSION) bats: bats-$(TEST_BATS_VERSION)
ln -sf bats-$(TEST_BATS_VERSION) bats if [ \( ! -L bats \) -o \( "x$$(readlink bats)" != "xbats-$(TEST_BATS_VERSION)" \) ]; then \
rm -rf bats; ln -s bats-$(TEST_BATS_VERSION) bats; \
fi

View File

@ -672,7 +672,7 @@ to `PATH` in the `<command>`'s environment, the same as what e.g. RVM does.
### Running nested shells from Python-based programs ### Running nested shells from Python-based programs
In addition to altering `PATH`, `pyenv exec` sets `PYENV_VERSION` in the In addition to altering `PATH`, `pyenv exec` sets `PYENV_VERSION` in the
executed program's environment to ensure that it won't spontaneouly switch to executed program's environment to ensure that it won't spontaneously switch to
using a different Python version. using a different Python version.
Some Python-based programs (e.g. Jupyter) can spawn nested shell sessions. Some Python-based programs (e.g. Jupyter) can spawn nested shell sessions.
@ -837,13 +837,10 @@ e.g. `~/.pyenv --install bash`.
## Development ## Development
The pyenv source code is [hosted on The pyenv source code is [hosted on
GitHub](https://github.com/pyenv/pyenv). It's clean, modular, GitHub](https://github.com/pyenv/pyenv).
and easy to understand, even if you're not a shell hacker.
Tests are executed using [Bats](https://github.com/bats-core/bats-core): Tests are executed using [Bats](https://github.com/bats-core/bats-core).
See the [tests README](test/README.md) for details.
bats test
bats/test/<file>.bats
### Contributing ### Contributing

View File

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

View File

@ -16,12 +16,60 @@ and dependency metadata exist to catch that.
## Commands ## Commands
### `pyenv binary save <version> [<output-dir>]` ### `pyenv binary package <version>:<entry> --archive-base-url <url>`
Installs `<version>` from source under the separate name `<entry>`, packages
that install with `save`, then emits a python-build definition for it with
`generate-installer`. The archive, metadata and definition land in the current
directory, named after the entry; host the archive under `<url>` and drop the
definition into python-build's definition directory. Keeping the entry name
distinct from the version lets the binary sit alongside a normal source
install of the same version.
```sh
pyenv binary package 3.12.7:3.12.7-debian-12 \
--archive-base-url https://example.com/binaries
# writes 3.12.7-debian-12.tar.gz, its .meta file and
# a `3.12.7-debian-12' definition
```
### `pyenv binary save <version> [<output-dir>] [--name <name>]`
Packs an installed version into `<version>-<platform>.tar.gz` (relative paths) Packs an installed version into `<version>-<platform>.tar.gz` (relative paths)
and writes `<version>-<platform>.meta` describing the build platform (OS, arch, and writes `<version>-<platform>.meta` describing the build platform (OS, arch,
distro and libc version) and the system libraries the build links against. distro and libc version) and the system libraries the build links against. Use
`--name` to set a different base name for both files.
```sh ```sh
pyenv binary save 3.12.7 ./dist pyenv binary save 3.12.7 ./dist
``` ```
### `pyenv binary generate-installer <metadata-file> --archive-url <url> [-o <output>]`
Reads a `.meta` file and emits a python-build definition. Drop it into
python-build's definition directory and `pyenv install <name>` installs the
archive like any other version. The archive location is a parameter, so you can
host it anywhere (it does not have to be a pyenv location); the archive itself
must sit next to the `.meta` file so its checksum can be baked into the
definition.
The definition refuses to install on a different OS/architecture, or an older
glibc, than the archive was built for, and checks that the system libraries it
needs are present.
```sh
pyenv binary generate-installer ./dist/3.12.7-linux-x86_64.meta \
--archive-url https://example.com/3.12.7-linux-x86_64.tar.gz \
-o "$(pyenv root)/plugins/python-build/share/python-build/3.12.7-linux-x86_64"
pyenv install 3.12.7-linux-x86_64
```
### `pyenv binary relocate <prefix>`
Rewrites the rpaths of a Python tree unpacked into `<prefix>` so the interpreter
and its extension modules load the bundled libraries from there rather than from
the path the archive was built at. Uses `patchelf`. The generated definition
calls this; you rarely run it by hand.
Relocation is implemented for Linux; macOS is not wired up yet.

View File

@ -16,6 +16,11 @@ set -e
libexec="${BASH_SOURCE%/*}/../libexec" 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}"
list_commands() { list_commands() {
local path local path
for path in "$libexec"/pyenv-binary-*; do for path in "$libexec"/pyenv-binary-*; do
@ -54,8 +59,7 @@ if [ ! -x "$command_path" ]; then
fi fi
if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
# `pyenv help' looks the command up on PATH; the subcommands live in libexec. exec pyenv-help "binary-${subcommand}"
PATH="${libexec}:${PATH}" exec pyenv-help "binary-${subcommand}"
fi fi
exec "$command_path" "$@" exec "$command_path" "$@"

View File

@ -0,0 +1,189 @@
#!/usr/bin/env bash
#
# Summary: Generate a python-build definition for a saved binary archive
#
# Usage: pyenv binary generate-installer <metadata-file> --archive-url <url> [-o <output>]
#
# Reads a metadata file written by `pyenv binary save' and emits a python-build
# definition. Dropped into python-build's definition directory, it installs the
# archive like any other version: `pyenv install' downloads it from <url>,
# checks the platform and the required system libraries, unpacks it, then
# rewrites rpaths so the copy runs from its prefix.
#
# The archive must sit next to the metadata file so its checksum can be baked
# into the definition; `pyenv binary save' writes the two together.
#
# <metadata-file> A .meta file written by `pyenv binary save'.
# The corresponsing binary package written by `pyenv binary save'
# needs to be present alongside it.
# --archive-url <url> The URL for the resulting installation script to download
# the package from.
# -o <output> Write the definition here (default: stdout).
#
set -e
[ -n "$PYENV_DEBUG" ] && set -x
# Provide pyenv completions
if [ "$1" = "--complete" ]; then
echo --archive-url
echo -o
exit
fi
metadata=""
archive_url=""
output=""
while [ $# -gt 0 ]; do
case "$1" in
--archive-url )
[ $# -ge 2 ] || { echo "pyenv-binary: --archive-url needs a value" >&2; exit 1; }
archive_url="$2"; shift 2 ;;
-o )
[ $# -ge 2 ] || { echo "pyenv-binary: -o needs a value" >&2; exit 1; }
output="$2"; shift 2 ;;
-* )
echo "pyenv-binary: unknown option \`$1'" >&2; exit 1 ;;
* )
[ -z "$metadata" ] || { echo "pyenv-binary: unexpected argument \`$1'" >&2; exit 1; }
metadata="$1"; shift ;;
esac
done
if [ -z "$metadata" ] || [ -z "$archive_url" ]; then
pyenv-help --usage binary-generate-installer >&2
exit 1
fi
version="" os="" arch="" distro="" libc="" archive=""
deps=""
while IFS='=' read -r key value; do
case "$key" in
version ) version="$value" ;;
os ) os="$value" ;;
arch ) arch="$value" ;;
distro ) distro="$value" ;;
libc ) libc="$value" ;;
archive ) archive="$value" ;;
dep ) deps="${deps:+$deps }$value" ;;
esac
done < "$metadata"
# Fail here if the metadata is incomplete, rather than bake a blank into the
# definition where a missing arch would give a confusing platform error.
for field in version os arch archive; do
if [ -z "${!field}" ]; then
echo "pyenv-binary: metadata is missing \`${field}'" >&2
exit 1
fi
done
# macOS relocation needs install_name_tool and a different rpath scheme, so it is
# not supported yet. Other systems relocate with patchelf.
if [ "$os" = "Darwin" ]; then
echo "pyenv-binary: macOS archives are not supported yet" >&2
exit 1
fi
# The glibc floor only applies on Linux; require it there so the definition can
# tell whether the target is new enough to run the binaries.
if [ "$os" = "Linux" ] && [ -z "$libc" ]; then
echo "pyenv-binary: metadata is missing \`libc'" >&2
exit 1
fi
# python-build downloads the archive itself, so the checksum has to be baked in.
# The archive sits next to the metadata `save' wrote it alongside.
archive_path="$(dirname "$metadata")/${archive}"
if [ ! -r "$archive_path" ]; then
echo "pyenv-binary: cannot read the archive \`${archive_path}' to checksum it" >&2
exit 1
fi
if command -v sha256sum >/dev/null 2>&1; then
sha256="$(sha256sum "$archive_path")"; sha256="${sha256%% *}"
elif command -v shasum >/dev/null 2>&1; then
sha256="$(shasum -a 256 "$archive_path")"; sha256="${sha256%% *}"
elif command -v openssl >/dev/null 2>&1; then
sha256="$(openssl dgst -sha256 "$archive_path")"; sha256="${sha256##* }"
else
echo "pyenv-binary: need sha256sum, shasum or openssl to checksum the archive" >&2
exit 1
fi
emit() {
# The values known now go in as %q-quoted assignments so a stray quote or space
# in the URL or metadata cannot break the definition or inject into it. The body
# below is a quoted here-doc, verbatim.
{
printf '# python-build definition for prebuilt Python %s (%s/%s%s).\n' \
"$version" "$os" "$arch" "${distro:+, $distro}"
echo "# Generated by \`pyenv binary generate-installer'."
echo
printf 'EXPECT_OS=%q\n' "$os"
printf 'EXPECT_ARCH=%q\n' "$arch"
printf 'EXPECT_LIBC=%q\n' "$libc"
printf 'VERSION=%q\n' "$version"
printf 'ARCHIVE_URL=%q\n' "$archive_url"
printf 'SHA256=%q\n' "$sha256"
printf 'DEPS=%q\n' "$deps"
}
cat <<'EOF'
os="$(uname -s)"
arch="$(uname -m)"
if [ "$os" != "$EXPECT_OS" ] || [ "$arch" != "$EXPECT_ARCH" ]; then
echo "pyenv-binary: this archive is for ${EXPECT_OS}/${EXPECT_ARCH}, not ${os}/${arch}" >&2
exit 1
fi
# Refuse a target whose glibc is older than the one the archive was built on;
# the dynamic loader would reject the binaries.
case "$EXPECT_LIBC" in
"glibc "* )
build_libc="${EXPECT_LIBC#glibc }"
target_libc="$(getconf GNU_LIBC_VERSION 2>/dev/null || true)"
case "$target_libc" in
"glibc "* )
target_libc="${target_libc#glibc }"
older="$(printf '%s\n%s\n' "$build_libc" "$target_libc" | sort -V | head -n1)"
if [ "$older" = "$target_libc" ] && [ "$target_libc" != "$build_libc" ]; then
echo "pyenv-binary: archive needs glibc ${build_libc} or newer, but this system has ${target_libc}" >&2
exit 1
fi
;;
esac
;;
esac
# Required system libraries must already be present on the target. ldconfig -p
# lists each library as "<soname> (...) => <path>"; match the soname column
# exactly so a longer name like libc.so.6.1 does not satisfy libc.so.6.
if command -v ldconfig &>/dev/null && cache="$(ldconfig -p)"; then
missing=""
for dep in $DEPS; do
printf '%s\n' "$cache" | awk -v d="$dep" '$1 == d { found = 1 } END { exit !found }' \
|| missing="${missing} ${dep}"
done
if [ -n "$missing" ]; then
echo "pyenv-binary: missing required system libraries:${missing}" >&2
exit 1
fi
elif [ -n "$DEPS" ]; then
echo "pyenv-binary: cannot check required system libraries (ldconfig with -p not found)" >&2
fi
build_package_relocate() {
pyenv binary relocate "$PREFIX_PATH"
}
install_package "Python-${VERSION}-binary" "${ARCHIVE_URL}#${SHA256}" copy relocate
EOF
}
if [ -n "$output" ]; then
emit > "$output"
echo "Wrote definition to ${output}"
else
emit
fi

View File

@ -0,0 +1,90 @@
#!/usr/bin/env bash
#
# Summary: Create an installable binary package from a Python version
#
# Usage: pyenv binary package <version>:<entry> --archive-base-url <url>
#
# Installs <version> from source under the separate name <entry>, saves it as
# a binary package, then emits a python-build definition for that package.
# The archive, metadata and definition are written to the current directory
# as <entry>.tar.gz, <entry>.meta and <entry>.
#
# <version> A version `pyenv install' knows how to build.
# <entry> The name to build under and to install the binary
# as, e.g. `3.13.14-debian-12'. Keeping it distinct
# from <version> lets the binary sit alongside a
# normal source install of the same version.
# --archive-base-url <url>
# Where the archive will be hosted; the definition
# downloads it from <url>/<entry>.tar.gz.
#
set -e
[ -n "$PYENV_DEBUG" ] && set -x
# Provide pyenv completions
if [ "$1" = "--complete" ]; then
echo --archive-base-url
exec pyenv-install --list --bare
fi
spec=""
archive_base_url=""
while [ $# -gt 0 ]; do
case "$1" in
--archive-base-url )
[ $# -ge 2 ] || { echo "pyenv-binary: --archive-base-url needs a value" >&2; exit 1; }
archive_base_url="$2"; shift 2 ;;
-* )
echo "pyenv-binary: unknown option \`$1'" >&2; exit 1 ;;
* )
[ -z "$spec" ] || { echo "pyenv-binary: unexpected argument \`$1'" >&2; exit 1; }
spec="$1"; shift ;;
esac
done
if [ -z "$spec" ] || [ -z "$archive_base_url" ]; then
pyenv-help --usage binary-package >&2
exit 1
fi
case "$spec" in
*?:?* ) ;;
* )
echo "pyenv-binary: expected <version>:<entry>, e.g. \`3.13.14:3.13.14-debian-12'" >&2
exit 1
;;
esac
entry="${spec##*:}"
case "$entry" in
# `pyenv install' reads a trailing `:latest' as part of the version rather than
# as an alias, so nothing would end up installed under that name.
latest )
echo "pyenv-binary: \`latest' cannot be used as an entry name" >&2
exit 1
;;
# The entry becomes a directory name under versions/. `pyenv install' does not
# validate the alias, and `save' only checks once the build is done, so refuse
# a name that could point elsewhere before compiling anything.
*/* | .. | . )
echo "pyenv-binary: invalid entry name \`${entry}'" >&2
exit 1
;;
esac
os="$(uname -s)"
# `generate-installer' refuses a macOS archive, so the last step here cannot
# succeed on one. Give up before compiling rather than after it.
if [ "$os" = "Darwin" ]; then
echo "pyenv-binary: macOS archives are not supported yet" >&2
exit 1
fi
# `pyenv install' puts a `<version>:<alias>' build under versions/<alias>.
pyenv-install "$spec"
pyenv-binary-save "$entry" "$PWD" --name "$entry"
pyenv-binary-generate-installer "${entry}.meta" \
--archive-url "${archive_base_url%/}/${entry}.tar.gz" -o "$entry"

View File

@ -0,0 +1,58 @@
#!/usr/bin/env bash
#
# Summary: Rewrite an unpacked Python's rpaths so it runs from its prefix
#
# Usage: pyenv binary relocate <prefix>
#
# Rewrites the rpaths of a Python tree that was unpacked into <prefix> so the
# interpreter and its extension modules load the bundled libraries from their
# new location rather than the path it was built at. Requires patchelf.
#
# The definition that `pyenv binary generate-installer' produces calls this
# after `install_package ... copy' has laid the tree down.
#
set -e
[ -n "$PYENV_DEBUG" ] && set -x
if [ "$1" = "--complete" ]; then
exit
fi
prefix="$1"
if [ -z "$prefix" ]; then
pyenv-help --usage binary-relocate >&2
exit 1
fi
# patchelf can add an rpath and write one of any length; chrpath can only shorten
# an existing one, which is not enough to relocate every build, so require it.
if ! command -v patchelf >/dev/null 2>&1; then
echo "pyenv-binary: need patchelf to relocate the binary" >&2
exit 1
fi
# The interpreter loads libpython from ../lib. Patch every ELF binary in bin/ so
# this holds whatever the interpreter is named (python3, python2.7, ...); the
# scripts alongside it (pip, idle) are not ELF, so `--print-rpath' fails on them
# and they are skipped. A tree with no interpreter at all did not unpack the way
# we expect, so treat that as an error rather than quietly relocating nothing.
found=0
for file in "$prefix"/bin/*; do
[[ -f $file && -x $file && ! -L $file ]] || continue
patchelf --print-rpath "$file" >/dev/null 2>&1 || continue
patchelf --set-rpath "$prefix/lib" "$file"
found=1
done
if [ "$found" -eq 0 ]; then
echo "pyenv-binary: found no interpreter to relocate under \`${prefix}/bin'" >&2
exit 1
fi
# The extension modules CPython built are the only other objects with an rpath
# into the old prefix, so point them at lib/ as well. Anything a wheel installed
# carries an rpath of its own, often into a bundled library directory beside it,
# and would stop loading if we overwrote it. Each match is an ELF object we expect
# to patch, so let a failure stop us rather than swallow it.
while IFS= read -r so; do
patchelf --set-rpath "$prefix/lib" "$so"
done < <(find "$prefix" -path '*/lib-dynload/*.so')

View File

@ -2,7 +2,7 @@
# #
# Summary: Save an installed Python version as a relocatable archive # Summary: Save an installed Python version as a relocatable archive
# #
# Usage: pyenv binary save <version> [<output-dir>] # Usage: pyenv binary save <version> [<output-dir>] [--name <name>]
# #
# Packs an installed version into a relocatable .tar.gz (relative paths) and # Packs an installed version into a relocatable .tar.gz (relative paths) and
# writes a metadata file listing the build platform and the system libraries # writes a metadata file listing the build platform and the system libraries
@ -10,20 +10,46 @@
# #
# <version> An installed version, as listed by `pyenv versions --bare'. # <version> An installed version, as listed by `pyenv versions --bare'.
# <output-dir> Where to write the archive and metadata (default: `.'). # <output-dir> Where to write the archive and metadata (default: `.').
# --name <name> Use <name> as the archive and metadata base name instead of
# <version>-<platform>.
# #
set -e set -e
[ -n "$PYENV_DEBUG" ] && set -x [ -n "$PYENV_DEBUG" ] && set -x
# Provide pyenv completions # Provide pyenv completions
if [ "$1" = "--complete" ]; then if [ "$1" = "--complete" ]; then
echo --name
exec pyenv-versions --bare exec pyenv-versions --bare
fi fi
version="$1" version=""
output_dir="${2:-$PWD}" output_dir=""
package_name=""
while [ $# -gt 0 ]; do
case "$1" in
--name )
[ $# -ge 2 ] && [ -n "$2" ] || { echo "pyenv-binary: --name needs a value" >&2; exit 1; }
package_name="$2"; shift 2 ;;
-* )
echo "pyenv-binary: unknown option \`$1'" >&2; exit 1 ;;
* )
if [ -z "$version" ]; then
version="$1"
elif [ -z "$output_dir" ]; then
output_dir="$1"
else
echo "pyenv-binary: unexpected argument \`$1'" >&2
exit 1
fi
shift ;;
esac
done
output_dir="${output_dir:-$PWD}"
if [ -z "$version" ]; then if [ -z "$version" ]; then
echo "Usage: pyenv binary save <version> [<output-dir>]" >&2 echo "Usage: pyenv binary save <version> [<output-dir>] [--name <name>]" >&2
exit 1 exit 1
fi fi
@ -36,6 +62,13 @@ case "$version" in
;; ;;
esac esac
case "$package_name" in
*/* | .. | . | *[[:cntrl:]]* )
echo "pyenv-binary: invalid package name \`${package_name}'" >&2
exit 1
;;
esac
prefix="${PYENV_ROOT}/versions/${version}" prefix="${PYENV_ROOT}/versions/${version}"
if [ ! -d "${prefix}/bin" ]; then if [ ! -d "${prefix}/bin" ]; then
echo "pyenv-binary: version \`${version}' is not installed" >&2 echo "pyenv-binary: version \`${version}' is not installed" >&2
@ -85,10 +118,11 @@ system_deps() {
} }
mkdir -p "$output_dir" mkdir -p "$output_dir"
archive="${version}-${platform}.tar.gz" package_name="${package_name:-${version}-${platform}}"
metadata="${version}-${platform}.meta" archive="${package_name}.tar.gz"
metadata="${package_name}.meta"
tar -C "$prefix" -czf "${output_dir}/${archive}" . tar -C "$(dirname "$prefix")" -czf "${output_dir}/${archive}" "$(basename "$prefix")"
{ {
echo "# pyenv-binary metadata" echo "# pyenv-binary metadata"

View File

@ -0,0 +1,123 @@
#!/usr/bin/env bats
load test_helper
create_meta() {
local os="${1-Linux}"
local arch="${2-x86_64}"
local libc="${3-glibc 2.17}"
local archive="${BATS_TEST_TMPDIR}/3.12.7.tar.gz"
local meta="${BATS_TEST_TMPDIR}/sample.meta"
rm -rf "${BATS_TEST_TMPDIR}/archive"
mkdir -p "${BATS_TEST_TMPDIR}/archive/3.12.7/bin"
printf '#!/bin/sh\n' > "${BATS_TEST_TMPDIR}/archive/3.12.7/bin/python"
chmod +x "${BATS_TEST_TMPDIR}/archive/3.12.7/bin/python"
tar -C "${BATS_TEST_TMPDIR}/archive" -czf "$archive" 3.12.7
{
echo "version=3.12.7"
echo "os=${os}"
echo "arch=${arch}"
[ -z "$libc" ] || echo "libc=${libc}"
echo "archive=${archive##*/}"
} > "$meta"
echo "$meta"
}
@test "completion lists the options" {
run pyenv-binary-generate-installer --complete
assert_success "--archive-url
-o"
}
@test "fails with no arguments" {
create_stub pyenv-help "echo usage"
run pyenv-binary-generate-installer
assert_failure "usage"
}
@test "fails without an archive url" {
create_stub pyenv-help "echo usage"
run pyenv-binary-generate-installer "$(create_meta)"
assert_failure "usage"
}
@test "fails when --archive-url has no value" {
run pyenv-binary-generate-installer "$(create_meta)" --archive-url
assert_failure "pyenv-binary: --archive-url needs a value"
}
@test "rejects a second positional argument" {
run pyenv-binary-generate-installer "$(create_meta)" extra --archive-url http://x/a.tar.gz
assert_failure "pyenv-binary: unexpected argument \`extra'"
}
@test "fails for a metadata file that cannot be read" {
run pyenv-binary-generate-installer /no/such.meta --archive-url http://x/a.tar.gz
assert_failure
}
@test "refuses macOS metadata" {
run pyenv-binary-generate-installer "$(create_meta Darwin arm64 '')" \
--archive-url http://x/a.tar.gz
assert_failure "pyenv-binary: macOS archives are not supported yet"
}
@test "fails when required metadata is missing" {
local field meta
for field in version os arch archive; do
meta="$(create_meta)"
#cannot use -i: GNU sed requires -i[suf], BSD sed required -i <suf>
sed "/^${field}=/d" "$meta" > "${meta}.tmp"; mv "${meta}"{.tmp,}
run pyenv-binary-generate-installer "$meta" --archive-url http://x/a.tar.gz
assert_failure "pyenv-binary: metadata is missing \`${field}'"
done
}
@test "fails when Linux metadata is missing libc" {
run pyenv-binary-generate-installer "$(create_meta Linux x86_64 '')" \
--archive-url http://x/a.tar.gz
assert_failure "pyenv-binary: metadata is missing \`libc'"
}
@test "refuses a host whose glibc is older than the archive" {
local out="${BATS_TEST_TMPDIR}/definition"
pyenv-binary-generate-installer "$(create_meta Linux x86_64 'glibc 99.0')" \
--archive-url http://example.com/a.tar.gz -o "$out"
create_stub uname 'case "$1" in -s) echo Linux;; -m) echo x86_64;; esac'
create_stub getconf 'echo "glibc 2.31"'
run bash "$out"
assert_failure "pyenv-binary: archive needs glibc 99.0 or newer, but this system has 2.31"
}
@test "fails when the archive is not beside the metadata" {
local meta="$(create_meta)"
rm "${BATS_TEST_TMPDIR}/3.12.7.tar.gz"
run pyenv-binary-generate-installer "$meta" --archive-url http://x/a.tar.gz
assert_failure "pyenv-binary: cannot read the archive \`${BATS_TEST_TMPDIR}/3.12.7.tar.gz' to checksum it"
}
@test "the generated definition is installable with python-build" {
ldconfig -p &>/dev/null || skip "ldconfig with -p is not present"
local archive="${BATS_TEST_TMPDIR}/3.12.7.tar.gz"
local cache="${BATS_TEST_TMPDIR}/cache"
local definition="${BATS_TEST_TMPDIR}/definition"
local prefix="${BATS_TEST_TMPDIR}/install"
pyenv-binary-generate-installer "$(create_meta)" \
--archive-url http://example.com/3.12.7.tar.gz -o "$definition"
mkdir -p "$cache"
cp "$archive" "${cache}/Python-3.12.7-binary.tar.gz"
create_stub pyenv 'echo "pyenv $*"'
create_stub uname 'case "$1" in -s) echo Linux;; -m) echo x86_64;; esac'
PYTHON_BUILD_CACHE_PATH="$cache" run \
"${BATS_TEST_DIRNAME}/../../python-build/bin/python-build" "$definition" "$prefix"
assert_success
assert_line "pyenv binary relocate ${prefix}"
assert_line "Installed Python-3.12.7-binary to ${prefix}"
assert [ -x "${prefix}/bin/python" ]
}

View File

@ -0,0 +1,92 @@
#!/usr/bin/env bats
load test_helper
# Make the build deterministic: `pyenv-install' just creates the prefix, and
# the platform tools report a fixed Linux target so the real `save' and
# `generate-installer' behave the same on any test host.
stub_build_environment() {
create_stub pyenv-install 'mkdir -p "${PYENV_ROOT}/versions/${1##*:}/bin"'
create_stub uname 'case "$1" in -s) echo Linux;; -m) echo x86_64;; esac'
create_stub getconf 'echo "glibc 2.17"'
}
@test "completion lists the option and definitions provided by another plugin" {
mkdir -p "${PYENV_ROOT}/plugins/example/share/python-build"
touch "${PYENV_ROOT}/plugins/example/share/python-build/3.12.7-example"
PATH="${BATS_TEST_DIRNAME}/../../python-build/bin:${PATH}"
run pyenv-binary-package --complete
assert_success
assert_line "--archive-base-url"
assert_line "3.12.7-example"
refute_line "Available versions:"
}
@test "fails with no arguments" {
create_stub pyenv-help "echo usage"
run pyenv-binary-package
assert_failure "usage"
}
@test "fails without an archive base url" {
create_stub pyenv-help "echo usage"
run pyenv-binary-package 3.12.7:3.12.7-test
assert_failure "usage"
}
@test "fails when --archive-base-url has no value" {
run pyenv-binary-package 3.12.7:3.12.7-test --archive-base-url
assert_failure "pyenv-binary: --archive-base-url needs a value"
}
@test "rejects a second positional argument" {
run pyenv-binary-package 3.12.7:3.12.7-test extra --archive-base-url http://x/b
assert_failure "pyenv-binary: unexpected argument \`extra'"
}
@test "rejects a bare version without an entry name" {
run pyenv-binary-package 3.12.7 --archive-base-url http://x/b
assert_failure "pyenv-binary: expected <version>:<entry>, e.g. \`3.13.14:3.13.14-debian-12'"
}
@test "rejects an entry name containing a slash" {
run pyenv-binary-package "3.12.7:foo/bar" --archive-base-url http://x/b
assert_failure "pyenv-binary: invalid entry name \`foo/bar'"
}
@test "rejects \`latest' as an entry name" {
run pyenv-binary-package 3.12:latest --archive-base-url http://x/b
assert_failure "pyenv-binary: \`latest' cannot be used as an entry name"
}
@test "refuses to package on macOS before compiling anything" {
create_stub uname 'case "$1" in -s) echo Darwin;; -m) echo arm64;; esac'
run pyenv-binary-package 3.12.7:3.12.7-test --archive-base-url http://x/b
assert_failure "pyenv-binary: macOS archives are not supported yet"
}
@test "writes the archive, metadata and definition under the entry name" {
stub_build_environment
cd "${BATS_TEST_TMPDIR}"
run pyenv-binary-package 3.12.7:3.12.7-test \
--archive-base-url http://example.com/binaries
assert_success
assert [ -d "${PYENV_ROOT}/versions/3.12.7-test" ]
assert [ -f "${BATS_TEST_TMPDIR}/3.12.7-test.tar.gz" ]
assert [ -f "${BATS_TEST_TMPDIR}/3.12.7-test.meta" ]
run grep '^ARCHIVE_URL=' "${BATS_TEST_TMPDIR}/3.12.7-test"
assert_success "ARCHIVE_URL=http://example.com/binaries/3.12.7-test.tar.gz"
}
@test "strips a trailing slash from the archive base url" {
stub_build_environment
cd "${BATS_TEST_TMPDIR}"
run pyenv-binary-package 3.12.7:3.12.7-test \
--archive-base-url http://example.com/binaries/
assert_success
run grep '^ARCHIVE_URL=' "${BATS_TEST_TMPDIR}/3.12.7-test"
assert_success "ARCHIVE_URL=http://example.com/binaries/3.12.7-test.tar.gz"
}

View File

@ -0,0 +1,72 @@
#!/usr/bin/env bats
load test_helper
_setup() {
create_stub pyenv-help "echo usage"
}
stub_patchelf() {
create_path_executable patchelf <<STUB
if [ "\$1" = "--print-rpath" ]; then
exit 0
fi
echo "\$*" >> "${BATS_TEST_TMPDIR}/patchelf.log"
STUB
}
create_interpreter() {
mkdir -p "${BATS_TEST_TMPDIR}/prefix/bin"
printf '#!/bin/sh\n' > "${BATS_TEST_TMPDIR}/prefix/bin/python2.7"
chmod +x "${BATS_TEST_TMPDIR}/prefix/bin/python2.7"
}
@test "completion produces nothing" {
run pyenv-binary-relocate --complete
assert_success ""
}
@test "fails without a prefix" {
run pyenv-binary-relocate
assert_failure "usage"
}
@test "fails when patchelf is not available" {
PATH="$(path_without patchelf)" run pyenv-binary-relocate "${BATS_TEST_TMPDIR}/prefix"
assert_failure "pyenv-binary: need patchelf to relocate the binary"
}
@test "fails when the prefix has no interpreter" {
create_path_executable patchelf "exit 0"
mkdir -p "${BATS_TEST_TMPDIR}/prefix"
run pyenv-binary-relocate "${BATS_TEST_TMPDIR}/prefix"
assert_failure "pyenv-binary: found no interpreter to relocate under \`${BATS_TEST_TMPDIR}/prefix/bin'"
}
@test "relocates an executable interpreter" {
stub_patchelf
create_interpreter
run pyenv-binary-relocate "${BATS_TEST_TMPDIR}/prefix"
assert_success
run cat "${BATS_TEST_TMPDIR}/patchelf.log"
assert_output "--set-rpath ${BATS_TEST_TMPDIR}/prefix/lib ${BATS_TEST_TMPDIR}/prefix/bin/python2.7"
}
@test "relocates the extension modules but not what a wheel installed" {
local lib="${BATS_TEST_TMPDIR}/prefix/lib/python3.12"
stub_patchelf
create_interpreter
mkdir -p "${lib}/lib-dynload" "${lib}/site-packages/numpy"
touch "${lib}/lib-dynload/_ssl.cpython-312-x86_64-linux-gnu.so"
# A wheel points its extensions at the libraries it bundles alongside them, so
# its rpath is its own business and must survive relocation.
touch "${lib}/site-packages/numpy/_multiarray.so"
run pyenv-binary-relocate "${BATS_TEST_TMPDIR}/prefix"
assert_success
run cat "${BATS_TEST_TMPDIR}/patchelf.log"
assert_line "--set-rpath ${BATS_TEST_TMPDIR}/prefix/lib ${lib}/lib-dynload/_ssl.cpython-312-x86_64-linux-gnu.so"
refute_line "--set-rpath ${BATS_TEST_TMPDIR}/prefix/lib ${lib}/site-packages/numpy/_multiarray.so"
}

View File

@ -12,7 +12,7 @@ platform() {
@test "fails with no version given" { @test "fails with no version given" {
run pyenv-binary-save run pyenv-binary-save
assert_failure "Usage: pyenv binary save <version> [<output-dir>]" assert_failure "Usage: pyenv binary save <version> [<output-dir>] [--name <name>]"
} }
@test "fails for a version that is not installed" { @test "fails for a version that is not installed" {
@ -33,40 +33,62 @@ platform() {
@test "packages an installed version" { @test "packages an installed version" {
create_version "3.12.7" create_version "3.12.7"
local out="${BATS_TEST_TMPDIR}/dist" local out="${BATS_TEST_TMPDIR}/dist"
local archive="${out}/3.12.7-$(platform).tar.gz"
run pyenv-binary-save "3.12.7" "$out" 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_success "Saved 3.12.7-$(platform).tar.gz and 3.12.7-$(platform).meta to $out"
assert [ -f "${out}/3.12.7-$(platform).tar.gz" ] assert [ -f "$archive" ]
assert [ -f "${out}/3.12.7-$(platform).meta" ] assert [ -f "${out}/3.12.7-$(platform).meta" ]
run tar -tzf "$archive"
assert_success
assert_line 0 "3.12.7/"
}
@test "uses an explicit package name" {
create_version "3.12.7"
local out="${BATS_TEST_TMPDIR}/dist"
run pyenv-binary-save "3.12.7" "$out" --name "custom"
assert_success "Saved custom.tar.gz and custom.meta to $out"
assert [ -f "${out}/custom.tar.gz" ]
run grep '^archive=' "${out}/custom.meta"
assert_success "archive=custom.tar.gz"
}
@test "fails when --name has no value" {
run pyenv-binary-save "3.12.7" --name
assert_failure "pyenv-binary: --name needs a value"
}
@test "rejects an invalid package name" {
create_version "3.12.7"
run pyenv-binary-save "3.12.7" --name "foo/bar"
assert_failure "pyenv-binary: invalid package name \`foo/bar'"
} }
@test "records the platform in the metadata" { @test "records the platform in the metadata" {
create_version "3.12.7" create_version "3.12.7"
local out="${BATS_TEST_TMPDIR}/dist" local out="${BATS_TEST_TMPDIR}/dist"
pyenv-binary-save "3.12.7" "$out" >/dev/null pyenv-binary-save "3.12.7" "$out" >/dev/null
run cat "${out}/3.12.7-$(platform).meta" run cat "${out}/3.12.7-$(platform).meta"
assert_success assert_success
assert_output_contains "version=3.12.7" assert_line "version=3.12.7"
assert_output_contains "platform=$(platform)" assert_line "platform=$(platform)"
assert_output_contains "archive=3.12.7-$(platform).tar.gz" assert_line "archive=3.12.7-$(platform).tar.gz"
}
# Put an executable on PATH that stands in for a system tool during the test.
stub() {
local name="$1"
local dir="${BATS_TEST_TMPDIR}/stubs"
mkdir -p "$dir"
{ echo "#!/usr/bin/env bash"; cat -; } > "${dir}/${name}"
chmod +x "${dir}/${name}"
export PATH="${dir}:$PATH"
} }
@test "records only the libraries ldd resolves outside the prefix" { @test "records only the libraries ldd resolves outside the prefix" {
create_version "3.12.7" create_version "3.12.7"
touch "${PYENV_ROOT}/versions/3.12.7/bin/python3.12" touch "${PYENV_ROOT}/versions/3.12.7/bin/python3.12"
create_path_executable uname <<'STUB'
# A realistic ldd listing: the vdso and the loader have no `=>' mapping, case "$1" in
# libpython resolves inside the prefix, and libc/libm are external. -s) echo Linux ;;
stub ldd <<'STUB' -m) echo x86_64 ;;
esac
STUB
create_path_executable ldd <<'STUB'
prefix="${PYENV_ROOT}/versions/3.12.7" prefix="${PYENV_ROOT}/versions/3.12.7"
cat <<EOF cat <<EOF
linux-vdso.so.1 (0x00007ffd1adfe000) linux-vdso.so.1 (0x00007ffd1adfe000)
@ -79,7 +101,6 @@ STUB
run pyenv-binary-save "3.12.7" "${BATS_TEST_TMPDIR}/dist" run pyenv-binary-save "3.12.7" "${BATS_TEST_TMPDIR}/dist"
assert_success assert_success
run grep '^dep=' "${BATS_TEST_TMPDIR}/dist/"*.meta run grep '^dep=' "${BATS_TEST_TMPDIR}/dist/"*.meta
assert_output "dep=libc.so.6 assert_output "dep=libc.so.6
dep=libm.so.6" dep=libm.so.6"
@ -88,18 +109,13 @@ dep=libm.so.6"
@test "records only the libraries otool resolves outside the prefix" { @test "records only the libraries otool resolves outside the prefix" {
create_version "3.12.7" create_version "3.12.7"
touch "${PYENV_ROOT}/versions/3.12.7/bin/python3.12" touch "${PYENV_ROOT}/versions/3.12.7/bin/python3.12"
create_path_executable uname <<'STUB'
# Take the macOS path by faking the platform, then feed a realistic otool
# listing: the first line names the file, @rpath and in-prefix entries are
# bundled, and libSystem is the one external dependency.
stub uname <<'STUB'
case "$1" in case "$1" in
-s) echo Darwin ;; -s) echo Darwin ;;
-m) echo arm64 ;; -m) echo arm64 ;;
*) exec /usr/bin/uname "$@" ;;
esac esac
STUB STUB
stub otool <<'STUB' create_path_executable otool <<'STUB'
prefix="${PYENV_ROOT}/versions/3.12.7" prefix="${PYENV_ROOT}/versions/3.12.7"
cat <<EOF cat <<EOF
${2}: ${2}:
@ -111,7 +127,6 @@ STUB
run pyenv-binary-save "3.12.7" "${BATS_TEST_TMPDIR}/dist" run pyenv-binary-save "3.12.7" "${BATS_TEST_TMPDIR}/dist"
assert_success assert_success
run grep '^dep=' "${BATS_TEST_TMPDIR}/dist/"*.meta run grep '^dep=' "${BATS_TEST_TMPDIR}/dist/"*.meta
assert_output "dep=/usr/lib/libSystem.B.dylib" assert_output "dep=/usr/lib/libSystem.B.dylib"
} }

View File

@ -1,68 +0,0 @@
setup() {
export PYENV_ROOT="${BATS_TEST_TMPDIR}/root"
PATH="/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin"
PATH="${BATS_TEST_DIRNAME}/../libexec:$PATH"
export PATH
# If test specific setup exist, run it
if [[ $(type -t _setup) == function ]]; then
_setup
fi
}
flunk() {
{ if [ "$#" -eq 0 ]; then cat -
else echo "$@"
fi
} | sed "s:${BATS_TEST_TMPDIR}:\${BATS_TEST_TMPDIR}:g" >&2
return 1
}
assert() {
if ! "$@"; then
flunk "failed: $@"
fi
}
assert_success() {
if [ "$status" -ne 0 ]; then
{ echo "command failed with exit status $status"
echo "output: $output"
} | flunk
elif [ "$#" -gt 0 ]; then
assert_output "$1"
fi
}
assert_failure() {
if [ "$status" -eq 0 ]; then
flunk "expected failed exit status"
elif [ "$#" -gt 0 ]; then
assert_output "$1"
fi
}
assert_equal() {
if [ "$1" != "$2" ]; then
{ echo "expected: $1"
echo "actual: $2"
} | flunk
fi
}
assert_output() {
local expected
if [ $# -eq 0 ]; then expected="$(cat -)"
else expected="$1"
fi
assert_equal "$expected" "$output"
}
assert_output_contains() {
local expected="$1"
echo "$output" | grep -F "$expected" >/dev/null || {
{ echo "expected output to contain: $expected"
echo "actual: $output"
} | flunk
}
}

View File

@ -0,0 +1 @@
../../../test/test_helper.bash

View File

@ -4,7 +4,7 @@
# #
# Usage: pyenv install [-f] [-kvp] <version>[:<alias>]... # Usage: pyenv install [-f] [-kvp] <version>[:<alias>]...
# pyenv install [-f] [-kvp] <definition-file>[:<alias>] # pyenv install [-f] [-kvp] <definition-file>[:<alias>]
# pyenv install -l|--list # pyenv install -l|--list [--bare]
# pyenv install --version # pyenv install --version
# #
# -l/--list List all available versions # -l/--list List all available versions
@ -45,6 +45,7 @@ shopt -u nullglob
# Provide pyenv completions # Provide pyenv completions
if [ "$1" = "--complete" ]; then if [ "$1" = "--complete" ]; then
echo --bare
echo --list echo --list
echo --force echo --force
echo --skip-existing echo --skip-existing
@ -79,6 +80,8 @@ unset KEEP
unset VERBOSE unset VERBOSE
unset HAS_PATCH unset HAS_PATCH
unset DEBUG unset DEBUG
unset BARE
unset LIST
[ -n "$PYENV_DEBUG" ] && VERBOSE="-v" [ -n "$PYENV_DEBUG" ] && VERBOSE="-v"
@ -88,10 +91,11 @@ for option in "${OPTIONS[@]}"; do
"h" | "help" ) "h" | "help" )
usage 0 usage 0
;; ;;
"bare" )
BARE=1
;;
"l" | "list" ) "l" | "list" )
echo "Available versions:" LIST=1
definitions | indent
exit
;; ;;
"f" | "force" ) "f" | "force" )
FORCE=true FORCE=true
@ -120,6 +124,16 @@ for option in "${OPTIONS[@]}"; do
esac esac
done done
if [[ -n $LIST ]]; then
if [[ -n $BARE ]]; then
definitions
else
echo "Available versions:"
definitions | indent
fi
exit
fi
unset VERSION_NAME unset VERSION_NAME
# The first argument contains the definition to install. If the # The first argument contains the definition to install. If the

View File

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

View File

@ -5,7 +5,7 @@ export PYTHON_BUILD_TCLTK_USE_PKGCONFIG=1
install_package "openssl-4.0.1" "https://github.com/openssl/openssl/releases/download/openssl-4.0.1/openssl-4.0.1.tar.gz#2db3f3a0d6ea4b59e1f094ace2c8cd536dffb87cdc39084c5afa1e6f7f37dd09" mac_openssl --if has_broken_mac_openssl install_package "openssl-4.0.1" "https://github.com/openssl/openssl/releases/download/openssl-4.0.1/openssl-4.0.1.tar.gz#2db3f3a0d6ea4b59e1f094ace2c8cd536dffb87cdc39084c5afa1e6f7f37dd09" mac_openssl --if has_broken_mac_openssl
install_package "readline-8.3" "https://ftpmirror.gnu.org/readline/readline-8.3.tar.gz#fe5383204467828cd495ee8d1d3c037a7eba1389c22bc6a041f627976f9061cc" mac_readline --if has_broken_mac_readline install_package "readline-8.3" "https://ftpmirror.gnu.org/readline/readline-8.3.tar.gz#fe5383204467828cd495ee8d1d3c037a7eba1389c22bc6a041f627976f9061cc" mac_readline --if has_broken_mac_readline
if has_tar_xz_support; then if has_tar_xz_support; then
install_package "Python-3.15.0b3" "https://www.python.org/ftp/python/3.15.0/Python-3.15.0b3.tar.xz#6a935ae234a67e6549894373b0cfeb8361182d03b21442328ae9598ab7422127" standard verify_py315 copy_python_gdb ensurepip install_package "Python-3.15.0b4" "https://www.python.org/ftp/python/3.15.0/Python-3.15.0b4.tar.xz#93efb9c88d7b6633368e7f7b8f8db6e98988f7f761c09b77849447262841ce3a" standard verify_py315 copy_python_gdb ensurepip
else else
install_package "Python-3.15.0b3" "https://www.python.org/ftp/python/3.15.0/Python-3.15.0b3.tgz#e5a18806817f912f2c9a1091ac77703f9a969b129c878d436f0f7025bf2f9e97" standard verify_py315 copy_python_gdb ensurepip install_package "Python-3.15.0b4" "https://www.python.org/ftp/python/3.15.0/Python-3.15.0b4.tgz#4825af9329834306ad4a9cb56b94455381b52bcde4b653604a39f387cc559fc9" standard verify_py315 copy_python_gdb ensurepip
fi fi

View File

@ -0,0 +1,49 @@
# Copyright (c) 2026, Oracle and/or its affiliates. All rights reserved.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of
# this software and associated documentation files (the "Software"), to deal in
# the Software without restriction, including without limitation the rights to
# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
# of the Software, and to permit persons to whom the Software is furnished to do
# so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
VERSION='25.2.4'
colorize 1 "GraalPy 23.1 and later installed by python-build use the faster Oracle GraalVM distribution" && echo
colorize 1 "Oracle GraalVM uses the GFTC license, which is free for development and production use, see https://medium.com/graalvm/161527df3d76" && echo
colorize 1 "The GraalVM Community Edition variant of GraalPy is also available, under the name graalpy3.12-community-${VERSION}" && echo
graalpy_arch="$(graalpy_architecture 2>/dev/null || true)"
case "$graalpy_arch" in
"linux-amd64" )
checksum="b3d0766ae6d55daa15f0db1f6c884383d7eec506b186d0ba2f702523a78ff28d"
;;
"linux-aarch64" )
checksum="e57472272b1b659ae6ac972117723b0515a49cc9577688ed5563919793170d67"
;;
"macos-aarch64" )
checksum="79f0e1fefb42bb484122ae9e50cb21ce14541d18e6bd66c498e44b459ce652df"
;;
* )
{ echo
colorize 1 "ERROR"
echo ": No binary distribution of GraalPy is available for $(uname -sm)."
echo
} >&2
exit 1
;;
esac
install_package "graalpy3.12-${VERSION}" "https://github.com/oracle/graalpython/releases/download/graal-${VERSION}/graalpy3.12-${VERSION}-${graalpy_arch}.tar.gz#${checksum}" "copy" ensurepip

View File

@ -0,0 +1,44 @@
# Copyright (c) 2026, Oracle and/or its affiliates. All rights reserved.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of
# this software and associated documentation files (the "Software"), to deal in
# the Software without restriction, including without limitation the rights to
# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
# of the Software, and to permit persons to whom the Software is furnished to do
# so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
VERSION='25.2.4'
graalpy_arch="$(graalpy_architecture 2>/dev/null || true)"
case "$graalpy_arch" in
"linux-amd64" )
checksum="98af303a6b714bde39077354733254f78023ddef06d61e14cb66a3a01f10ae82"
;;
"linux-aarch64" )
checksum="dda5e97c8b38158184dec189addaece57a37207a0dad38be162621d605f964f5"
;;
"macos-aarch64" )
checksum="76a182713660ce69f640b9666c2861ec8a5839637a972eaa80c6b5cf38f1357b"
;;
* )
{ echo
colorize 1 "ERROR"
echo ": No binary distribution of GraalPy is available for $(uname -sm)."
echo
} >&2
exit 1
;;
esac
install_package "graalpy3.12-community-${VERSION}" "https://github.com/oracle/graalpython/releases/download/graal-${VERSION}/graalpy3.12-community-${VERSION}-${graalpy_arch}.tar.gz#${checksum}" "copy" ensurepip

View File

@ -160,6 +160,22 @@ OUT
unstub python-build unstub python-build
} }
@test "list available versions with --bare" {
stub_python_build_lib
stub_python_build "--definitions : echo 2.6.9 2.7.9-rc1 2.7.9-rc2 3.4.2 | tr ' ' $'\\n'"
run pyenv-install --list --bare
assert_success
assert_output <<OUT
2.6.9
2.7.9-rc1
2.7.9-rc2
3.4.2
OUT
unstub python-build
}
@test "upgrade instructions given for a nonexistent version" { @test "upgrade instructions given for a nonexistent version" {
stub brew false stub brew false
stub_python_build_lib stub_python_build_lib
@ -265,6 +281,7 @@ OUT
run pyenv-install --complete run pyenv-install --complete
assert_success assert_success
assert_output <<OUT assert_output <<OUT
--bare
--list --list
--force --force
--skip-existing --skip-existing

View File

@ -15,62 +15,25 @@ Under the hood, `pyenv` test suites use `bats` as a test framework and are run o
- `test` - `test`
- Run the whole test suite on the local host - Run the whole test suite on the local host
- `test-docker` - `test-docker`
- Run the whole test suite on docker - Run the whole test suite in Docker (in all environments)
- Some volumes are used in read-only mode
- `test-unit` - `test-unit`
- Run the unit test - Run core tests
- `test-plugin` - `test-python-build`
- Run the plugin test - Run Python-Build tests
- `test-unit-docker-[BASH_VERSION]` - `test-binary`
- Run the unit test under **official** bash docker container (alpine/busybox) with the specified bash version if present is in the `Makefile` - Run Pyenv-Binary tests
- Some volumes are used in read-only mode - `test-*-docker`
- `test-unit-docker-gnu-[BASH_VERSION]` - Run the corresponding test suite in Docker
- Run the unit test under **official** bash docker container (alpine/busybox), completed by **GNU Tools**, with the specified bash version if present is in the `Makefile` - `test-*-docker-[BASH_VERSION]`, `test-*-docker-gnu-[BASH_VERSION]`
- Some volumes are used in read-only mode - Run the corresponding test suite in the official Bash Docker container (alpine/busybox)
- `test-plugin-docker-[BASH_VERSION]` against either Busybox tools or GNU tools, with the specified Bash version
- Run the plugin test under **official** bash docker container (alpine/busybox), completed by **GNU Tools**, with the specified bash version if present is in the `Makefile` among those listed in the `Makefile`
- Some volumes are used in read-only mode
- `test-plugin-docker-gnu-[BASH_VERSION]`
- Run the plugin test under **official** bash docker container (alpine/busybox), completed by **GNU Tools**, with the specified bash version if present is in the `Makefile`
- Some volumes are used in read-only mode
## Targeting specific test / test file ## Targeting specific test / test file
By setting some environment variables, it is possible to filtering which test and/or test file who will be tested with bats By setting some environment variables, it is possible to filter which test and/or test file will be run
- `BATS_FILE_FILTER` - `BATS_FILE_FILTER`
- Run tests from the specified file
- Run test only with the specified file
- `BATS_TEST_FILTER` - `BATS_TEST_FILTER`
- Run test only who corresponding to the filter provided - Run tests with the names corresponding to the filter
### Examples
```bash
$ BATS_TEST_FILTER=".*installed.*" BATS_FILE_FILTER="build.bats" make test-plugin-docker-gnu-3.2.57
build.bats
✓ yaml is installed for python
✓ homebrew is used in Linux if Pyenv is installed with Homebrew
✓ homebrew is not used in Linux if Pyenv is not installed with Homebrew
3 tests, 0 failures
$ BATS_TEST_FILTER=".*installed.*" BATS_FILE_FILTER="build.bats" make test-plugin
build.bats
✓ yaml is installed for python
✓ homebrew is used in Linux if Pyenv is installed with Homebrew
✓ homebrew is not used in Linux if Pyenv is not installed with Homebrew
3 tests, 0 failures
```
## Writing test
To be reproducible, each test use/should use its own `TMPDIR` .
It's achieved by using the environment variable `BATS_TEST_TMPDIR` provided by bats that is automatically deleted at the end of each test. More info [here](https://bats-core.readthedocs.io/en/stable/writing-tests.html#special-variables)
Another variable who could be used to source some file who need to be tested is `BATS_TEST_DIRNAME` who point to the directory in which the bats test file is located.

View File

@ -35,7 +35,7 @@ setup() {
unset xdg_var unset xdg_var
# Workaround for Powershell. When tests are run from a terminal, # Workaround for Powershell. When tests are run from a terminal,
# and running a script fron a here-document, # and running a script from a here-document,
# Powershell 7.5.4 erroneously prints ANSI escape sequences # Powershell 7.5.4 erroneously prints ANSI escape sequences
# even if its output is redirected, breaking the comparison logic # even if its output is redirected, breaking the comparison logic
export NO_COLOR=1 export NO_COLOR=1