Compare commits

...

78 commits

Author SHA1 Message Date
native-api ef4905cd81
Incorporate the pyenv-link plugin (#3538)
Some checks failed
pyenv_tests / pyenv_tests (ubuntu-22.04) (push) Failing after 1s
build / discover_build_logic_change (push) Has been cancelled
pyenv_tests / pyenv_tests (macos-14) (push) Has been cancelled
pyenv_tests / pyenv_tests (macos-15) (push) Has been cancelled
pyenv_tests / pyenv_tests (macos-15-intel) (push) Has been cancelled
pyenv_tests / pyenv_tests (macos-26) (push) Has been cancelled
pyenv_tests / pyenv_tests (ubuntu-22.04-arm) (push) Has been cancelled
pyenv_tests / pyenv_tests (ubuntu-24.04) (push) Has been cancelled
pyenv_tests / pyenv_tests (ubuntu-24.04-arm) (push) Has been cancelled
pyenv_tests / pyenv_tests_docker (push) Has been cancelled
build / build (push) Has been cancelled
for use in linking binary installations
2026-09-09 02:43:22 +03:00
Ivan Pozdeev 88e9ab13e8 pwsh: Fix error in shell integration if pyenv is on PATH multiple times
Fixes "The term 'pyenv pyenv' is not recognized..."
2026-09-09 02:31:49 +03:00
macayu17 798a1ad603 Incorporate the pyenv-link plugin
* Adapt test_helper for use in plugins
* Add pyenv-link tests
* Add pyenv-link tests to CI
2026-09-09 02:30:53 +03:00
macayu17 fb7f2071fb Add 'plugins/pyenv-link/' from commit '2f8cb2cf1f093e955a72babf0b65a07f84f33522'
git-subtree-dir: plugins/pyenv-link
git-subtree-mainline: ef7a9f5d14
git-subtree-split: 2f8cb2cf1f
2026-09-08 02:55:49 +05:30
Michael Newman ef7a9f5d14
docs: Add link to list of available Python distributions (#3535)
Some checks failed
pyenv_tests / pyenv_tests (ubuntu-22.04) (push) Failing after 1s
pyenv_tests / pyenv_tests (ubuntu-22.04-arm) (push) Has been cancelled
pyenv_tests / pyenv_tests (ubuntu-24.04) (push) Has been cancelled
build / discover_build_logic_change (push) Has been cancelled
pyenv_tests / pyenv_tests (macos-15) (push) Has been cancelled
pyenv_tests / pyenv_tests (macos-15-intel) (push) Has been cancelled
pyenv_tests / pyenv_tests (macos-26) (push) Has been cancelled
pyenv_tests / pyenv_tests (ubuntu-24.04-arm) (push) Has been cancelled
pyenv_tests / pyenv_tests_docker (push) Has been cancelled
build / build (push) Has been cancelled
pyenv_tests / pyenv_tests (macos-14) (push) Has been cancelled
Add a link to the python-build share directory in the intro section
so users can see which Python distributions are supported before
installing pyenv.
2026-09-06 22:14:47 +03:00
Ayush 265b0dcefa
python-build: add build prerequisite installer (#3532)
Some checks failed
pyenv_tests / pyenv_tests (ubuntu-22.04) (push) Failing after 1s
pyenv_tests / pyenv_tests (ubuntu-24.04-arm) (push) Has been cancelled
pyenv_tests / pyenv_tests_docker (push) Has been cancelled
pyenv_tests / pyenv_tests (ubuntu-22.04-arm) (push) Has been cancelled
pyenv_tests / pyenv_tests (ubuntu-24.04) (push) Has been cancelled
pyenv_tests / pyenv_tests (macos-15-intel) (push) Has been cancelled
pyenv_tests / pyenv_tests (macos-26) (push) Has been cancelled
pyenv_tests / pyenv_tests (macos-14) (push) Has been cancelled
pyenv_tests / pyenv_tests (macos-15) (push) Has been cancelled
build / discover_build_logic_change (push) Has been cancelled
build / build (push) Has been cancelled
2026-09-02 17:56:35 +03:00
Michael Šimáček 2548d53706
Update graalpy URLs for 25.3.4.1 (#3533) 2026-09-02 14:47:33 +03:00
Ivan Pozdeev c293de3650 2.8.5
Some checks failed
build / discover_build_logic_change (push) Waiting to run
build / build (push) Blocked by required conditions
pyenv_tests / pyenv_tests (macos-14) (push) Waiting to run
pyenv_tests / pyenv_tests (macos-15) (push) Waiting to run
pyenv_tests / pyenv_tests (macos-15-intel) (push) Waiting to run
pyenv_tests / pyenv_tests (macos-26) (push) Waiting to run
pyenv_tests / pyenv_tests (ubuntu-22.04-arm) (push) Waiting to run
pyenv_tests / pyenv_tests (ubuntu-24.04) (push) Waiting to run
pyenv_tests / pyenv_tests (ubuntu-24.04-arm) (push) Waiting to run
pyenv_tests / pyenv_tests_docker (push) Waiting to run
pyenv_tests / pyenv_tests (ubuntu-22.04) (push) Failing after 1s
2026-09-01 18:05:40 +03:00
Ayush bdfc6b03f3
pyenv-binary: support relocating macOS archives (#3528) 2026-09-01 18:01:23 +03:00
pyenv-bot[bot] 8c46508bd0
Add CPython 3.15.0rc2 (#3530)
Co-authored-by: native-api <2670332+native-api@users.noreply.github.com>
2026-09-01 17:53:59 +03:00
Michael Šimáček a00e0bc475
Add GraalPy 25.3.4.1 (#3529)
Some checks failed
build / build (push) Blocked by required conditions
build / discover_build_logic_change (push) Waiting to run
pyenv_tests / pyenv_tests (macos-14) (push) Waiting to run
pyenv_tests / pyenv_tests (macos-15) (push) Waiting to run
pyenv_tests / pyenv_tests (macos-15-intel) (push) Waiting to run
pyenv_tests / pyenv_tests (macos-26) (push) Waiting to run
pyenv_tests / pyenv_tests (ubuntu-22.04-arm) (push) Waiting to run
pyenv_tests / pyenv_tests (ubuntu-24.04) (push) Waiting to run
pyenv_tests / pyenv_tests (ubuntu-24.04-arm) (push) Waiting to run
pyenv_tests / pyenv_tests_docker (push) Waiting to run
pyenv_tests / pyenv_tests (ubuntu-22.04) (push) Failing after 1s
2026-08-31 23:28:40 +03:00
Michael Newman 981559003f
Fix typo
Some checks failed
pyenv_tests / pyenv_tests (ubuntu-22.04) (push) Failing after 0s
pyenv_tests / pyenv_tests (macos-15) (push) Has been cancelled
pyenv_tests / pyenv_tests (macos-15-intel) (push) Has been cancelled
pyenv_tests / pyenv_tests (macos-26) (push) Has been cancelled
pyenv_tests / pyenv_tests (ubuntu-22.04-arm) (push) Has been cancelled
pyenv_tests / pyenv_tests (ubuntu-24.04) (push) Has been cancelled
pyenv_tests / pyenv_tests (ubuntu-24.04-arm) (push) Has been cancelled
pyenv_tests / pyenv_tests_docker (push) Has been cancelled
build / discover_build_logic_change (push) Has been cancelled
pyenv_tests / pyenv_tests (macos-14) (push) Has been cancelled
build / build (push) Has been cancelled
2026-08-29 15:01:30 +03:00
Michael Newman 4733cca31b
Fix typo
Some checks failed
build / discover_build_logic_change (push) Waiting to run
build / build (push) Blocked by required conditions
pyenv_tests / pyenv_tests (ubuntu-22.04-arm) (push) Waiting to run
pyenv_tests / pyenv_tests (ubuntu-24.04) (push) Waiting to run
pyenv_tests / pyenv_tests (ubuntu-24.04-arm) (push) Waiting to run
pyenv_tests / pyenv_tests_docker (push) Waiting to run
pyenv_tests / pyenv_tests (macos-14) (push) Waiting to run
pyenv_tests / pyenv_tests (macos-15) (push) Waiting to run
pyenv_tests / pyenv_tests (macos-15-intel) (push) Waiting to run
pyenv_tests / pyenv_tests (macos-26) (push) Waiting to run
pyenv_tests / pyenv_tests (ubuntu-22.04) (push) Failing after 1s
2026-08-28 15:36:28 +03:00
native-api ef2fb22235
Merge pull request #3522 from sujeito-operator/ci-test-everywhere-on-build-logic-change
CI: test on all runners when the build logic changes
2026-08-26 16:05:18 +03:00
sujeito-operator 97900a4aa4 CI: test on all runners when the build logic changes
Co-Authored-By: Ivan Pozdeev <vano@mail.mipt.ru>
2026-08-26 10:09:25 +03:00
sujeito-operator ecf9a7f9e6 CI: collapse macos_build and ubuntu_build into a single job
Co-Authored-By: Ivan Pozdeev <vano@mail.mipt.ru>
2026-08-26 09:40:01 +03:00
native-api 495550afc8
Merge pull request #3525 from native-api/test_improvements
Test improvements
2026-08-26 06:00:53 +03:00
Ivan Pozdeev 57f1df294b tests: add file names to TAP output
by using a customized formatter
2026-08-26 05:51:24 +03:00
Ivan Pozdeev 14830b18bf tests: skip permission tests if permission bits are being overridden
e.g. if running as root in a docker container
2026-08-26 05:50:04 +03:00
Ivan Pozdeev 032e7af407 tests: consolidate shims tests 2026-08-26 05:49:17 +03:00
native-api b0cff001ff
tests: Fix "cd: null directory" in OpenSUSE (#3524)
A workaround because tests don't use the Pyenv launcher and setting PYENV_DIR to $PWD at every run invocation is too cumbersome.
2026-08-25 22:43:59 +03:00
Michael Newman 234a87e400
Fix typo 2026-08-17 01:51:28 +03:00
Ayush 50fbc8c6cc
pyenv-binary: record direct system dependencies in Linux/FreeBSD (#3520) 2026-08-15 22:47:27 +03:00
Ivan Pozdeev 0f16606e4f 2.8.4 2026-08-13 15:08:51 +03:00
native-api 7c2226386b
Add anaconda3-2026.07-1, miniconda3 26.5.3-2 2026-08-13 14:59:25 +03:00
Ivan Pozdeev 3a98f8c1c3 add_miniforge: better logging, skip 2 faulty releases 2026-08-13 14:16:14 +03:00
native-api f99638cb82
Merge pull request #3518 from pyenv/auto_add_version/3.10.21_3.11.16_3.12.14
Add CPython 3.10.21, 3.11.16, 3.12.14
2026-08-13 14:03:45 +03:00
Ivan Pozdeev 3b9604c093 Add missing 3.10.x patches 2026-08-13 13:10:43 +03:00
native-api 920052eb0b Add CPython 3.10.21, 3.11.16, 3.12.14 2026-08-13 08:53:14 +00:00
native-api cb20e375d3
Merge pull request #3517 from native-api/ci_ubuntu_arm
CI: add ubuntu ARM images
2026-08-13 01:51:46 +03:00
Ivan Pozdeev f11926a274 Run Docker tests separately 2026-08-13 01:44:17 +03:00
Ivan Pozdeev 0fc5dfe630 refactor 2026-08-13 01:44:17 +03:00
Ivan Pozdeev 2bcc7d8fc4 Add ubuntu ARM images 2026-08-13 01:44:11 +03:00
Ivan Pozdeev 2bd4f6c4da - rbenv compatibility note
We've not been syncing with Rbenv for years
2026-08-12 15:26:35 +03:00
Ivan Pozdeev 8771e721c1 Add past CVE-2026-68939 fix to CHANGELOG
Now that Github has issued a CVE number 3 weeks late
2026-08-12 15:19:48 +03:00
native-api d92b6e1bbe
Merge pull request #3516 from macayu17/fix/2334-package-feedback
pyenv-binary-package: check patchelf early and add --verbose
2026-08-11 05:25:39 +03:00
Ivan Pozdeev 9962f8cb39 pyenv-binary-package: refactor tests
* make them more human-readable
* don't double-test external code outside of integration tests
2026-08-11 05:17:49 +03:00
Ivan Pozdeev f9ffb73a7e test_helper: support here-document to assert_success/failure; + assert_output_glob 2026-08-11 05:17:42 +03:00
Ivan Pozdeev bd7c969e7f test_helper: show diff with whitespace highlights
to be able to see tiny and whitespace differences
2026-08-11 04:22:34 +03:00
macayu17 4a73bd17e2 pyenv-binary-package: add --verbose
Co-authored-by: Ivan Pozdeev <vano@mail.mipt.ru>
2026-08-11 04:22:33 +03:00
macayu17 2c1f405180 pyenv-binary: check patchelf before installing archive 2026-08-11 04:19:39 +03:00
native-api e234812f46
Merge pull request #3515 from fudianchn/fix/version-file-relative-loop-3513
Stop infinite loop in pyenv version-file for relative paths
2026-08-10 13:08:04 +03:00
Ivan Pozdeev 1a591b3963 Avoid extra iteration for argument with a trailing slash 2026-08-10 12:56:57 +03:00
Ivan Pozdeev 48e70e1fe9 Only test for UNC paths every iteration if they are special 2026-08-10 12:55:19 +03:00
付典 195b9fe940 version-file: Fix infinite loop for relative paths
find_local_version_file reduces its target with ${root%/*}, but that leaves a slash-less relative argument such as "." unchanged, leading to an infinite loop

Signed-off-by: 付典 <fudianchn@gmail.com>
2026-08-10 12:49:53 +03:00
native-api b7e7adf4ec
Merge pull request #3511 from macayu17/fix/2334-freebsd-ldconfig
pyenv-binary: check FreeBSD system libraries
2026-08-10 03:29:33 +03:00
macayu17 a6ef1e70ba Resolve version prefixes in package names 2026-08-10 03:27:47 +03:00
macayu17 5a31fea21b pyenv-binary: support checking FreeBSD system libraries
* Handle both spaced and unspaced FreeBSD `ldconfig -r` output
2026-08-10 03:27:46 +03:00
native-api 17be308600
Merge pull request #3514 from native-api/add_macos_26_intel
CI: Add macos_26_intel
2026-08-08 00:58:10 +03:00
Ivan Pozdeev 9d6cf587b7 Run the discover job on slim 2026-08-07 23:17:31 +03:00
Ivan Pozdeev 1cc9e770ae Fix regexes 2026-08-07 23:17:31 +03:00
Ivan Pozdeev 0e2e214f56 Fix ubuntu_build_tar_gz 2026-08-07 23:17:31 +03:00
Ivan Pozdeev 340348d98d - code irrelevant to CPython in CPython-specific scenarios 2026-08-07 23:17:30 +03:00
Ivan Pozdeev 2d9a224e6c Add macos-26-intel to CI
* Fix macos_build_bundled_dependencies in macos-26-intel
  It has a different set of preinstalled OpenSSL formulae
2026-08-07 23:16:23 +03:00
Ivan Pozdeev da172db42d 2.8.3 2026-08-05 22:08:09 +03:00
pyenv-bot[bot] b0a64af8cc
Add CPython 3.13.15, 3.14.7 (#3512) 2026-08-05 22:06:09 +03:00
Ivan Pozdeev 9e4d1ca95a 2.8.2 2026-08-04 23:10:49 +03:00
Ayush b9e165271e
pyenv-binary: generate platform-specific package names (#3504) 2026-08-04 22:53:34 +03:00
John Sirois 3088203e33
Add CPython 3.15.0rc1 (#3510) 2026-08-04 22:48:04 +03:00
Anupam Mediratta 8f70d418bb
add_cpython: refactor extra Requests logic (#3507)
---------

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-authored-by: Ivan Pozdeev <vano@mail.mipt.ru>
2026-08-04 13:12:42 +03:00
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
Mészáros Máté Róbert 2f8cb2cf1f
Handle osx specific ln option name (#1)
On OSX `ln` does not have `--symbolic` only `-s`.

* bin/pyenv-link-version

---------

Co-authored-by: yfprojects <62463991+real-yfprojects@users.noreply.github.com>
2023-07-07 14:18:02 +00:00
real-yfprojects b8d8dee191
Fix output
* bin/pyenv-link-version
2023-06-06 16:59:25 +02:00
real-yfprojects ba9099392a
Fix completions
* bin/pyenv-link
2023-06-06 16:56:16 +02:00
real-yfprojects d428be59ec
Write README.
* README.md
2023-06-06 16:45:22 +02:00
real-yfprojects dffc750fa2
Initial implementation
* bin/pyenv-link

* bin/pyenv-link-version
2023-06-06 16:22:52 +02:00
yfprojects f46b669f1d
Initial commit 2023-06-06 11:09:59 +00:00
83 changed files with 12720 additions and 442 deletions

View file

@ -3,9 +3,6 @@ Make sure you have checked all steps below.
### Prerequisite ### Prerequisite
* [ ] Please consider implementing the feature as a hook script or plugin as a first step. * [ ] Please consider implementing the feature as a hook script or plugin as a first step.
* pyenv has some powerful support for plugins and hook scripts. Please refer to [Authoring plugins](https://github.com/pyenv/pyenv/wiki/Authoring-plugins) for details and try to implement it as a plugin if possible. * pyenv has some powerful support for plugins and hook scripts. Please refer to [Authoring plugins](https://github.com/pyenv/pyenv/wiki/Authoring-plugins) for details and try to implement it as a plugin if possible.
* [ ] Please consider contributing the patch upstream to [rbenv](https://github.com/rbenv/rbenv), since we have borrowed most of the code from that project.
* We occasionally import the changes from rbenv. In general, you can expect changes made in rbenv will be imported to pyenv too, eventually.
* Generally speaking, we prefer not to make changes in the core in order to keep compatibility with rbenv.
* [ ] My PR addresses the following pyenv issue (if any) * [ ] My PR addresses the following pyenv issue (if any)
- Closes https://github.com/pyenv/pyenv/issues/XXXX - Closes https://github.com/pyenv/pyenv/issues/XXXX

44
.github/actions/build-python/action.yml vendored Normal file
View file

@ -0,0 +1,44 @@
name: Build a Python version
description: >
Install python-build's system dependencies for the current runner's OS, build
and check the requested version.
inputs:
python-version:
description: A version as accepted by `pyenv install`.
required: true
runs:
using: composite
steps:
- shell: bash
run: |
#envvars
export PYENV_ROOT="$GITHUB_WORKSPACE"
echo "PYENV_ROOT=$PYENV_ROOT" >> $GITHUB_ENV
echo "$PYENV_ROOT/shims:$PYENV_ROOT/bin" >> $GITHUB_PATH
# The two OSes differ only in this step.
- if: runner.os == 'macOS'
shell: bash
run: |
#prerequisites
brew install openssl readline sqlite3 xz tcl-tk@8 libb2 zstd
- if: runner.os == 'Linux'
shell: bash
run: |
#prerequisites
pyenv install-prerequisites
- shell: bash
run: |
#build
pyenv --debug install ${{ inputs.python-version }} && rc=$? || rc=$?
if [[ $rc -ne 0 ]]; then echo config.log:; cat "${TMPDIR:-/tmp}"/python-build*/*/config.log; false; fi
pyenv global ${{ inputs.python-version }}
pyenv rehash
- shell: bash
run: |
#print version
python --version
python -m pip --version
- shell: python # Prove that actual Python == expected Python
env:
EXPECTED_PYTHON: ${{ inputs.python-version }}
run: import os, sys ; assert sys.version.startswith(os.getenv("EXPECTED_PYTHON"))

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'

62
.github/workflows/build.yml vendored Normal file
View file

@ -0,0 +1,62 @@
name: build
on:
push:
branches: [master]
pull_request: {}
permissions:
contents: read
jobs:
discover_build_logic_change:
if: github.event_name == 'pull_request'
runs-on: ubuntu-slim
env:
FULL_OS_MATRIX: '[
"macos-14",
"macos-15",
"macos-15-intel",
"macos-26",
"macos-26-intel",
"ubuntu-22.04",
"ubuntu-22.04-arm",
"ubuntu-24.04",
"ubuntu-24.04-arm"
]'
outputs:
os: ${{ steps.detect.outputs.os }}
steps:
- uses: actions/checkout@v7
- run: git fetch origin "$GITHUB_BASE_REF"
- id: detect
shell: bash
run: |
if [[ -n $(git diff --name-only "origin/$GITHUB_BASE_REF" -- \
plugins/python-build/bin/python-build \
.github/actions/build-python/action.yml \
.github/workflows/build.yml) ]]
then
printf "%s\n" "os<<!" "$FULL_OS_MATRIX" "!" >> "$GITHUB_OUTPUT"
fi
build:
needs: discover_build_logic_change
# Run when the detection job succeeded *or was skipped* -- but not failed
if: ${{ !cancelled() && !failure() }}
strategy:
fail-fast: false
matrix:
os: ${{ fromJson(needs.discover_build_logic_change.outputs.os || '["macos-latest","ubuntu-latest"]') }}
python-version:
- "3.10"
- "3.11"
- "3.12"
- "3.13"
- "3.14"
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v7
- uses: ./.github/actions/build-python
with:
python-version: ${{ matrix.python-version }}

View file

@ -1,43 +0,0 @@
name: macos_build
on:
push:
branches: [master]
pull_request: {}
permissions:
contents: read # to fetch code (actions/checkout)
jobs:
macos_build:
strategy:
fail-fast: false
matrix:
python-version:
- "3.10"
- "3.11"
- "3.12"
- "3.13"
- "3.14"
runs-on: macos-latest
steps:
- uses: actions/checkout@v7
- run: |
brew install openssl readline sqlite3 xz tcl-tk@8 libb2 zstd
- run: |
#envvars
export PYENV_ROOT="$GITHUB_WORKSPACE"
echo "PYENV_ROOT=$PYENV_ROOT" >> $GITHUB_ENV
echo "$PYENV_ROOT/shims:$PYENV_ROOT/bin" >> $GITHUB_PATH
- run: |
#build
pyenv --debug install ${{ matrix.python-version }} && rc=$? || rc=$?
if [[ $rc -ne 0 ]]; then echo config.log:; cat $TMPDIR/python-build*/*/config.log; false; fi
pyenv global ${{ matrix.python-version }}
- run: |
#print version
python --version
python -m pip --version
- shell: python # Prove that actual Python == expected Python
env:
EXPECTED_PYTHON: ${{ matrix.python-version }}
run: import os, sys ; assert sys.version.startswith(os.getenv("EXPECTED_PYTHON"))

View file

@ -2,7 +2,7 @@ name: modified_scripts
on: [pull_request] on: [pull_request]
jobs: jobs:
discover_modified_scripts: discover_modified_scripts:
runs-on: ubuntu-latest runs-on: ubuntu-slim
outputs: outputs:
versions: ${{steps.modified-versions.outputs.versions}} versions: ${{steps.modified-versions.outputs.versions}}
versions_cpython_only: ${{steps.modified-versions.outputs.versions_cpython_only}} versions_cpython_only: ${{steps.modified-versions.outputs.versions_cpython_only}}
@ -43,28 +43,32 @@ jobs:
import packaging.version import packaging.version
result=[] result=[]
def exclude_macos_intel(result, python_version):
result.append({'os':'macos-15-intel','python-version':python_version})
result.append({'os':'macos-26-intel','python-version':python_version})
for line in os.environ['versions'].splitlines(): for line in os.environ['versions'].splitlines():
if m:=re.match(r'([^-]+)-(\d+\.\d+)-(\d+\.\d+.\d+)', line): if m:=re.match(r'miniconda3-\d+\.\d+-(\d+\.\d+\.\d+)', line):
name, version = m.group(1), packaging.version.Version(m.group(3)) version = packaging.version.Version(m.group(1))
# Miniconda dropped MacOS x64 support # Miniconda dropped MacOS x64 support
if (name == 'miniconda3' and version >= packaging.version.Version('25.9.1')): if version >= packaging.version.Version('25.9.1'):
result.append({'os':'macos-15-intel','python-version':line}) exclude_macos_intel(result, line)
if m:=re.match(r'([^-]+)-(\d+\.\d+)', line): if m:=re.match(r'anaconda3-(\d+\.\d+)', line):
name, version = m.group(1), packaging.version.Version(m.group(2)) version = packaging.version.Version(m.group(1))
# Anaconda dropped MacOS x64 support # Anaconda dropped MacOS x64 support
if name == 'anaconda3' and version >= packaging.version.Version('2025.12'): if version >= packaging.version.Version('2025.12'):
result.append({'os':'macos-15-intel','python-version':line}) exclude_macos_intel(result, line)
if m:=re.match(r'graalpy[^-]*-(community-)?(\d+\.\d+.\d+)', line): if m:=re.match(r'graalpy[^-]*-(community-)?(\d+\.\d+\.\d+)', line):
version = packaging.version.Version(m.group(2)) version = packaging.version.Version(m.group(2))
# GraalPy dropped MacOS x64 support # GraalPy dropped MacOS x64 support
if version >= packaging.version.Version('25.0.2'): if version >= packaging.version.Version('25.0.2'):
result.append({'os':'macos-15-intel','python-version':line}) exclude_macos_intel(result, line)
EOF = str(random.getrandbits(15*8)) EOF = str(random.getrandbits(15*8))
@ -91,6 +95,7 @@ jobs:
- macos-15 - macos-15
- macos-15-intel - macos-15-intel
- macos-26 - macos-26
- macos-26-intel
exclude: ${{fromJson(needs.discover_modified_scripts.outputs.versions_macos_build_exclude)}} exclude: ${{fromJson(needs.discover_modified_scripts.outputs.versions_macos_build_exclude)}}
runs-on: ${{ matrix.os }} runs-on: ${{ matrix.os }}
steps: steps:
@ -153,7 +158,12 @@ jobs:
fail-fast: false fail-fast: false
matrix: matrix:
python-version: ${{fromJson(needs.discover_modified_scripts.outputs.versions_cpython_only)}} python-version: ${{fromJson(needs.discover_modified_scripts.outputs.versions_cpython_only)}}
os: ["macos-14", "macos-15", "macos-15-intel"] os:
- macos-14
- macos-15
- macos-15-intel
- macos-26
- macos-26-intel
runs-on: ${{ matrix.os }} runs-on: ${{ matrix.os }}
steps: steps:
- uses: actions/checkout@v7 - uses: actions/checkout@v7
@ -165,12 +175,7 @@ jobs:
- run: | - run: |
#prerequisites #prerequisites
brew install sqlite3 xz tcl-tk@8 libb2 zstd brew install sqlite3 xz tcl-tk@8 libb2 zstd
"$GITHUB_WORKSPACE/.github/workflows/scripts/brew-uninstall-cascade.sh" openssl@3 openssl@1.1 readline "$GITHUB_WORKSPACE/.github/workflows/scripts/brew-uninstall-cascade.sh" $(brew list | grep -E '^openssl(@|$)') readline
if [[ "${{ matrix.python-version }}" =~ pypy.*-(src|dev) ]]; then
export PYENV_BOOTSTRAP_VERSION=pypy2.7-7
echo "PYENV_BOOTSTRAP_VERSION=$PYENV_BOOTSTRAP_VERSION" >> $GITHUB_ENV
pyenv install $PYENV_BOOTSTRAP_VERSION
fi
- run: | - run: |
#build #build
pyenv --debug install ${{ matrix.python-version }} && rc=$? || rc=$? pyenv --debug install ${{ matrix.python-version }} && rc=$? || rc=$?
@ -202,7 +207,9 @@ jobs:
python-version: ${{fromJson(needs.discover_modified_scripts.outputs.versions)}} python-version: ${{fromJson(needs.discover_modified_scripts.outputs.versions)}}
os: os:
- ubuntu-22.04 - ubuntu-22.04
- ubuntu-22.04-arm
- ubuntu-24.04 - ubuntu-24.04
- ubuntu-24.04-arm
runs-on: ${{ matrix.os }} runs-on: ${{ matrix.os }}
steps: steps:
- uses: actions/checkout@v7 - uses: actions/checkout@v7
@ -213,10 +220,7 @@ jobs:
echo "$PYENV_ROOT/shims:$PYENV_ROOT/bin" >> $GITHUB_PATH echo "$PYENV_ROOT/shims:$PYENV_ROOT/bin" >> $GITHUB_PATH
- run: | - run: |
#prerequisites #prerequisites
sudo apt-get update -q; sudo apt-get install -yq make build-essential \ pyenv install-prerequisites
libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev \
curl llvm libncurses5-dev libncursesw5-dev \
xz-utils tk-dev libffi-dev liblzma-dev
if [[ "${{ matrix.python-version }}" =~ pypy.*-(src|dev) ]]; then if [[ "${{ matrix.python-version }}" =~ pypy.*-(src|dev) ]]; then
export PYENV_BOOTSTRAP_VERSION=pypy2.7-7 export PYENV_BOOTSTRAP_VERSION=pypy2.7-7
echo "PYENV_BOOTSTRAP_VERSION=$PYENV_BOOTSTRAP_VERSION" >> $GITHUB_ENV echo "PYENV_BOOTSTRAP_VERSION=$PYENV_BOOTSTRAP_VERSION" >> $GITHUB_ENV
@ -265,8 +269,7 @@ jobs:
fail-fast: false fail-fast: false
matrix: matrix:
python-version: ${{fromJson(needs.discover_modified_scripts.outputs.versions_cpython_only)}} python-version: ${{fromJson(needs.discover_modified_scripts.outputs.versions_cpython_only)}}
os: ["ubuntu-latest"] runs-on: ubuntu-latest
runs-on: ${{ matrix.os }}
steps: steps:
- uses: actions/checkout@v7 - uses: actions/checkout@v7
- run: | - run: |
@ -274,18 +277,10 @@ jobs:
export PYENV_ROOT="$GITHUB_WORKSPACE" export PYENV_ROOT="$GITHUB_WORKSPACE"
echo "PYENV_ROOT=$PYENV_ROOT" >> $GITHUB_ENV echo "PYENV_ROOT=$PYENV_ROOT" >> $GITHUB_ENV
echo "$PYENV_ROOT/shims:$PYENV_ROOT/bin" >> $GITHUB_PATH echo "$PYENV_ROOT/shims:$PYENV_ROOT/bin" >> $GITHUB_PATH
echo "_PYTHON_BUILD_FORCE_SKIP_XZ=1" >> $GITHUB_PATH echo "_PYTHON_BUILD_FORCE_SKIP_XZ=1" >> $GITHUB_ENV
- run: | - run: |
#prerequisites #prerequisites
sudo apt-get update -q; sudo apt-get install -yq make build-essential \ pyenv install-prerequisites
libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev \
curl llvm libncurses5-dev libncursesw5-dev \
xz-utils tk-dev libffi-dev liblzma-dev
if [[ "${{ matrix.python-version }}" =~ pypy.*-(src|dev) ]]; then
export PYENV_BOOTSTRAP_VERSION=pypy2.7-7
echo "PYENV_BOOTSTRAP_VERSION=$PYENV_BOOTSTRAP_VERSION" >> $GITHUB_ENV
pyenv install $PYENV_BOOTSTRAP_VERSION
fi
- run: | - run: |
#build #build
pyenv --debug install ${{ matrix.python-version }} && rc=$? || rc=$? pyenv --debug install ${{ matrix.python-version }} && rc=$? || rc=$?

View file

@ -14,7 +14,9 @@ jobs:
matrix: matrix:
os: os:
- ubuntu-22.04 - ubuntu-22.04
- ubuntu-22.04-arm
- ubuntu-24.04 - ubuntu-24.04
- ubuntu-24.04-arm
- macos-14 - macos-14
- macos-15 - macos-15
- macos-15-intel - macos-15-intel
@ -22,25 +24,22 @@ jobs:
runs-on: ${{ matrix.os }} runs-on: ${{ matrix.os }}
steps: steps:
- uses: actions/checkout@v7 - uses: actions/checkout@v7
- run: | - name: Install prerequisites
run: |
if test "$RUNNER_OS" == "macOS"; then if test "$RUNNER_OS" == "macOS"; then
brew install coreutils fish brew install coreutils fish
fi fi
- run: pwd - name: Run tests
- env:
PYENV_ROOT: /home/runner/work/pyenv/pyenv
run: |
echo $PYENV_ROOT
echo "$PYENV_ROOT/shims:$PYENV_ROOT/bin" >> $GITHUB_PATH
- name: Run test on the host
run: | run: |
make test make test
- name: Run test with docker
if: ${{ ! contains(matrix.os, 'macos') }}
run: |
make test-docker
- env: - env:
PYENV_NATIVE_EXT: 1 PYENV_NATIVE_EXT: 1
run: | run: |
(cd src; ./configure; make) (cd src; ./configure; make)
bats/bin/bats test/{pyenv,hooks,versions}.bats bats/bin/bats test/{pyenv,hooks,versions}.bats
pyenv_tests_docker:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- run: |
make test-docker

View file

@ -1,43 +0,0 @@
name: ubuntu_build
on:
push:
branches: [master]
pull_request: {}
permissions:
contents: read # to fetch code (actions/checkout)
jobs:
ubuntu_build:
strategy:
fail-fast: false
matrix:
python-version:
- "3.10"
- "3.11"
- "3.12"
- "3.13"
- "3.14"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- run: |
sudo apt-get update -q; sudo apt install -yq make build-essential libssl-dev zlib1g-dev \
libbz2-dev libreadline-dev libsqlite3-dev curl \
libncursesw5-dev xz-utils tk-dev libxml2-dev libxmlsec1-dev libffi-dev liblzma-dev
# https://github.com/pyenv/pyenv#installation
- run: pwd
- env:
PYENV_ROOT: /home/runner/work/pyenv/pyenv
run: |
echo $PYENV_ROOT
echo "$PYENV_ROOT/shims:$PYENV_ROOT/bin" >> $GITHUB_PATH
bin/pyenv --debug install ${{ matrix.python-version }}
bin/pyenv global ${{ matrix.python-version }}
bin/pyenv rehash
- run: python --version
- run: python -m pip --version
- shell: python # Prove that actual Python == expected Python
env:
EXPECTED_PYTHON: ${{ matrix.python-version }}
run: import os, sys ; assert sys.version.startswith(os.getenv("EXPECTED_PYTHON"))

1
.gitignore vendored
View file

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

View file

@ -1,6 +1,40 @@
# Version History # Version History
## Release v2.8.5
* pyenv-binary: record direct system dependencies in Linux/FreeBSD by @macayu17 in https://github.com/pyenv/pyenv/pull/3520
* tests: Fix "cd: null directory" in OpenSUSE by @native-api in https://github.com/pyenv/pyenv/pull/3524
* Test improvements by @native-api in https://github.com/pyenv/pyenv/pull/3525
* CI: test on all runners when the build logic changes by @sujeito-operator in https://github.com/pyenv/pyenv/pull/3522
* Add GraalPy 25.3.4.1 by @msimacek in https://github.com/pyenv/pyenv/pull/3529
* Add CPython 3.15.0rc2 by @pyenv-bot[bot] in https://github.com/pyenv/pyenv/pull/3530
* pyenv-binary: support relocating macOS archives by @macayu17 in https://github.com/pyenv/pyenv/pull/3528
## Release v2.8.4
* CI: Add macos_26_intel by @native-api in https://github.com/pyenv/pyenv/pull/3514
* pyenv-binary: check FreeBSD system libraries by @macayu17 in https://github.com/pyenv/pyenv/pull/3511
* version-file: Fix infinite loop for a relative path argument by @fudianchn in https://github.com/pyenv/pyenv/pull/3515
* pyenv-binary: check patchelf early and add --verbose by @macayu17 in https://github.com/pyenv/pyenv/pull/3516
* CI: add ubuntu ARM images by @native-api in https://github.com/pyenv/pyenv/pull/3517
* Add CPython 3.10.21, 3.11.16, 3.12.14 by @pyenv-bot[bot] in https://github.com/pyenv/pyenv/pull/3518
* Add anaconda3-2026.07-1, miniconda3 26.5.3-2 by @native-api in https://github.com/pyenv/pyenv/pull/3519
## Release v2.8.3
* Add CPython 3.13.15, 3.14.7 by @pyenv-bot[bot] in https://github.com/pyenv/pyenv/pull/3512
## Release v2.8.2
* pyenv-binary: add the `package` subcommand; add `pyenv install --list --bare` by @macayu17 in https://github.com/pyenv/pyenv/pull/3498
* Add graalpy3.12-25.2.4 by @msimacek in https://github.com/pyenv/pyenv/pull/3502
* Bump actions/setup-python from 6 to 7 in the github-actions group by @dependabot[bot] in https://github.com/pyenv/pyenv/pull/3505
* add_cpython: refactor extra Requests logic by @anupamme in https://github.com/pyenv/pyenv/pull/3507
* Add CPython 3.15.0rc1 by @jsirois in https://github.com/pyenv/pyenv/pull/3510
* pyenv-binary: generate platform-specific package names by @macayu17 in https://github.com/pyenv/pyenv/pull/3504
## 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
* CVE-2026-68939: Fix handling of glob characters in .python-version
* 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
* rehash: fix race condition in landlock writability check by @Sheile in https://github.com/pyenv/pyenv/pull/3483 * rehash: fix race condition in landlock writability check by @Sheile in https://github.com/pyenv/pyenv/pull/3483
@ -383,7 +417,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 +1553,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

131
Makefile
View file

@ -1,16 +1,24 @@
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_LINK_DOCKER_PREFIX = test-link-docker
TEST_LINK_DOCKER_TARGETS = $(foreach bash,$(TEST_BASH_VERSIONS),$(addsuffix -$(bash),$(TEST_LINK_DOCKER_PREFIX)) $(addsuffix -gnu-$(bash),$(TEST_LINK_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) $(TEST_LINK_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 +39,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,10 +62,57 @@ $(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 $${CI:+-F "/code/test/libexec/bats-format-tap-suite"} \
$${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 $${CI:+-F "/code/test/libexec/bats-format-tap-suite"} \
$${BATS_TEST_FILTER:+--filter "$${BATS_TEST_FILTER}"} plugins/pyenv-binary/test/$${BATS_FILE_FILTER}
.PHONY: $(TEST_LINK_DOCKER_PREFIX)
$(TEST_LINK_DOCKER_PREFIX): $(TEST_LINK_DOCKER_TARGETS)
.PHONY: $(TEST_LINK_DOCKER_TARGETS)
$(TEST_LINK_DOCKER_TARGETS): DOCKER_IMAGE = $(TEST_BATS_IMAGE_PREFIX)
$(TEST_LINK_DOCKER_TARGETS): GNU = $(if $(findstring -gnu-,$@),True,False)
$(TEST_LINK_DOCKER_TARGETS): BASH = $(filter $(TEST_BASH_VERSIONS),$(subst -, ,$@))
$(TEST_LINK_DOCKER_TARGETS): DOCKER_TAG = bash-$(BASH)-gnu-$(GNU)
$(TEST_LINK_DOCKER_TARGETS): INTERACTIVE = $(if $(findstring true,$(CI)),,-ti)
$(TEST_LINK_DOCKER_TARGETS): $(TEST_LINK_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 $${CI:+-F "/code/test/libexec/bats-format-tap-suite"} \
$${BATS_TEST_FILTER:+--filter "$${BATS_TEST_FILTER}"} plugins/pyenv-link/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)
@ -71,7 +125,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 +133,38 @@ $(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 test-link
# 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-link
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:+-F "$(PWD)/test/libexec/bats-format-tap-suite"} \
$${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:+-F "$(PWD)/test/libexec/bats-format-tap-suite"} \
PYTHON_BUILD_VERSION ?= 3.8-dev $${BATS_TEST_FILTER:+--filter "$${BATS_TEST_FILTER}"} test/$${BATS_FILE_FILTER}
PYTHON_BUILD_TEST_PREFIX ?= $(PYTHON_BUILD_ROOT)/test/build/tmp/dist
test-build: test-link: bats
$(RM) -r $(PYTHON_BUILD_TEST_PREFIX) cd plugins/pyenv-link && $(PWD)/bats/bin/bats $${CI:+-F "$(PWD)/test/libexec/bats-format-tap-suite"} \
$(PYTHON_BUILD_ROOT)/bin/python-build $(PYTHON_BUILD_OPTS) $(PYTHON_BUILD_VERSION) $(PYTHON_BUILD_TEST_PREFIX) $${BATS_TEST_FILTER:+--filter "$${BATS_TEST_FILTER}"} test/$${BATS_FILE_FILTER}
[ -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

@ -13,6 +13,8 @@ This project was forked from [rbenv](https://github.com/rbenv/rbenv) and
* Lets you **change the global Python version** on a per-user basis. * Lets you **change the global Python version** on a per-user basis.
* Provides support for **per-project Python versions**. * Provides support for **per-project Python versions**.
* Supports **multiple Python distributions**: CPython, PyPy, Stackless Python, Jython, and more.
See the [full list of available versions](https://github.com/pyenv/pyenv/tree/master/plugins/python-build/share/python-build).
* Allows you to **override the Python version** with an environment * Allows you to **override the Python version** with an environment
variable. variable.
* Searches for commands from **multiple versions of Python at a time**. * Searches for commands from **multiple versions of Python at a time**.
@ -672,7 +674,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 +839,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.5"
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

@ -473,12 +473,12 @@ function pyenv {
} }
if ( ("${commands[*]}" -split ' ') -contains \$command ) { if ( ("${commands[*]}" -split ' ') -contains \$command ) {
\$shell_cmds = (& (get-command -commandtype application pyenv) sh-\$command \$args) \$shell_cmds = (& (get-command -commandtype application pyenv -totalcount 1) sh-\$command \$args)
if ( \$shell_cmds.Count -gt 0 ) { if ( \$shell_cmds.Count -gt 0 ) {
iex (\$shell_cmds -join "\`n") iex (\$shell_cmds -join "\`n")
} }
} else { } else {
& (get-command -commandtype application pyenv) \$command \$args & (get-command -commandtype application pyenv -totalcount 1) \$command \$args
} }
} }
EOS EOS

View file

@ -8,12 +8,28 @@ target_dir="$1"
find_local_version_file() { find_local_version_file() {
local root="$1" local root="$1"
while ! [[ "$root" =~ ^//[^/]*$ ]]; do # Nonexistent paths are UB as of this writing.
if [ -f "${root}/.python-version" ]; then # Relative ones cause a failure but absolute ones don't
echo "${root}/.python-version" [[ $root != /* ]] && root=$(CDPATH= cd -- "$root" && pwd)
# Original Rbenv code supports UNC notation for Cygwin/MinGW
# (https://github.com/rbenv/rbenv/pull/529)
# POSIX.1-2024 still allows to treat //<name> in implementation-specific manner
# (https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/V1_chap04.html#tag_04_16)
# even though few UNIX variants do that
local unc; [[ $root =~ ^//[^/] && ! / -ef // ]] && unc=1
root="${root%/}"
# when testing root, $root is ""
while true; do
# don't test //.python-version if // is special
# as it's pointless and possibly very slow
# if it e.g. leads to a network search
[[ $unc && $root == / ]] && break
if [[ -f $root/.python-version ]]; then
echo "$root/.python-version"
return 0 return 0
fi fi
[ -n "$root" ] || break [[ -n $root ]] || break
root="${root%/*}" root="${root%/*}"
done done
return 1 return 1
@ -22,7 +38,9 @@ find_local_version_file() {
if [ -n "$target_dir" ]; then if [ -n "$target_dir" ]; then
find_local_version_file "$target_dir" find_local_version_file "$target_dir"
else else
find_local_version_file "$PYENV_DIR" || { # In tests, PYENV_DIR is not set, ultimately leading to "cd: null directory" in OpenSUSE
# While most `cd` implementations treat an empty argument the same as missing, that's still wrong
find_local_version_file "${PYENV_DIR:=$PWD}" || {
[ "$PYENV_DIR" != "$PWD" ] && find_local_version_file "$PWD" [ "$PYENV_DIR" != "$PWD" ] && find_local_version_file "$PWD"
} || echo "${PYENV_ROOT}/version" } || echo "${PYENV_ROOT}/version"
fi fi

1
plugins/.gitignore vendored
View file

@ -3,4 +3,5 @@
!/version-ext-compat !/version-ext-compat
!/python-build !/python-build
!/pyenv-binary !/pyenv-binary
!/pyenv-link
/python-build/test/build /python-build/test/build

View file

@ -16,12 +16,79 @@ and dependency metadata exist to catch that.
## Commands ## Commands
### `pyenv binary save <version> [<output-dir>]` ### `pyenv binary package [-v|--verbose] <version>[:<entry>] --archive-base-url <url>`
Installs `<version>` from source under a separate name, packages that install
with `save`, then emits a python-build definition for it with
`generate-installer`. With no explicit entry, the name is generated from the
current platform, platform version and architecture. An explicit entry keeps
the existing custom-build workflow.
Pass `-v` to show build progress from `pyenv install`.
```sh
pyenv binary package 3.12.7 \
--archive-base-url https://example.com/binaries
# On Debian 12 x86_64, writes 3.12.7-debian-12-x86_64.tar.gz,
# its .meta file and a `3.12.7-debian-12-x86_64' definition.
pyenv binary package 3.12.7:company-python \
--archive-base-url https://example.com/binaries
```
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.
### `pyenv binary package-name <version>`
Prints the automatically generated entry name without building anything. Linux
uses the distribution name and version, macOS uses the macOS version, and other
systems use the name and release reported by `uname`. All names include the
architecture.
```sh
pyenv binary package-name 3.12.7
# 3.12.7-debian-12-x86_64
```
### `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,224 @@
#!/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 corresponding 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="" build_prefix="" 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" ;;
build_prefix ) build_prefix="$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
# Mach-O load commands contain the prefix where Python was built.
if [ "$os" = "Darwin" ] && [ -z "$build_prefix" ]; then
echo "pyenv-binary: metadata is missing \`build_prefix'" >&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 'BUILD_PREFIX=%q\n' "$build_prefix"
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. Linux lists
# the soname first; FreeBSD lists it in the resolved path, so normalize that
# path before matching exact names.
cache=""
if command -v ldconfig &>/dev/null; then
case "$os" in
FreeBSD )
cache="$(ldconfig -r 2>/dev/null)" &&
cache="$(printf '%s\n' "$cache" | awk -F ' *=> *' '{ sub(/^.*\//, "", $2); print $2 }')" \
|| cache=""
;;
* )
cache="$(ldconfig -p 2>/dev/null)" || cache=""
;;
esac
fi
if [ -n "$cache" ]; 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 cache unavailable)" >&2
fi
case "$os" in
Darwin )
for tool in otool install_name_tool; do
if ! command -v "$tool" >/dev/null 2>&1; then
echo "pyenv-binary: need ${tool} to relocate the binary" >&2
exit 1
fi
done
;;
* )
if ! command -v patchelf >/dev/null 2>&1; then
echo "pyenv-binary: need patchelf to relocate the binary" >&2
exit 1
fi
;;
esac
build_package_relocate() {
if [ "$os" = "Darwin" ]; then
pyenv binary relocate "$PREFIX_PATH" "$BUILD_PREFIX"
else
pyenv binary relocate "$PREFIX_PATH"
fi
}
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,83 @@
#!/usr/bin/env bash
#
# Summary: Create an installable binary package from a Python version
#
# Usage: pyenv binary package [-v|--verbose] <version>[:<entry>] --archive-base-url <url>
#
# Installs <version> from source under a separate entry name, 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 optional name to build under and install the
# binary as. If omitted, a name is generated from the
# current platform, platform version and architecture.
# -v,--verbose Show build progress from `pyenv install'.
# --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
echo --verbose
exec pyenv-install --list --bare
fi
spec=""
archive_base_url=""
verbose=""
while [ $# -gt 0 ]; do
case "$1" in
--archive-base-url )
[ $# -lt 2 ] && { echo "pyenv-binary: --archive-base-url needs a value" >&2; exit 1; }
archive_base_url="$2"; shift ;;
-v|--verbose)
verbose=1 ;;
-* )
echo "pyenv-binary: unknown option \`$1'" >&2; exit 1 ;;
* )
[ -z "$spec" ] || { echo "pyenv-binary: unexpected argument \`$1'" >&2; exit 1; }
spec="$1"
;;
esac
shift
done
if [ -z "$spec" ] || [ -z "$archive_base_url" ]; then
pyenv-help --usage binary-package >&2
exit 1
fi
case "$spec" in
*?:?* ) entry="${spec##*:}" ;;
* ) entry="$(pyenv-binary-package-name "$spec")"; spec="${spec}:${entry}" ;;
esac
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
# `pyenv install' puts a `<version>:<alias>' build under versions/<alias>.
pyenv-install ${verbose:+--verbose} "$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,73 @@
#!/usr/bin/env bash
#
# Summary: Generate a binary package name for the current platform
#
# Usage: pyenv binary package-name <version>
#
# Prints a package name containing the Python version, platform name,
# platform version and architecture.
#
set -e
[ -n "$PYENV_DEBUG" ] && set -x
if [ "$1" = "--complete" ]; then
exec pyenv-install --list --bare
fi
if [ $# -ne 1 ]; then
pyenv-help --usage binary-package-name >&2
exit 1
fi
version="$1"
case "$version" in
*/* | .. | . | *[[:cntrl:]]* )
echo "pyenv-binary: invalid version name \`${version}'" >&2
exit 1
;;
esac
version="$(pyenv-latest -f -k "$version")"
os="$(uname -s)"
arch="$(uname -m)"
distro=""
distro_version=""
case "$os" in
Linux )
if type -p lsb_release >/dev/null; then
distro="$(lsb_release -si)"
distro_version="$(lsb_release -sr)"
elif [ -r /etc/os-release ]; then
distro="$(. /etc/os-release && printf '%s' "${ID:-}")"
distro_version="$(. /etc/os-release && printf '%s' "${VERSION_ID:-}")"
fi
;;
Darwin )
distro="macos"
distro_version="$(sw_vers -productVersion)"
;;
* )
distro="$os"
distro_version="$(uname -r)"
;;
esac
slug() {
printf '%s' "$1" |
tr '[:upper:] ' '[:lower:]-' |
tr -cd 'a-z0-9._-'
}
distro="$(slug "$distro")"
distro_version="$(slug "$distro_version")"
arch="$(slug "$arch")"
if [ -z "$distro" ] || [ -z "$distro_version" ] || [ -z "$arch" ]; then
echo "pyenv-binary: could not determine the package platform" >&2
exit 1
fi
printf '%s-%s-%s-%s\n' "$version" "$distro" "$distro_version" "$arch"

View file

@ -0,0 +1,137 @@
#!/usr/bin/env bash
#
# Summary: Rewrite an unpacked Python's library paths so it runs from its prefix
#
# Usage: pyenv binary relocate <prefix> [<build-prefix>]
#
# Rewrites the library paths 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 on
# Linux and FreeBSD, or otool and install_name_tool on macOS.
#
# 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
if [ "$(uname -s)" = "Darwin" ]; then
build_prefix="${2%/}"
if [ -z "$build_prefix" ]; then
echo "pyenv-binary: need the original build prefix to relocate a macOS binary" >&2
exit 1
fi
for tool in otool install_name_tool; do
if ! command -v "$tool" >/dev/null 2>&1; then
echo "pyenv-binary: need ${tool} to relocate the binary" >&2
exit 1
fi
done
relocate_macho() {
local file="$1" new_rpath="$2"
local load_commands install_ids rpaths dependency install_id rpath replacement
load_commands="$(otool -L "$file")"
install_ids="$(otool -D "$file" 2>/dev/null || true)"
rpaths="$(otool -l "$file")"
install_id="$(printf '%s\n' "$install_ids" | sed -n '2s/^[[:space:]]*//p')"
while IFS= read -r dependency; do
case "$dependency" in
"$build_prefix"/lib/* )
if [ "$dependency" != "$install_id" ]; then
replacement="@rpath/${dependency#"$build_prefix"/lib/}"
install_name_tool -change "$dependency" "$replacement" "$file"
fi
;;
esac
done < <(printf '%s\n' "$load_commands" | tail -n +2 | sed -E \
's/^[[:space:]]*//; s/[[:space:]]+\(compatibility version.*$//')
case "$install_id" in
"$build_prefix"/lib/* )
replacement="@rpath/${install_id#"$build_prefix"/lib/}"
install_name_tool -id "$replacement" "$file"
;;
esac
while IFS= read -r rpath; do
if [ "$rpath" = "$build_prefix/lib" ]; then
install_name_tool -rpath "$rpath" "$new_rpath" "$file"
fi
done < <(printf '%s\n' "$rpaths" | awk '
/cmd LC_RPATH/ { found = 1; next }
found && /^[[:space:]]*path / {
sub(/^[[:space:]]*path /, "")
sub(/ \(offset [0-9]+\)$/, "")
print
found = 0
}
')
}
found=0
for file in "$prefix"/bin/*; do
[[ -f $file && -x $file && ! -L $file ]] || continue
otool -L "$file" >/dev/null 2>&1 || continue
relocate_macho "$file" '@executable_path/../lib'
found=1
done
if [ "$found" -eq 0 ]; then
echo "pyenv-binary: found no interpreter to relocate under \`${prefix}/bin'" >&2
exit 1
fi
for file in "$prefix"/lib/*.dylib; do
[[ -f $file && ! -L $file ]] || continue
relocate_macho "$file" '@loader_path'
done
while IFS= read -r so; do
relocate_macho "$so" '@loader_path/../..'
done < <(find "$prefix" -type f -path '*/lib/python*/lib-dynload/*.so')
exit
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
@ -59,12 +92,16 @@ fi
if [ "$os" = "Linux" ]; then if [ "$os" = "Linux" ]; then
libc="$(getconf GNU_LIBC_VERSION 2>/dev/null || true)" libc="$(getconf GNU_LIBC_VERSION 2>/dev/null || true)"
fi fi
if [ "$os" != "Darwin" ] && ! LC_ALL=C readelf --version &>/dev/null; then
echo "pyenv-binary: need readelf to inspect shared libraries" >&2
exit 1
fi
# List the external shared libraries the install links against: those that # List the external shared libraries the install links against: those that
# resolve outside its own prefix, so they must already exist on the target. # resolve outside its own prefix, so they must already exist on the target.
# The interpreter plus every bundled shared object are inspected. # The interpreter plus every bundled shared object are inspected.
system_deps() { system_deps() {
local f local f needed
{ {
for f in "${prefix}"/bin/python*; do for f in "${prefix}"/bin/python*; do
[ -e "$f" ] && printf '%s\n' "$f" [ -e "$f" ] && printf '%s\n' "$f"
@ -78,17 +115,29 @@ system_deps() {
otool -L "$f" 2>/dev/null | tail -n +2 | awk -v pfx="${prefix}/" \ otool -L "$f" 2>/dev/null | tail -n +2 | awk -v pfx="${prefix}/" \
'$1 !~ /^@/ && substr($1, 1, length(pfx)) != pfx { print $1 }' '$1 !~ /^@/ && substr($1, 1, length(pfx)) != pfx { print $1 }'
else else
ldd "$f" 2>/dev/null | awk -v pfx="${prefix}/" \ # GNU binutils 2.44 writes "(NEEDED) ... [name]"; FreeBSD 15.1 writes
'$2 == "=>" && $3 ~ /^\// && substr($3, 1, length(pfx)) != pfx { print $1 }' # "NEEDED ... [name]". readelf(1) documents -d, not its text format.
needed="$(LC_ALL=C readelf -dW "$f" 2>/dev/null | awk \
'$2 == "(NEEDED)" || $2 == "NEEDED" { sub(/^.*\[/, ""); sub(/\].*$/, ""); print }' | tr '\n' ' ')"
# Linux and FreeBSD ldd write resolved libraries as
# "name => /absolute/path (address)"; entries without "=>" are ignored.
LC_ALL=C ldd "$f" 2>/dev/null | awk -v needed="$needed" -v pfx="${prefix}/" '
BEGIN {
split(needed, deps, " ")
for (i in deps) direct[deps[i]] = 1
}
$1 in direct && $2 == "=>" && $3 ~ /^\// && substr($3, 1, length(pfx)) != pfx { print $1 }
'
fi fi
done | sort -u done | sort -u
} }
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"
@ -98,6 +147,7 @@ tar -C "$prefix" -czf "${output_dir}/${archive}" .
echo "platform=${platform}" echo "platform=${platform}"
[ -n "$distro" ] && echo "distro=${distro}" [ -n "$distro" ] && echo "distro=${distro}"
[ -n "$libc" ] && echo "libc=${libc}" [ -n "$libc" ] && echo "libc=${libc}"
echo "build_prefix=${prefix}"
echo "archive=${archive}" echo "archive=${archive}"
system_deps | while IFS= read -r dep; do system_deps | while IFS= read -r dep; do
[ -n "$dep" ] && echo "dep=${dep}" [ -n "$dep" ] && echo "dep=${dep}"

View file

@ -0,0 +1,212 @@
#!/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 build_prefix="${4-}"
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}"
[ -z "$build_prefix" ] || echo "build_prefix=${build_prefix}"
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 "fails when macOS metadata is missing the build prefix" {
run pyenv-binary-generate-installer "$(create_meta Darwin arm64 '')" \
--archive-url http://x/a.tar.gz
assert_failure "pyenv-binary: metadata is missing \`build_prefix'"
}
@test "quotes the macOS build prefix in the generated definition" {
local out="${BATS_TEST_TMPDIR}/definition"
pyenv-binary-generate-installer \
"$(create_meta Darwin arm64 '' '/build prefix/$name')" \
--archive-url http://example.com/a.tar.gz -o "$out"
run grep '^BUILD_PREFIX=' "$out"
assert_success 'BUILD_PREFIX=/build\ prefix/\$name'
}
@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 "checks required libraries in the FreeBSD ldconfig cache" {
local out="${BATS_TEST_TMPDIR}/definition"
local meta="$(create_meta FreeBSD amd64 '')"
printf 'dep=libc.so.7\ndep=libmissing.so.1\n' >> "$meta"
pyenv-binary-generate-installer "$meta" \
--archive-url http://example.com/a.tar.gz -o "$out"
create_stub uname 'case "$1" in -s) echo FreeBSD;; -m) echo amd64;; esac'
create_stub ldconfig '[ "$1" = "-r" ] && echo "0:-lc.7=>/lib/libc.so.7"'
run bash "$out"
assert_failure "pyenv-binary: missing required system libraries: libmissing.so.1"
}
@test "checks for patchelf before installing the archive" {
local out="${BATS_TEST_TMPDIR}/definition"
pyenv-binary-generate-installer "$(create_meta)" \
--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"'
PATH="$(path_without patchelf)" run bash "$out"
assert_failure "pyenv-binary: need patchelf to relocate the binary"
}
@test "checks for otool before installing a macOS archive" {
local out="${BATS_TEST_TMPDIR}/definition"
pyenv-binary-generate-installer \
"$(create_meta Darwin arm64 '' /build/3.12.7)" \
--archive-url http://example.com/a.tar.gz -o "$out"
create_stub uname 'case "$1" in -s) echo Darwin;; -m) echo arm64;; esac'
create_path_executable install_name_tool true
PATH="$(path_without otool)" run bash "$out"
assert_failure "pyenv-binary: need otool to relocate the binary"
}
@test "checks for install_name_tool before installing a macOS archive" {
local out="${BATS_TEST_TMPDIR}/definition"
pyenv-binary-generate-installer \
"$(create_meta Darwin arm64 '' /build/3.12.7)" \
--archive-url http://example.com/a.tar.gz -o "$out"
create_stub uname 'case "$1" in -s) echo Darwin;; -m) echo arm64;; esac'
create_path_executable otool true
PATH="$(path_without install_name_tool)" run bash "$out"
assert_failure "pyenv-binary: need install_name_tool to relocate the binary"
}
@test "the generated macOS definition preserves both relocation arguments" {
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 Darwin arm64 '' '/build prefix/$name')" \
--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 'printf "argc=%s\narg1=%s\narg2=%s\narg3=%s\narg4=%s\n" "$#" "$1" "$2" "$3" "$4"'
create_stub uname 'case "$1" in -s) echo Darwin;; -m) echo arm64;; esac'
create_stub sw_vers 'echo 15.5'
create_stub ldconfig true
create_path_executable otool true
create_path_executable install_name_tool true
PYTHON_BUILD_CACHE_PATH="$cache" run \
"${BATS_TEST_DIRNAME}/../../python-build/bin/python-build" "$definition" "$prefix"
assert_success
assert_line "argc=4"
assert_line "arg1=binary"
assert_line "arg2=relocate"
assert_line "arg3=${prefix}"
assert_line 'arg4=/build prefix/$name'
assert_line "Installed Python-3.12.7-binary to ${prefix}"
}
@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_path_executable patchelf "exit 0"
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,59 @@
#!/usr/bin/env bats
load test_helper
_setup() {
create_stub pyenv-latest '[ "$1" = "-f" ] && [ "$2" = "-k" ] && shift 2 && echo "$*"'
}
@test "completion lists installable versions" {
create_stub pyenv-install \
'[ "$*" = "--list --bare" ] && echo 3.13.14'
run pyenv-binary-package-name --complete
assert_success "3.13.14"
}
@test "fails without a version" {
create_stub pyenv-help 'echo usage'
run pyenv-binary-package-name
assert_failure "usage"
}
@test "rejects a second argument" {
create_stub pyenv-help 'echo usage'
run pyenv-binary-package-name 3.13.14 extra
assert_failure "usage"
}
@test "generates a package name for Linux" {
create_stub uname 'case "$1" in -s) echo Linux;; -m) echo x86_64;; esac'
create_stub lsb_release 'case "$1" in -si) echo Debian;; -sr) echo 12;; esac'
run pyenv-binary-package-name 3.13.14
assert_success "3.13.14-debian-12-x86_64"
}
@test "generates a package name for macOS" {
create_stub uname 'case "$1" in -s) echo Darwin;; -m) echo arm64;; esac'
create_stub sw_vers 'echo 15.5'
run pyenv-binary-package-name 3.13.14
assert_success "3.13.14-macos-15.5-arm64"
}
@test "resolves a version prefix when generating a package name" {
create_stub pyenv-latest '[ "$*" = "-f -k 3" ] && echo 3.14.7'
create_stub uname \
'case "$1" in -s) echo FreeBSD;; -m) echo amd64;; -r) echo 14.2-RELEASE-p3;; esac'
run pyenv-binary-package-name 3
assert_success "3.14.7-freebsd-14.2-release-p3-amd64"
}
@test "rejects an invalid version name" {
run pyenv-binary-package-name ../3.13.14
assert_failure "pyenv-binary: invalid version name \`../3.13.14'"
}

View file

@ -0,0 +1,131 @@
#!/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 'echo "${0##*/} $*"; mkdir -p "${PYENV_ROOT}/versions/${1##*:}/bin"'
create_stub pyenv-latest 'while (($#)); do case "$1" in -f|-k);; *)break;; esac; shift; done; echo "$*"'
create_stub uname 'case "$1" in -s) echo Linux;; -m) echo x86_64;; esac'
create_stub getconf 'echo "glibc 2.17"'
create_stub readelf true
}
@test "-v|--verbose runs pyenv install verbosely" {
stub_build_environment
create_stub pyenv-binary-save true
create_stub pyenv-binary-generate-installer true
for opt in "" -v --verbose; do
run pyenv-binary-package $opt 3.12.7:3.12.7-test \
--archive-base-url http://example.com/binaries
assert_success "pyenv-install ${opt:+--verbose }3.12.7:3.12.7-test"
done
}
@test "completions" {
create_stub pyenv-install 'echo "${0##*/} $*"'
run pyenv-binary-package --complete
assert_success <<!
--archive-base-url
--verbose
pyenv-install --list --bare
!
}
@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 "generates an entry name for a bare version" {
stub_build_environment
create_stub lsb_release 'case "$1" in -si) echo Debian;; -sr) echo 12;; esac'
cd "${BATS_TEST_TMPDIR}"
run pyenv-binary-package 3.12.7 --archive-base-url http://example.com/binaries
assert_success
assert [ -d "${PYENV_ROOT}/versions/3.12.7-debian-12-x86_64" ]
assert [ -f "${BATS_TEST_TMPDIR}/3.12.7-debian-12-x86_64.tar.gz" ]
assert [ -f "${BATS_TEST_TMPDIR}/3.12.7-debian-12-x86_64.meta" ]
run grep '^ARCHIVE_URL=' "${BATS_TEST_TMPDIR}/3.12.7-debian-12-x86_64"
assert_success "ARCHIVE_URL=http://example.com/binaries/3.12.7-debian-12-x86_64.tar.gz"
}
@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 "packages on macOS" {
create_stub uname 'case "$1" in -s) echo Darwin;; -m) echo arm64;; esac'
create_stub pyenv-install 'echo install'
create_stub pyenv-binary-save 'echo save'
create_stub pyenv-binary-generate-installer 'echo generate-installer'
run pyenv-binary-package 3.12.7:3.12.7-test --archive-base-url http://x/b
assert_success "install
save
generate-installer"
}
@test "writes the archive, metadata and definition under the entry name (integration)" {
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 "correctly joins archive base url with a trailing slash" {
stub_build_environment
create_stub pyenv-binary-save true
create_stub pyenv-binary-generate-installer <<'!'
echo -n "${0##*/} "
while (($#)); do
case $1 in
--archive-url)
echo "$1 ${2:?}"
break
;;
esac
shift
done
!
run pyenv-binary-package 3.12.7:3.12.7-test \
--archive-base-url http://example.com/binaries/
assert_success
assert_line "pyenv-binary-generate-installer --archive-url http://example.com/binaries/3.12.7-test.tar.gz"
}

View file

@ -0,0 +1,221 @@
#!/usr/bin/env bats
load test_helper
_setup() {
create_stub pyenv-help "echo usage"
create_stub uname 'case "$1" in -s) echo Linux;; -m) echo x86_64;; esac'
}
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"
}
create_macos_tree() {
local prefix="${BATS_TEST_TMPDIR}/prefix"
local lib="${prefix}/lib/python3.12"
mkdir -p "${prefix}/bin" "${lib}/lib-dynload" "${lib}/site-packages/numpy"
printf '#!/bin/sh\n' > "${prefix}/bin/python3.12"
chmod +x "${prefix}/bin/python3.12"
touch "${prefix}/lib/libpython3.12.dylib"
touch "${lib}/lib-dynload/_ssl.cpython-312-darwin.so"
touch "${lib}/site-packages/numpy/_multiarray.so"
}
stub_macos_tools() {
create_stub uname 'case "$1" in -s) echo Darwin;; -m) echo arm64;; esac'
create_path_executable install_name_tool \
'echo "$*" >> "${BATS_TEST_TMPDIR}/install-name-tool.log"'
create_path_executable otool <<'STUB'
file="${!#}"
echo "$*" >> "${BATS_TEST_TMPDIR}/otool.log"
old="/build prefix/3.12.7"
case "$1" in
-L )
echo "${file}:"
case "$file" in
*/bin/python3.12 )
if [ -n "$OTOOL_RELOCATED" ]; then
echo " @rpath/libpython3.12.dylib (compatibility version 3.12.0, current version 3.12.0)"
else
echo " ${old}/lib/libpython3.12.dylib (compatibility version 3.12.0, current version 3.12.0)"
fi
echo " ${old}-other/lib/libother.dylib (compatibility version 1.0.0, current version 1.0.0)"
echo " /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1.0.0)"
echo " /opt/homebrew/lib/libintl.8.dylib (compatibility version 1.0.0, current version 1.0.0)"
echo " @loader_path/liblocal.dylib (compatibility version 1.0.0, current version 1.0.0)"
;;
*/lib/libpython3.12.dylib )
if [ -n "$OTOOL_RELOCATED" ]; then
echo " @rpath/libpython3.12.dylib (compatibility version 3.12.0, current version 3.12.0)"
else
echo " ${old}/lib/libpython3.12.dylib (compatibility version 3.12.0, current version 3.12.0)"
fi
;;
esac
;;
-D )
case "$file" in
*/lib/libpython3.12.dylib )
echo "${file}:"
if [ -n "$OTOOL_RELOCATED" ]; then
echo '@rpath/libpython3.12.dylib'
else
echo "${old}/lib/libpython3.12.dylib"
fi
;;
* )
exit 1
;;
esac
;;
-l )
if [ -n "$OTOOL_RELOCATED" ]; then
case "$file" in
*/bin/* ) rpath='@executable_path/../lib' ;;
*/lib/*.dylib ) rpath='@loader_path' ;;
* ) rpath='@loader_path/../..' ;;
esac
else
rpath="${old}/lib"
fi
cat <<EOF
cmd LC_RPATH
path ${rpath} (offset 12)
cmd LC_RPATH
path /opt/homebrew/lib (offset 12)
cmd LC_RPATH
path @loader_path/vendor (offset 12)
EOF
;;
esac
STUB
}
@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 without the original build prefix on macOS" {
create_stub uname 'case "$1" in -s) echo Darwin;; -m) echo arm64;; esac'
run pyenv-binary-relocate "${BATS_TEST_TMPDIR}/prefix"
assert_failure "pyenv-binary: need the original build prefix to relocate a macOS binary"
}
@test "fails when otool is not available on macOS" {
create_stub uname 'case "$1" in -s) echo Darwin;; -m) echo arm64;; esac'
create_path_executable install_name_tool true
PATH="$(path_without otool)" run \
pyenv-binary-relocate "${BATS_TEST_TMPDIR}/prefix" /build/3.12.7
assert_failure "pyenv-binary: need otool to relocate the binary"
}
@test "fails when install_name_tool is not available on macOS" {
create_stub uname 'case "$1" in -s) echo Darwin;; -m) echo arm64;; esac'
create_path_executable otool true
PATH="$(path_without install_name_tool)" run \
pyenv-binary-relocate "${BATS_TEST_TMPDIR}/prefix" /build/3.12.7
assert_failure "pyenv-binary: need install_name_tool 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"
}
@test "relocates macOS load commands without changing unrelated entries" {
local prefix="${BATS_TEST_TMPDIR}/prefix"
local old="/build prefix/3.12.7"
local lib="${prefix}/lib/python3.12"
create_macos_tree
stub_macos_tools
run pyenv-binary-relocate "$prefix" "$old"
assert_success
run cat "${BATS_TEST_TMPDIR}/install-name-tool.log"
assert_output <<EOF
-change ${old}/lib/libpython3.12.dylib @rpath/libpython3.12.dylib ${prefix}/bin/python3.12
-rpath ${old}/lib @executable_path/../lib ${prefix}/bin/python3.12
-id @rpath/libpython3.12.dylib ${prefix}/lib/libpython3.12.dylib
-rpath ${old}/lib @loader_path ${prefix}/lib/libpython3.12.dylib
-rpath ${old}/lib @loader_path/../.. ${lib}/lib-dynload/_ssl.cpython-312-darwin.so
EOF
run grep -F "${lib}/site-packages/numpy/_multiarray.so" "${BATS_TEST_TMPDIR}/otool.log"
assert_failure
}
@test "skips already relocated macOS load commands" {
local prefix="${BATS_TEST_TMPDIR}/prefix"
create_macos_tree
stub_macos_tools
export OTOOL_RELOCATED=1
run pyenv-binary-relocate "$prefix" "/build prefix/3.12.7"
assert_success
assert [ ! -e "${BATS_TEST_TMPDIR}/install-name-tool.log" ]
}
@test "fails when install_name_tool cannot modify a selected file" {
local prefix="${BATS_TEST_TMPDIR}/prefix"
create_macos_tree
stub_macos_tools
create_path_executable install_name_tool 'exit 1'
run pyenv-binary-relocate "$prefix" "/build prefix/3.12.7"
assert_failure ""
}

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,80 @@ 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. @test "records the original installation prefix" {
stub() { create_version "3.12.7"
local name="$1" local out="${BATS_TEST_TMPDIR}/dist"
local dir="${BATS_TEST_TMPDIR}/stubs" pyenv-binary-save "3.12.7" "$out" >/dev/null
mkdir -p "$dir"
{ echo "#!/usr/bin/env bash"; cat -; } > "${dir}/${name}" run grep '^build_prefix=' "${out}/3.12.7-$(platform).meta"
chmod +x "${dir}/${name}" assert_success "build_prefix=${PYENV_ROOT}/versions/3.12.7"
export PATH="${dir}:$PATH"
} }
@test "records only the libraries ldd resolves outside the prefix" { @test "fails when readelf is not available" {
create_version "3.12.7"
create_stub uname 'case "$1" in -s) echo Linux;; -m) echo x86_64;; esac'
PATH="$(path_without readelf)" run pyenv-binary-save "3.12.7" "${BATS_TEST_TMPDIR}/dist"
assert_failure "pyenv-binary: need readelf to inspect shared libraries"
assert [ ! -e "${BATS_TEST_TMPDIR}/dist/3.12.7-$(platform).tar.gz" ]
}
@test "records only direct libraries resolved 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)
@ -75,31 +115,30 @@ cat <<EOF
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f4a3b800000) libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f4a3b800000)
/lib64/ld-linux-x86-64.so.2 (0x00007f4a3c200000) /lib64/ld-linux-x86-64.so.2 (0x00007f4a3c200000)
EOF EOF
STUB
create_path_executable readelf <<'STUB'
cat <<EOF
0x0000000000000001 (NEEDED) Shared library: [libpython3.12.so.1.0]
0x0000000000000001 (NEEDED) Shared library: [libm.so.6]
EOF
STUB 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=libm.so.6"
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 +150,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

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2023 yfprojects
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.

View file

@ -0,0 +1,33 @@
# pyenv-link
A [pyenv](https://github.com/pyenv/pyenv) plugin for linking Python installations and virtual environments into your pyenv root.
This plugin recommends the [pyenv-virtualenv](https://github.com/pyenv/pyenv-virtualenv/) plugin.
## Usage
Make an arbitrary virtualenv available through pyenv. This automatically guesses a fitting name from the prompt, the directory name or the location of the venv.
```console
$ pyenv link version .venv
Linked new version named myproject
```
You can also specify a name to use for the venv.
```console
$ pyenv link version .venv myname
Linked new version named myname
```
The same command can give a platform-specific binary installation a shorter name:
```console
$ pyenv link version "$(pyenv root)/versions/3.13.14-linux-x86_64" 3.13.14
Linked new version named 3.13.14
```
Now you can make pyenv activate/use the venv automatically:
```console
$ pyenv local myproject
```

View file

@ -0,0 +1,34 @@
#!/usr/bin/env bash
#
# Summary: Link a Python environment as a pyenv version
#
# Usage: pyenv link version [--dry] [--quiet] <path> [<name>]
#
# Link a virtual python environment to pyenvs version directory
# so that the venv can be used like one created with *pyenv-virtualenv*.
#
# <path> should be a path to a Python installation or virtual environment.
set -e
[ -n "$PYENV_DEBUG" ] && set -x
# Provide pyenv completions
case "$1" in
--complete)
if [ -z "$2" ]; then
echo version
else
shift 2
pyenv-link-version --complete "$@"
fi
;;
version)
shift
pyenv-link-version "$@"
exit $?
;;
*)
pyenv-help --usage link >&2
exit 1
;;
esac

View file

@ -0,0 +1,150 @@
#!/usr/bin/env bash
#
# Summary: Link a Python environment as a pyenv version
#
# Usage: pyenv link version [--dry] [--quiet] <path> [<name>]
#
# Link a virtual python environment to pyenvs version directory
# so that the venv can be used like one created with *pyenv-virtualenv*.
#
# <path> should be a path to a Python installation or virtual environment.
# <name> should be string used as a version name it may not be present
# in the pyenv version directory yet.
# If not specified a matching name is guessed from pyvenv.cfg
# or directory name of the venv.
set -e
[ -n "$PYENV_DEBUG" ] && set -x
# functions
if ! {
enable -f "${BASH_SOURCE%/*}"/../../../libexec/pyenv-realpath.dylib realpath ||
type realpath # realpath available?
} >/dev/null 2>&1; then
# realpath requires GNU coreutils to be installed. That's why its bundled with pyenv
echo realpath not available >&2
# work-around when realpath is unavailable
realpath() {
(cd "$1" && pwd)
}
fi
guess_name() {
local venv_dir=$1
local name
# guess venv name from pyvenv.cfg
local pyvenv_cfg_path=$venv_dir/pyvenv.cfg
if [ -f "$pyvenv_cfg_path" ]; then
# if `prompt` key wasn't found the var remains empty
name=$(cut -b 1-1024 "$pyvenv_cfg_path" | sed -n '/^ *prompt *= */s///p')
case "$name" in
\"*\" | \'*\')
name=${name:1:${#name}-2}
;;
esac
fi
# guess venv name from name of venv directory
local venv_dir_name=${venv_dir##*/}
if [ -z "$name" ]; then
case "$venv_dir_name" in
venv | env | .venv | .env | ENV | VENV) ;;
*) name=$venv_dir_name ;;
esac
fi
# guess venv name from name of the parent directory of the venv directory
local venv_dir_parent=${venv_dir%/*}
local venv_dir_parent_name=${venv_dir_parent##*/}
if [ -z "$name" ]; then
name=$venv_dir_parent_name
fi
echo "$name"
}
# process args
POSARGS=()
# Provide pyenv completions
if [ "$1" = "--complete" ]; then
echo --dry
echo --quiet
exit
fi
for arg in "$@"; do
case $arg in
--dry)
dry=true # any value
;;
--quiet)
quiet=true # any value
;;
-*)
pyenv-help --usage link-version >&2
exit 1
;;
*)
POSARGS+=("$arg")
;;
esac
done
if [ ! ${#POSARGS[@]} -le 2 ] || [ ! ${#POSARGS[@]} -ge 1 ]; then
pyenv-help --usage link-version >&2
exit 1
fi
venv_dir=${POSARGS[0]%/}
venv_name=${POSARGS[1]}
# Check venv exists
if [ ! -d "$venv_dir" ]; then
echo "The virtual env you specified doesn't exist"
exit 2
fi
# make venv dir absolute
venv_dir=$(realpath "$venv_dir")
# determine venv name
if [ -z "$venv_name" ]; then
venv_name=$(guess_name "$venv_dir")
fi
case "$venv_name" in
"" | */* | . | .. | *:* | system | *[[:cntrl:]]* )
echo "pyenv-link: invalid version name \`${venv_name}'" >&2
exit 1
;;
esac
versions_dir="$PYENV_ROOT/versions"
pyenv_prefix_path="$versions_dir/$venv_name"
if [ -e "$pyenv_prefix_path" ] || [ -L "$pyenv_prefix_path" ]; then
echo Version "$venv_name" already exists >&2
exit 3
fi
case "$venv_dir" in
"$versions_dir"/*)
link_target=${venv_dir#"$versions_dir"/}
;;
*)
link_target=$venv_dir
;;
esac
# link to pyenv version directory
if [ -z "$dry" ]; then
mkdir -p "$versions_dir"
ln -s "$link_target" "$pyenv_prefix_path"
fi
# output
if [ -z "$quiet" ]; then
echo "Linked new version named $venv_name"
fi

View file

@ -0,0 +1,61 @@
#!/usr/bin/env bats
load test_helper
@test "link completions use the dispatcher" {
run pyenv completions link
assert_success
assert_output <<OUT
--help
version
OUT
run pyenv completions link version
assert_success
assert_output <<OUT
--help
--dry
--quiet
OUT
}
@test "link requires a version path" {
run pyenv-link version
assert_failure "Usage: pyenv link version [--dry] [--quiet] <path> [<name>]"
}
@test "links an installed binary under its plain version name" {
create_alt_executable_in_version "3.13.14-linux-x86_64" python 'echo linked-python'
run pyenv-link version "$PYENV_ROOT/versions/3.13.14-linux-x86_64" 3.13.14
assert_success "Linked new version named 3.13.14"
assert_equal "3.13.14-linux-x86_64" "$(readlink "$PYENV_ROOT/versions/3.13.14")"
PYENV_VERSION=3.13.14 run pyenv exec python
assert_success "linked-python"
}
@test "links external paths containing spaces into a fresh root" {
mkdir -p "$PYENV_TEST_DIR/external env/bin"
run pyenv-link version "$PYENV_TEST_DIR/external env" custom
assert_success "Linked new version named custom"
assert_equal "$PYENV_TEST_DIR/external env" "$(readlink "$PYENV_ROOT/versions/custom")"
}
@test "refuses a dangling destination link" {
mkdir -p "$PYENV_ROOT/versions" "$PYENV_TEST_DIR/source"
ln -s missing "$PYENV_ROOT/versions/dangling"
run pyenv-link version "$PYENV_TEST_DIR/source" dangling
assert_failure "Version dangling already exists"
assert_equal missing "$(readlink "$PYENV_ROOT/versions/dangling")"
}
@test "rejects invalid version names" {
mkdir -p "$PYENV_TEST_DIR/source"
for name in ../outside . .. 'foo/bar' 'foo:bar' system; do
run pyenv-link version "$PYENV_TEST_DIR/source" "$name"
assert_failure "pyenv-link: invalid version name \`$name'"
assert [ ! -e "$PYENV_ROOT/outside" ]
done
echo "prompt = '../outside'" > "$PYENV_TEST_DIR/source/pyvenv.cfg"
run pyenv-link version "$PYENV_TEST_DIR/source"
assert_failure "pyenv-link: invalid version name \`../outside'"
assert [ ! -e "$PYENV_ROOT/outside" ]
}

View file

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

View file

@ -54,8 +54,11 @@ Or, if you would like to install the latest development release:
## Usage ## Usage
Before you begin, you should ensure that your build environment has the proper On Ubuntu, Debian, and Mint, install the recommended build dependencies with:
system dependencies for compiling the wanted Python Version (see our [recommendations](https://github.com/pyenv/pyenv/wiki#suggested-build-environment)).
pyenv install-prerequisites
For other environments, see our [build environment recommendations](https://github.com/pyenv/pyenv/wiki#suggested-build-environment).
### Using `pyenv install` with pyenv ### Using `pyenv install` with pyenv
@ -361,4 +364,3 @@ git diff --name-only master \
- Filter out any which don't live where python-build keeps its build scripts - Filter out any which don't live where python-build keeps its build scripts
- Look only at the file name (i.e. the python version name) - Look only at the file name (i.e. the python version name)
- Run a new docker container for each, building that version - Run a new docker container for each, building that version

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

@ -0,0 +1,47 @@
#!/usr/bin/env bash
#
# Summary: Install Python build prerequisites on Debian-based systems
#
# Usage: pyenv install-prerequisites
#
set -e
[ -n "$PYENV_DEBUG" ] && set -x
# Provide pyenv completions
if [ "$1" = "--complete" ]; then
exit
fi
usage() {
pyenv-help install-prerequisites 2>/dev/null
[ -z "$1" ] || exit "$1"
}
if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
usage 0
fi
[ "$#" -eq 0 ] || usage 1 >&2
if ! command -v apt-get >/dev/null; then
echo "pyenv: installing build prerequisites is not supported on this system" >&2
exit 1
fi
prerequisites=(
make build-essential libssl-dev zlib1g-dev libbz2-dev libreadline-dev
libsqlite3-dev curl git llvm libncurses5-dev libncursesw5-dev xz-utils
tk-dev libxml2-dev libxmlsec1-dev libffi-dev liblzma-dev libzstd-dev
)
if [ "$(id -u)" -eq 0 ]; then
apt_get=(apt-get)
elif command -v sudo >/dev/null; then
apt_get=(sudo apt-get)
else
echo "pyenv: sudo is required to install build prerequisites" >&2
exit 1
fi
"${apt_get[@]}" update -q
"${apt_get[@]}" install -yq "${prerequisites[@]}"

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.5"
OLDIFS="$IFS" OLDIFS="$IFS"

View file

@ -542,8 +542,7 @@ class OpenSSLVersionsDirectory(KeyedList[_OpenSSLVersionInfo, packaging.version.
url = "https://api.github.com/repos/openssl/openssl/releases" url = "https://api.github.com/repos/openssl/openssl/releases"
while url: while url:
response = requests.get(url, timeout=30) response = Requests.get(url)
response.raise_for_status()
matching = [ matching = [
release release
for release in response.json() for release in response.json()
@ -568,7 +567,7 @@ class OpenSSLVersionsDirectory(KeyedList[_OpenSSLVersionInfo, packaging.version.
for asset in j_release['assets'] for asset in j_release['assets']
if urllib.parse.urlparse(asset['browser_download_url']).path.split('/')[-1].endswith('.sha256') if urllib.parse.urlparse(asset['browser_download_url']).path.split('/')[-1].endswith('.sha256')
) )
shasum_text = requests.get(shasum_url, timeout=30).text shasum_text = Requests.get(shasum_url).text
shasum_data = jc.parse("hashsum", shasum_text, quiet=True)[0] shasum_data = jc.parse("hashsum", shasum_text, quiet=True)[0]
package_hash, package_filename = shasum_data["hash"], shasum_data["filename"] package_hash, package_filename = shasum_data["hash"], shasum_data["filename"]
del shasum_data, shasum_text, shasum_url del shasum_data, shasum_text, shasum_url
@ -742,6 +741,13 @@ class Url:
h.update(c) h.update(c)
return h.hexdigest() return h.hexdigest()
class Requests:
@staticmethod
def get(url: str) -> requests.Response:
response = requests.get(url, timeout=30)
response.raise_for_status()
return response
if __name__ == "__main__": if __name__ == "__main__":
#sys.excepthook seems to have no effect in Github Actions #sys.excepthook seems to have no effect in Github Actions

View file

@ -219,7 +219,10 @@ class CondaVersion(NamedTuple):
# since 4.8, Miniconda specifies versions explicitly in the file name # since 4.8, Miniconda specifies versions explicitly in the file name
raise ValueError("Miniconda 4.8+ is supposed to specify a Python version explicitly") raise ValueError("Miniconda 4.8+ is supposed to specify a Python version explicitly")
if self.flavor == "anaconda": if self.flavor == "anaconda":
# https://www.anaconda.com/docs/tools/anaconda-org/release-notes # Info about the bundled Python version
# https://www.anaconda.com/docs/getting-started/anaconda/release-notes
if v >= (2026,7):
return PyVersion.PY314
if v >= (2025,6): if v >= (2025,6):
return PyVersion.PY313 return PyVersion.PY313
if v >= (2024,6): if v >= (2024,6):

View file

@ -1,6 +1,7 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
'Adds the latest miniforge and mambaforge releases.' 'Adds the latest miniforge and mambaforge releases.'
from pathlib import Path from pathlib import Path
import argparse
import logging import logging
import os import os
import string import string
@ -8,7 +9,7 @@ import string
import requests import requests
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
logging.basicConfig(level=os.environ.get('LOGLEVEL', 'INFO')) logging.basicConfig(level=logging.INFO)
MINIFORGE_REPO = 'conda-forge/miniforge' MINIFORGE_REPO = 'conda-forge/miniforge'
DISTRIBUTIONS = ['miniforge'] DISTRIBUTIONS = ['miniforge']
@ -21,6 +22,8 @@ SKIPPED_RELEASES = [
'22.11.1-2', #MacOS packages are broken (have broken dep tarballs, downloading them fails with 403) '22.11.1-2', #MacOS packages are broken (have broken dep tarballs, downloading them fails with 403)
'25.3.0-0', #marked as prerelease, no Linux version '25.3.0-0', #marked as prerelease, no Linux version
'25.11.0-0', #regression reported in constructor, re-released as 25.11.0-1 with hotfix bumping to constructor>=3.14 (was >=3.12, 3.13 implicit) '25.11.0-0', #regression reported in constructor, re-released as 25.11.0-1 with hotfix bumping to constructor>=3.14 (was >=3.12, 3.13 implicit)
'26.1.1-0', #prerelease, no binary assets
'26.1.1-1', #prerelease, no binary assets
] ]
install_script_fmt = """ install_script_fmt = """
@ -136,7 +139,7 @@ def main():
if version in SKIPPED_RELEASES: if version in SKIPPED_RELEASES:
continue continue
logger.info(f'Looking for {version} in {out_dir}') logger.debug(f'Looking for {version} in {out_dir}')
# mambaforge is retired https://github.com/conda-forge/miniforge/releases/tag/24.11.2-0 # mambaforge is retired https://github.com/conda-forge/miniforge/releases/tag/24.11.2-0
if version_tuple(version) >= (24, 11, 2): if version_tuple(version) >= (24, 11, 2):
@ -149,4 +152,17 @@ def main():
add_version(release, distributions) add_version(release, distributions)
if __name__ == '__main__': if __name__ == '__main__':
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument(
"-d", "--dry-run", action="store_true",
help="Do not write scripts, just report them to stdout",
)
parser.add_argument(
"-v", "--verbose", action="store_true", default=0,
help="Increase verbosity of logging",
)
parsed = parser.parse_args()
if parsed.verbose: logging.getLogger.setLevel(logging.DEBUG)
main() main()

View file

@ -0,0 +1,9 @@
prefer_openssl3
export PYTHON_BUILD_CONFIGURE_WITH_OPENSSL=1
install_package "openssl-3.6.3" "https://github.com/openssl/openssl/releases/download/openssl-3.6.3/openssl-3.6.3.tar.gz#243a86649cf6f23eeb6a2ff2456e09e5d77dd9018a54d3d96b0c6bdd6ba6c7f1" 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
if has_tar_xz_support; then
install_package "Python-3.10.21" "https://www.python.org/ftp/python/3.10.21/Python-3.10.21.tar.xz#a0da1e72132e950154eca0f6f47d5db828454700de20e5113667940d81e0db04" standard verify_py310 copy_python_gdb ensurepip
else
install_package "Python-3.10.21" "https://www.python.org/ftp/python/3.10.21/Python-3.10.21.tgz#f276987f06270ae6c1fb4da620bd105edf78c31368c2f7e85e6c1d51c560b04b" standard verify_py310 copy_python_gdb ensurepip
fi

View file

@ -0,0 +1,11 @@
prefer_openssl3
export PYTHON_BUILD_CONFIGURE_WITH_OPENSSL=1
export PYTHON_BUILD_CONFIGURE_WITH_OPENSSL_RPATH=1
export PYTHON_BUILD_TCLTK_USE_PKGCONFIG=1
install_package "openssl-3.6.3" "https://github.com/openssl/openssl/releases/download/openssl-3.6.3/openssl-3.6.3.tar.gz#243a86649cf6f23eeb6a2ff2456e09e5d77dd9018a54d3d96b0c6bdd6ba6c7f1" 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
if has_tar_xz_support; then
install_package "Python-3.11.16" "https://www.python.org/ftp/python/3.11.16/Python-3.11.16.tar.xz#91bcdebfdde239a003ae93738a7fce0f9230fee5c4bc2b86f6e6e8c6f98aabe8" standard verify_py311 copy_python_gdb ensurepip
else
install_package "Python-3.11.16" "https://www.python.org/ftp/python/3.11.16/Python-3.11.16.tgz#6c0bd76ab0ec7d94ed400b1497f01ac6c7751c8822615ee0855a3eb2d893ea76" standard verify_py311 copy_python_gdb ensurepip
fi

View file

@ -0,0 +1,11 @@
prefer_openssl3
export PYTHON_BUILD_CONFIGURE_WITH_OPENSSL=1
export PYTHON_BUILD_CONFIGURE_WITH_OPENSSL_RPATH=1
export PYTHON_BUILD_TCLTK_USE_PKGCONFIG=1
install_package "openssl-3.6.3" "https://github.com/openssl/openssl/releases/download/openssl-3.6.3/openssl-3.6.3.tar.gz#243a86649cf6f23eeb6a2ff2456e09e5d77dd9018a54d3d96b0c6bdd6ba6c7f1" 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
if has_tar_xz_support; then
install_package "Python-3.12.14" "https://www.python.org/ftp/python/3.12.14/Python-3.12.14.tar.xz#5c8462af5790baf43a321a1559dbe0db06d1be4300fb85fb53c40060668e548a" standard verify_py312 copy_python_gdb ensurepip
else
install_package "Python-3.12.14" "https://www.python.org/ftp/python/3.12.14/Python-3.12.14.tgz#6c6df908d2c3fd24e6d76869e92542abd0f33aec9dfc18df8875f89660286d43" standard verify_py312 copy_python_gdb ensurepip
fi

View file

@ -0,0 +1,11 @@
prefer_openssl3
export PYTHON_BUILD_CONFIGURE_WITH_OPENSSL=1
export PYTHON_BUILD_CONFIGURE_WITH_OPENSSL_RPATH=1
export PYTHON_BUILD_TCLTK_USE_PKGCONFIG=1
install_package "openssl-3.6.3" "https://github.com/openssl/openssl/releases/download/openssl-3.6.3/openssl-3.6.3.tar.gz#243a86649cf6f23eeb6a2ff2456e09e5d77dd9018a54d3d96b0c6bdd6ba6c7f1" 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
if has_tar_xz_support; then
install_package "Python-3.13.15" "https://www.python.org/ftp/python/3.13.15/Python-3.13.15.tar.xz#1e66a7945a48390ee4c2a4268a0e4185884059a13c4aab6d148aa208deea4a76" standard verify_py313 copy_python_gdb ensurepip
else
install_package "Python-3.13.15" "https://www.python.org/ftp/python/3.13.15/Python-3.13.15.tgz#c28d9d213c09b5b5ab2c29812950e12f746999e099b82894231be954b26baed9" standard verify_py313 copy_python_gdb ensurepip
fi

View file

@ -1,11 +1,11 @@
prefer_openssl3 prefer_openssl3_to_4
export PYTHON_BUILD_CONFIGURE_WITH_OPENSSL=1 export PYTHON_BUILD_CONFIGURE_WITH_OPENSSL=1
export PYTHON_BUILD_CONFIGURE_WITH_OPENSSL_RPATH=1 export PYTHON_BUILD_CONFIGURE_WITH_OPENSSL_RPATH=1
export PYTHON_BUILD_TCLTK_USE_PKGCONFIG=1 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.14.7" "https://www.python.org/ftp/python/3.14.7/Python-3.14.7.tar.xz#3b48dac8fb59f62eaa67ac83c1eb12bda1b7a08406dd286e252c11a66be27f81" standard verify_py314 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.14.7" "https://www.python.org/ftp/python/3.14.7/Python-3.14.7.tgz#62859805f6fdf25e2bcbf3fa3217801e1996887ca33e6a2af80674bdfa2dbe07" standard verify_py314 copy_python_gdb ensurepip
fi fi

View file

@ -0,0 +1,2 @@
export PYTHON_BUILD_FREE_THREADING=1
source "${BASH_SOURCE[0]%t}"

View file

@ -0,0 +1,11 @@
prefer_openssl3
export PYTHON_BUILD_CONFIGURE_WITH_OPENSSL=1
export PYTHON_BUILD_CONFIGURE_WITH_OPENSSL_RPATH=1
export PYTHON_BUILD_TCLTK_USE_PKGCONFIG=1
install_package "openssl-4.0.2" "https://github.com/openssl/openssl/releases/download/openssl-4.0.2/openssl-4.0.2.tar.gz#736b467530f916737b7031310ccb21d8218c6229e61e8e160cd1d3458cd543a8" 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
if has_tar_xz_support; then
install_package "Python-3.15.0rc2" "https://www.python.org/ftp/python/3.15.0/Python-3.15.0rc2.tar.xz#8d93af5eaaaea5adfd41bd786a7ba3f03f2ad1ab57c6a65e0b963deab91d5ad7" standard verify_py315 copy_python_gdb ensurepip
else
install_package "Python-3.15.0rc2" "https://www.python.org/ftp/python/3.15.0/Python-3.15.0rc2.tgz#164dbb80f5e1fdd8768387724bfa014da1000401b2015d872a2396c8b858b829" standard verify_py315 copy_python_gdb ensurepip
fi

View file

@ -0,0 +1,2 @@
export PYTHON_BUILD_FREE_THREADING=1
source "${BASH_SOURCE[0]%t}"

View file

@ -0,0 +1,19 @@
case "$(anaconda_architecture 2>/dev/null || true)" in
"Linux-aarch64" )
install_script "Anaconda3-2026.07-1-Linux-aarch64" "https://repo.anaconda.com/archive/Anaconda3-2026.07-1-Linux-aarch64.sh#af2fd0025728a04408e0481d5668b92c53589cbfc66525a15119e6503742a04d" "anaconda" verify_py314
;;
"Linux-x86_64" )
install_script "Anaconda3-2026.07-1-Linux-x86_64" "https://repo.anaconda.com/archive/Anaconda3-2026.07-1-Linux-x86_64.sh#9f49042048e9a8220c1cddf9192054290724052d3b2a86f938f9f5edd911db8f" "anaconda" verify_py314
;;
"MacOSX-arm64" )
install_script "Anaconda3-2026.07-1-MacOSX-arm64" "https://repo.anaconda.com/archive/Anaconda3-2026.07-1-MacOSX-arm64.sh#6a9b63c645db4dbe293ffe9f168f7e380fe7a041fc863e67ee84db027425bce2" "anaconda" verify_py314
;;
* )
{ echo
colorize 1 "ERROR"
echo ": The binary distribution of Anaconda is not available for $(anaconda_architecture 2>/dev/null || true)."
echo
} >&2
exit 1
;;
esac

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

@ -0,0 +1,50 @@
# 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.3.4.1'
RELEASE_TAG='graal-25.3.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.13-community-${VERSION}" && echo
graalpy_arch="$(graalpy_architecture 2>/dev/null || true)"
case "$graalpy_arch" in
"linux-amd64" )
checksum="23515b4e659d645960517b0ceedb90faa84fcb01f0f4497beca5868a1b1ae3ea"
;;
"linux-aarch64" )
checksum="53b80e284e444540ae7cb67349af3dd8f6c1848fbf6abb5051742ac745f1f33d"
;;
"macos-aarch64" )
checksum="8ac33b5a5d0ee872751595211508fd826f47051ff6e6614032aed1de071eebab"
;;
* )
{ echo
colorize 1 "ERROR"
echo ": No binary distribution of GraalPy is available for $(uname -sm)."
echo
} >&2
exit 1
;;
esac
install_package "graalpy3.13-${VERSION}" "https://github.com/oracle/graalpython/releases/download/${RELEASE_TAG}/graalpy3.13-${VERSION}-${graalpy_arch}.tar.gz#${checksum}" "copy" ensurepip

View file

@ -0,0 +1,45 @@
# 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.3.4.1'
RELEASE_TAG='graal-25.3.4'
graalpy_arch="$(graalpy_architecture 2>/dev/null || true)"
case "$graalpy_arch" in
"linux-amd64" )
checksum="5e239616c8352488585f58d33991d262e8c627483741778ad43d39a4830176ad"
;;
"linux-aarch64" )
checksum="13007ecfe8180e91f1060de60a2ba6ce88f38faa4a36574b34143a492e8c660e"
;;
"macos-aarch64" )
checksum="e2cf7ae230478ad8d100ad868f75e3addb174d81e7f550322ea5e74cab066644"
;;
* )
{ echo
colorize 1 "ERROR"
echo ": No binary distribution of GraalPy is available for $(uname -sm)."
echo
} >&2
exit 1
;;
esac
install_package "graalpy3.13-community-${VERSION}" "https://github.com/oracle/graalpython/releases/download/${RELEASE_TAG}/graalpy3.13-community-${VERSION}-${graalpy_arch}.tar.gz#${checksum}" "copy" ensurepip

View file

@ -0,0 +1,20 @@
export CONDA_PLUGINS_AUTO_ACCEPT_TOS=true
case "$(anaconda_architecture 2>/dev/null || true)" in
"Linux-aarch64" )
install_script "Miniconda3-py310_26.5.3-2-Linux-aarch64" "https://repo.anaconda.com/miniconda/Miniconda3-py310_26.5.3-2-Linux-aarch64.sh#69b30d25b1308596e39819d2eeb8d669fec8b35205254d4d38975e9a6eb525e5" "miniconda" verify_py310
;;
"Linux-x86_64" )
install_script "Miniconda3-py310_26.5.3-2-Linux-x86_64" "https://repo.anaconda.com/miniconda/Miniconda3-py310_26.5.3-2-Linux-x86_64.sh#83e53ab0246ca320db28734bfd16f9bba895d96ae3e0ccf6f9b65e1383ab6a26" "miniconda" verify_py310
;;
"MacOSX-arm64" )
install_script "Miniconda3-py310_26.5.3-2-MacOSX-arm64" "https://repo.anaconda.com/miniconda/Miniconda3-py310_26.5.3-2-MacOSX-arm64.sh#fc25d37469e162e3073093c1e02a0a21a59681af10a097f73df3f303b89b050a" "miniconda" verify_py310
;;
* )
{ echo
colorize 1 "ERROR"
echo ": The binary distribution of Miniconda is not available for $(anaconda_architecture 2>/dev/null || true)."
echo
} >&2
exit 1
;;
esac

View file

@ -0,0 +1,20 @@
export CONDA_PLUGINS_AUTO_ACCEPT_TOS=true
case "$(anaconda_architecture 2>/dev/null || true)" in
"Linux-aarch64" )
install_script "Miniconda3-py311_26.5.3-2-Linux-aarch64" "https://repo.anaconda.com/miniconda/Miniconda3-py311_26.5.3-2-Linux-aarch64.sh#e50d1c902e94b6f64a19e0a3fbc35f8cadc09c5a1cf5b0fe10da14e4ce7ff24d" "miniconda" verify_py311
;;
"Linux-x86_64" )
install_script "Miniconda3-py311_26.5.3-2-Linux-x86_64" "https://repo.anaconda.com/miniconda/Miniconda3-py311_26.5.3-2-Linux-x86_64.sh#cdca3dd8440759bb87c60b227e26946263fe2856b30b2bcfdd964c38254fb8eb" "miniconda" verify_py311
;;
"MacOSX-arm64" )
install_script "Miniconda3-py311_26.5.3-2-MacOSX-arm64" "https://repo.anaconda.com/miniconda/Miniconda3-py311_26.5.3-2-MacOSX-arm64.sh#129bee9cb8e23d0eed175439a8b41c9844bac5c75f3f2aefa0be7104b403706f" "miniconda" verify_py311
;;
* )
{ echo
colorize 1 "ERROR"
echo ": The binary distribution of Miniconda is not available for $(anaconda_architecture 2>/dev/null || true)."
echo
} >&2
exit 1
;;
esac

View file

@ -0,0 +1,20 @@
export CONDA_PLUGINS_AUTO_ACCEPT_TOS=true
case "$(anaconda_architecture 2>/dev/null || true)" in
"Linux-aarch64" )
install_script "Miniconda3-py312_26.5.3-2-Linux-aarch64" "https://repo.anaconda.com/miniconda/Miniconda3-py312_26.5.3-2-Linux-aarch64.sh#822923b30d789477964ef5589f86de5a72ac4c584bad3b9f72d97190e13d776f" "miniconda" verify_py312
;;
"Linux-x86_64" )
install_script "Miniconda3-py312_26.5.3-2-Linux-x86_64" "https://repo.anaconda.com/miniconda/Miniconda3-py312_26.5.3-2-Linux-x86_64.sh#37606f9f03ced8ef60f4ffc76b21dda01728eac8a632dcab316c891cea4fe2f5" "miniconda" verify_py312
;;
"MacOSX-arm64" )
install_script "Miniconda3-py312_26.5.3-2-MacOSX-arm64" "https://repo.anaconda.com/miniconda/Miniconda3-py312_26.5.3-2-MacOSX-arm64.sh#ba7e4dede827e98c468c2dfa3b9a859728844ee8bde72a28eb216869af2d6ce1" "miniconda" verify_py312
;;
* )
{ echo
colorize 1 "ERROR"
echo ": The binary distribution of Miniconda is not available for $(anaconda_architecture 2>/dev/null || true)."
echo
} >&2
exit 1
;;
esac

View file

@ -0,0 +1,20 @@
export CONDA_PLUGINS_AUTO_ACCEPT_TOS=true
case "$(anaconda_architecture 2>/dev/null || true)" in
"Linux-aarch64" )
install_script "Miniconda3-py313_26.5.3-2-Linux-aarch64" "https://repo.anaconda.com/miniconda/Miniconda3-py313_26.5.3-2-Linux-aarch64.sh#549176858e194a15df5c8326b9f4e1b7ddf1464df47aec4115d0e6d14204e8bb" "miniconda" verify_py313
;;
"Linux-x86_64" )
install_script "Miniconda3-py313_26.5.3-2-Linux-x86_64" "https://repo.anaconda.com/miniconda/Miniconda3-py313_26.5.3-2-Linux-x86_64.sh#66f7c434bbdc7a4c5687b7e56cde724f73954d1322ffb273c6e387f12fbcdc03" "miniconda" verify_py313
;;
"MacOSX-arm64" )
install_script "Miniconda3-py313_26.5.3-2-MacOSX-arm64" "https://repo.anaconda.com/miniconda/Miniconda3-py313_26.5.3-2-MacOSX-arm64.sh#0d4d44f5d0740dddc68d381bbc8eb8c056d4792c832a9f0e3b5c663f7dda9d67" "miniconda" verify_py313
;;
* )
{ echo
colorize 1 "ERROR"
echo ": The binary distribution of Miniconda is not available for $(anaconda_architecture 2>/dev/null || true)."
echo
} >&2
exit 1
;;
esac

View file

@ -0,0 +1,20 @@
export CONDA_PLUGINS_AUTO_ACCEPT_TOS=true
case "$(anaconda_architecture 2>/dev/null || true)" in
"Linux-aarch64" )
install_script "Miniconda3-py314_26.5.3-2-Linux-aarch64" "https://repo.anaconda.com/miniconda/Miniconda3-py314_26.5.3-2-Linux-aarch64.sh#999e8761f4dc74fb8d0dc9f74d5374f6708ff81eebbb0af677a4d5307d38b2e5" "miniconda" verify_py314
;;
"Linux-x86_64" )
install_script "Miniconda3-py314_26.5.3-2-Linux-x86_64" "https://repo.anaconda.com/miniconda/Miniconda3-py314_26.5.3-2-Linux-x86_64.sh#80bc27f13c4de90f10e387aa45e864de4f0860692c1221aef5900009a2b55302" "miniconda" verify_py314
;;
"MacOSX-arm64" )
install_script "Miniconda3-py314_26.5.3-2-MacOSX-arm64" "https://repo.anaconda.com/miniconda/Miniconda3-py314_26.5.3-2-MacOSX-arm64.sh#e830bee5b9c6ebfb67e9df924b259a0d43c451bd17b965f7aa84523b69f7c3eb" "miniconda" verify_py314
;;
* )
{ echo
colorize 1 "ERROR"
echo ": The binary distribution of Miniconda is not available for $(anaconda_architecture 2>/dev/null || true)."
echo
} >&2
exit 1
;;
esac

View file

@ -0,0 +1,27 @@
From 3fec519d6b326918f39ceb142ef762042ce8365f Mon Sep 17 00:00:00 2001
From: Ivan Pozdeev <vano@mail.mipt.ru>
Date: Fri, 26 Dec 2025 13:39:21 +0300
Subject: [PATCH] Recognize an argument to -j in MAKEFLAGS
---
setup.py | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/setup.py b/setup.py
index ad8fb81b218..5666deaf67b 100644
--- a/setup.py
+++ b/setup.py
@@ -307,8 +307,8 @@ def __init__(self, dist):
self.failed_on_import = []
self.missing = []
self.disabled_configure = []
- if '-j' in os.environ.get('MAKEFLAGS', ''):
- self.parallel = True
+ if (m:=re.search(r'(?:^|\s)(?:-j|--jobs)(?:\s+|=)?(\d*)',os.environ.get('MAKEFLAGS', ''))) is not None:
+ self.parallel = int(m.group(1)) if m.group(1) else True
def add(self, ext):
self.extensions.append(ext)
--
2.36.1.windows.1

View file

@ -0,0 +1,27 @@
From 3fec519d6b326918f39ceb142ef762042ce8365f Mon Sep 17 00:00:00 2001
From: Ivan Pozdeev <vano@mail.mipt.ru>
Date: Fri, 26 Dec 2025 13:39:21 +0300
Subject: [PATCH] Recognize an argument to -j in MAKEFLAGS
---
setup.py | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/setup.py b/setup.py
index ad8fb81b218..5666deaf67b 100644
--- a/setup.py
+++ b/setup.py
@@ -307,8 +307,8 @@ def __init__(self, dist):
self.failed_on_import = []
self.missing = []
self.disabled_configure = []
- if '-j' in os.environ.get('MAKEFLAGS', ''):
- self.parallel = True
+ if (m:=re.search(r'(?:^|\s)(?:-j|--jobs)(?:\s+|=)?(\d*)',os.environ.get('MAKEFLAGS', ''))) is not None:
+ self.parallel = int(m.group(1)) if m.group(1) else True
def add(self, ext):
self.extensions.append(ext)
--
2.36.1.windows.1

View file

@ -0,0 +1,27 @@
From 3fec519d6b326918f39ceb142ef762042ce8365f Mon Sep 17 00:00:00 2001
From: Ivan Pozdeev <vano@mail.mipt.ru>
Date: Fri, 26 Dec 2025 13:39:21 +0300
Subject: [PATCH] Recognize an argument to -j in MAKEFLAGS
---
setup.py | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/setup.py b/setup.py
index ad8fb81b218..5666deaf67b 100644
--- a/setup.py
+++ b/setup.py
@@ -307,8 +307,8 @@ def __init__(self, dist):
self.failed_on_import = []
self.missing = []
self.disabled_configure = []
- if '-j' in os.environ.get('MAKEFLAGS', ''):
- self.parallel = True
+ if (m:=re.search(r'(?:^|\s)(?:-j|--jobs)(?:\s+|=)?(\d*)',os.environ.get('MAKEFLAGS', ''))) is not None:
+ self.parallel = int(m.group(1)) if m.group(1) else True
def add(self, ext):
self.extensions.append(ext)
--
2.36.1.windows.1

View file

@ -0,0 +1,64 @@
From cc13eabc7ce08accf49656e258ba500f74a1dae8 Mon Sep 17 00:00:00 2001
From: Ronald Oussoren <ronaldoussoren@mac.com>
Date: Thu, 28 Dec 2023 09:42:05 +0100
Subject: [PATCH] gh-110459: Make sure --with-openssl-rpath works on macOS
(#113441)
* gh-110459: Make sure --with-openssl-rpath works on macOS
On macOS the `-rpath` linker flag is spelled differently
than on on platforms.
---
.../macOS/2023-12-23-22-41-07.gh-issue-110459.NaMBJy.rst | 2 ++
configure | 7 ++++++-
configure.ac | 7 ++++++-
3 files changed, 14 insertions(+), 2 deletions(-)
create mode 100644 Misc/NEWS.d/next/macOS/2023-12-23-22-41-07.gh-issue-110459.NaMBJy.rst
diff --git a/Misc/NEWS.d/next/macOS/2023-12-23-22-41-07.gh-issue-110459.NaMBJy.rst b/Misc/NEWS.d/next/macOS/2023-12-23-22-41-07.gh-issue-110459.NaMBJy.rst
new file mode 100644
index 00000000000..44ffd857785
--- /dev/null
+++ b/Misc/NEWS.d/next/macOS/2023-12-23-22-41-07.gh-issue-110459.NaMBJy.rst
@@ -0,0 +1,2 @@
+Running ``configure ... --with-openssl-rpath=X/Y/Z`` no longer fails to detect
+OpenSSL on macOS.
diff --git a/configure b/configure
index 7e50abc29d0..6d65d3abc18 100755
--- a/configure
+++ b/configure
@@ -27478,7 +27478,12 @@ then :
else $as_nop
- rpath_arg="-Wl,-rpath="
+ if test "$ac_sys_system" = "Darwin"
+ then
+ rpath_arg="-Wl,-rpath,"
+ else
+ rpath_arg="-Wl,-rpath="
+ fi
fi
diff --git a/configure.ac b/configure.ac
index e064848af9e..bfdabc4474e 100644
--- a/configure.ac
+++ b/configure.ac
@@ -6808,7 +6808,12 @@ AX_CHECK_OPENSSL([have_openssl=yes],[have_openssl=no])
AS_VAR_IF([GNULD], [yes], [
rpath_arg="-Wl,--enable-new-dtags,-rpath="
], [
- rpath_arg="-Wl,-rpath="
+ if test "$ac_sys_system" = "Darwin"
+ then
+ rpath_arg="-Wl,-rpath,"
+ else
+ rpath_arg="-Wl,-rpath="
+ fi
])
AC_MSG_CHECKING([for --with-openssl-rpath])
--
2.46.2.windows.1

View file

@ -0,0 +1 @@
3.14.7

View file

@ -1276,6 +1276,7 @@ OUT
mkdir -p "$INSTALL_ROOT/bin" mkdir -p "$INSTALL_ROOT/bin"
touch "$INSTALL_ROOT/bin/package" touch "$INSTALL_ROOT/bin/package"
chmod -w "$INSTALL_ROOT/bin/package" chmod -w "$INSTALL_ROOT/bin/package"
skip_if_nonposix_security -w "$INSTALL_ROOT/bin/package"
install_fixture definitions/without-checksum install_fixture definitions/without-checksum
assert_success assert_success
@ -1288,6 +1289,7 @@ OUT
export TMPDIR="${BATS_TEST_TMPDIR}/build" export TMPDIR="${BATS_TEST_TMPDIR}/build"
mkdir -p "$TMPDIR" mkdir -p "$TMPDIR"
chmod -w "$TMPDIR" chmod -w "$TMPDIR"
skip_if_nonposix_security -w "$TMPDIR"
touch "${BATS_TEST_TMPDIR}/build-definition" touch "${BATS_TEST_TMPDIR}/build-definition"
run python-build "${BATS_TEST_TMPDIR}/build-definition" "$INSTALL_ROOT" run python-build "${BATS_TEST_TMPDIR}/build-definition" "$INSTALL_ROOT"
@ -1298,6 +1300,7 @@ OUT
export TMPDIR="${BATS_TEST_TMPDIR}/build" export TMPDIR="${BATS_TEST_TMPDIR}/build"
mkdir -p "$TMPDIR" mkdir -p "$TMPDIR"
chmod -x "$TMPDIR" chmod -x "$TMPDIR"
skip_if_nonposix_security -x "$TMPDIR"
touch "${BATS_TEST_TMPDIR}/build-definition" touch "${BATS_TEST_TMPDIR}/build-definition"
run python-build "${BATS_TEST_TMPDIR}/build-definition" "$INSTALL_ROOT" run python-build "${BATS_TEST_TMPDIR}/build-definition" "$INSTALL_ROOT"

View file

@ -0,0 +1,83 @@
#!/usr/bin/env bats
load test_helper
_setup() {
prerequisites="make build-essential libssl-dev zlib1g-dev libbz2-dev \
libreadline-dev libsqlite3-dev curl git llvm libncurses5-dev \
libncursesw5-dev xz-utils tk-dev libxml2-dev libxmlsec1-dev libffi-dev \
liblzma-dev libzstd-dev"
}
@test "completion does not install packages" {
stub apt-get
PATH="${BATS_TEST_DIRNAME}/../../../libexec:$PATH" \
run pyenv completions install-prerequisites
assert_success "--help"
unstub apt-get
}
@test "supports help" {
stub pyenv-help 'install-prerequisites : echo "Usage: pyenv install-prerequisites"'
run pyenv-install-prerequisites --help
assert_success "Usage: pyenv install-prerequisites"
unstub pyenv-help
}
@test "rejects arguments" {
stub pyenv-help 'install-prerequisites : echo "Usage: pyenv install-prerequisites"'
run pyenv-install-prerequisites unexpected
assert_failure "Usage: pyenv install-prerequisites"
unstub pyenv-help
}
@test "installs build prerequisites with apt-get as root" {
stub id '-u : echo 0'
stub apt-get \
'update -q : true' \
"install -yq ${prerequisites} : true"
run pyenv-install-prerequisites
assert_success
unstub apt-get
unstub id
}
@test "uses sudo when not running as root" {
stub id '-u : echo 1000'
stub apt-get
stub sudo \
'apt-get update -q : true' \
"apt-get install -yq ${prerequisites} : true"
run pyenv-install-prerequisites
assert_success
unstub sudo
unstub apt-get
unstub id
}
@test "fails when apt-get is unavailable" {
PATH="$(path_without apt-get)" run pyenv-install-prerequisites
assert_failure "pyenv: installing build prerequisites is not supported on this system"
}
@test "fails when sudo is unavailable for an unprivileged user" {
stub id '-u : echo 1000'
stub apt-get
PATH="$(path_without sudo)" run pyenv-install-prerequisites
assert_failure "pyenv: sudo is required to install build prerequisites"
unstub apt-get
unstub id
}

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

@ -2,6 +2,7 @@ setup() {
export PYTHON_BUILD_CURL_OPTS= export PYTHON_BUILD_CURL_OPTS=
export PYTHON_BUILD_HTTP_CLIENT="curl" export PYTHON_BUILD_HTTP_CLIENT="curl"
export PYENV_TEST_DIR="${BATS_TEST_TMPDIR}/pyenv"
export FIXTURE_ROOT="${BATS_TEST_DIRNAME}/fixtures" export FIXTURE_ROOT="${BATS_TEST_DIRNAME}/fixtures"
export INSTALL_ROOT="${BATS_TEST_TMPDIR}/install" export INSTALL_ROOT="${BATS_TEST_TMPDIR}/install"
PATH="/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin" PATH="/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin"
@ -148,7 +149,7 @@ path_without() {
if [ "$found" != "${PYENV_ROOT}/shims" ]; then if [ "$found" != "${PYENV_ROOT}/shims" ]; then
alt="${PYENV_TEST_DIR}/$(echo "${found#/}" | tr '/' '-')" alt="${PYENV_TEST_DIR}/$(echo "${found#/}" | tr '/' '-')"
mkdir -p "$alt" mkdir -p "$alt"
for util in bash head cut readlink greadlink; do for util in bash head cut readlink greadlink tr; do
if [ -x "${found}/$util" ]; then if [ -x "${found}/$util" ]; then
ln -s "${found}/$util" "${alt}/$util" ln -s "${found}/$util" "${alt}/$util"
fi fi
@ -162,3 +163,7 @@ path_without() {
echo "$path" echo "$path"
} }
skip_if_nonposix_security() {
true "${1:?}" "${2:?}"
test "$@" && skip "UNIX permission bits are being overridden" || true
}

View file

@ -12,7 +12,7 @@ FROM bash:$BASH
apk add sed coreutils findutils \ apk add sed coreutils findutils \
;fi ;fi
# Bats # Bats
RUN apk add --update parallel ncurses git \ RUN apk add --update parallel ncurses git binutils \
&& mkdir -p ~/.parallel \ && mkdir -p ~/.parallel \
&& touch ~/.parallel/will-cite && touch ~/.parallel/will-cite
COPY --from=bats /root/bats-core /root/bats-core COPY --from=bats /root/bats-core /root/bats-core

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

@ -0,0 +1,45 @@
#!/usr/bin/env bash
set -e
# Wraps Bats TAP formatter, adding file names to the output
_BATS_FORMATTER_LIB_RELPATH="lib/bats-core/formatter.bash"
source "$BATS_ROOT/$_BATS_FORMATTER_LIB_RELPATH"
# `bats-format-tap` calls this fn at the end
# We must stub it to be able to source and alter it
# https://stackoverflow.com/questions/1203583/how-do-i-rename-a-bash-function
eval orig_"$(declare -f bats_parse_internal_extended_tap)"
bats_parse_internal_extended_tap() { true; }
# stub sourcing lib from `bats-format-tap`
# as that would've reset the stubbed fn
FAKE_BATS_ROOT=
_trap_rm_fakeroot() { rm -rf "$FAKE_BATS_ROOT"; }
REAL_BATS_ROOT="$BATS_ROOT"
FAKE_BATS_ROOT=$(mktemp -d)
trap _trap_rm_fakeroot ERR EXIT
mkdir -p "$(dirname "$FAKE_BATS_ROOT/$_BATS_FORMATTER_LIB_RELPATH")"
touch "$FAKE_BATS_ROOT/$_BATS_FORMATTER_LIB_RELPATH"
BATS_ROOT="$FAKE_BATS_ROOT"
source "$REAL_BATS_ROOT/libexec/bats-core/bats-format-tap"
_trap_rm_fakeroot
trap - ERR EXIT
BATS_ROOT="$REAL_BATS_ROOT"
unset FAKE_BATS_ROOT REAL_BATS_ROOT _trap_rm_fakeroot
# Finally, alter `bats-format-tap`'s logic and invoke it
# print as "Anything" line
bats_tap_stream_suite() { # <file name>
# bats only passes --base-name to specific built-in formatters
# so we don't have info where the test root is
printf '%s\n' "${1##*/}"
}
orig_bats_parse_internal_extended_tap

View file

@ -13,6 +13,8 @@ load test_helper
@test "non-writable shims directory" { @test "non-writable shims directory" {
mkdir -p "${PYENV_ROOT}/shims" mkdir -p "${PYENV_ROOT}/shims"
chmod -w "${PYENV_ROOT}/shims" chmod -w "${PYENV_ROOT}/shims"
skip_if_nonposix_security -w "${PYENV_ROOT}/shims"
run pyenv-rehash run pyenv-rehash
assert_failure "pyenv: cannot rehash: ${PYENV_ROOT}/shims isn't writable" assert_failure "pyenv: cannot rehash: ${PYENV_ROOT}/shims isn't writable"
} }
@ -23,7 +25,8 @@ load test_helper
touch "${PYENV_ROOT}/shims/.pyenv-shim" touch "${PYENV_ROOT}/shims/.pyenv-shim"
#avoid failure due to a localized error message #avoid failure due to a localized error message
LANG=C run pyenv-rehash LANG=C run pyenv-rehash
assert_failure <<! assert_failure
assert_output_glob <<!
pyenv: cannot rehash: couldn't acquire lock ${PYENV_ROOT}/shims/.pyenv-shim for 1 seconds. Last error message: pyenv: cannot rehash: couldn't acquire lock ${PYENV_ROOT}/shims/.pyenv-shim for 1 seconds. Last error message:
*/pyenv-rehash: line *: ${PYENV_ROOT}/shims/.pyenv-shim: cannot overwrite existing file */pyenv-rehash: line *: ${PYENV_ROOT}/shims/.pyenv-shim: cannot overwrite existing file
! !

View file

@ -6,4 +6,4 @@ if [ -n "$PYENV_NATIVE_EXT" ]; then
make -C src make -C src
fi fi
exec bats ${CI:+--tap} ${BATS_TEST_FILTER:+--filter "${BATS_TEST_FILTER}"} test/${BATS_FILE_FILTER} exec bats ${CI:+-F "$PWD/test/libexec/bats-format-tap-suite"} ${BATS_TEST_FILTER:+--filter "${BATS_TEST_FILTER}"} test/${BATS_FILE_FILTER}

View file

@ -1,39 +0,0 @@
#!/usr/bin/env bats
load test_helper
@test "shims linked from elsewhere are chained, other programs at the same paths are unaffected (integration)" {
bats_require_minimum_version 1.5.0
progname=shimmed_program
called_progname=another_program
create_alt_executable_in_version "custom" "$progname" <<!
echo "called from \$0"
pyenv-exec "$called_progname"
!
pyenv-rehash
PATH="$(path_without "$progname" "$called_progname")"
for disguised_shim_path in "$BATS_TEST_TMPDIR/"{weird-location,even/weirder/location}; do
mkdir -p "$disguised_shim_path"
ln -s "${PYENV_ROOT}/shims/$progname" "$disguised_shim_path/$progname"
PATH="$PATH:$disguised_shim_path"
done
create_executable "$disguised_shim_path" "$called_progname" <<!
echo "convoluted call success!"
!
real_path="$BATS_TEST_TMPDIR/real-location"
mkdir -p "$real_path"
ln -s "${PYENV_ROOT}/versions/custom/bin/$progname" "$real_path/$progname"
PATH="$PATH:$real_path"
run "$progname"
assert_success
assert_output <<!
called from $real_path/$progname
convoluted call success!
!
rm "$real_path/$progname"
run -127 "$progname"
assert_failure
assert_line 0 "pyenv: shimmed_program: command not found"
}

View file

@ -27,3 +27,39 @@ load test_helper
assert_line "irb" assert_line "irb"
assert_line "python" assert_line "python"
} }
@test "shims linked from elsewhere are chained, other programs at the same paths are unaffected (integration)" {
bats_require_minimum_version 1.5.0
progname=shimmed_program
called_progname=another_program
create_alt_executable_in_version "custom" "$progname" <<!
echo "called from \$0"
pyenv-exec "$called_progname"
!
pyenv-rehash
PATH="$(path_without "$progname" "$called_progname")"
for disguised_shim_path in "$BATS_TEST_TMPDIR/"{weird-location,even/weirder/location}; do
mkdir -p "$disguised_shim_path"
ln -s "${PYENV_ROOT}/shims/$progname" "$disguised_shim_path/$progname"
PATH="$PATH:$disguised_shim_path"
done
create_executable "$disguised_shim_path" "$called_progname" <<!
echo "convoluted call success!"
!
real_path="$BATS_TEST_TMPDIR/real-location"
mkdir -p "$real_path"
ln -s "${PYENV_ROOT}/versions/custom/bin/$progname" "$real_path/$progname"
PATH="$PATH:$real_path"
run "$progname"
assert_success
assert_output <<!
called from $real_path/$progname
convoluted call success!
!
rm "$real_path/$progname"
run -127 "$progname"
assert_failure
assert_line 0 "pyenv: shimmed_program: command not found"
}

View file

@ -2,8 +2,14 @@ unset PYENV_VERSION
unset PYENV_DIR unset PYENV_DIR
setup() { setup() {
export _PYENV_INSTALL_PREFIX="${BATS_TEST_DIRNAME%/*}"
export PS4='+(${BASH_SOURCE}:${LINENO}): ${FUNCNAME[0]:+${FUNCNAME[0]}(): }' export PS4='+(${BASH_SOURCE}:${LINENO}): ${FUNCNAME[0]:+${FUNCNAME[0]}(): }'
export _PYENV_INSTALL_PREFIX="${BATS_TEST_DIRNAME%/*}"
local PLUGIN_PREFIX
if [[ $_PYENV_INSTALL_PREFIX =~ /plugins/[^/]+$ ]]; then
PLUGIN_PREFIX="$_PYENV_INSTALL_PREFIX"
_PYENV_INSTALL_PREFIX="${_PYENV_INSTALL_PREFIX::${#_PYENV_INSTALL_PREFIX}-${#BASH_REMATCH[0]}}"
fi
if ! enable -f "${_PYENV_INSTALL_PREFIX}"/libexec/pyenv-realpath.dylib realpath 2>/dev/null; then if ! enable -f "${_PYENV_INSTALL_PREFIX}"/libexec/pyenv-realpath.dylib realpath 2>/dev/null; then
if [ -n "$PYENV_NATIVE_EXT" ]; then if [ -n "$PYENV_NATIVE_EXT" ]; then
echo "pyenv: failed to load \`realpath' builtin" >&2 echo "pyenv: failed to load \`realpath' builtin" >&2
@ -27,6 +33,9 @@ setup() {
PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin
PATH="${PYENV_TEST_DIR}/bin:$PATH" PATH="${PYENV_TEST_DIR}/bin:$PATH"
PATH="${_PYENV_INSTALL_PREFIX}/libexec:$PATH" PATH="${_PYENV_INSTALL_PREFIX}/libexec:$PATH"
if [[ -n $PLUGIN_PREFIX ]]; then
PATH="${PLUGIN_PREFIX}/libexec:${PLUGIN_PREFIX}/bin:$PATH"
fi
PATH="${BATS_TEST_DIRNAME}/libexec:$PATH" PATH="${BATS_TEST_DIRNAME}/libexec:$PATH"
PATH="${PYENV_ROOT}/shims:$PATH" PATH="${PYENV_ROOT}/shims:$PATH"
PATH="${BATS_TEST_TMPDIR}/stubs:$PATH" PATH="${BATS_TEST_TMPDIR}/stubs:$PATH"
@ -35,11 +44,12 @@ 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
# If test specific setup exist, run it # If test specific setup exist, run it
if [[ $(type -t _setup) == function ]];then if [[ $(type -t _setup) == function ]];then
_setup _setup
@ -58,34 +68,64 @@ assert_success() {
if [ "$status" -ne 0 ]; then if [ "$status" -ne 0 ]; then
flunk "command failed with exit status $status" $'\n'\ flunk "command failed with exit status $status" $'\n'\
"output: $output" "output: $output"
elif [ "$#" -gt 0 ]; then
assert_output "$1"
fi fi
_assert_output_if_provided "$@"
} }
assert_failure() { assert_failure() {
if [ "$status" -eq 0 ]; then if [ "$status" -eq 0 ]; then
flunk "expected failed exit status" $'\n'\ flunk "expected failed exit status" $'\n'\
"output: $output" "output: $output"
elif [ "$#" -gt 0 ]; then
assert_output "$1"
fi fi
_assert_output_if_provided "$@"
} }
assert_equal() { assert_equal() {
if [ "$1" != "$2" ]; then _assert_equal_as text "$@"
{ echo "expected: \`$1'" }
echo "actual: \`$2'"
_assert_equal_as() {
if case "$1" in
text)
[[ "$2" != "$3" ]];;
glob)
[[ "$3" != $2 ]];;
*)
echo "invalid comparison type: \`$1'" >&2; return 1;;
esac
then
{ diff -u --label expected --label actual <(echo "$2") <(echo "$3") | cat -te
} | flunk } | flunk
fi fi
} }
assert_output() { _assert_output_if_provided() {
local expected if [ "$#" -gt 0 ]; then
if [ $# -eq 0 ]; then expected="$(cat -)" assert_output "$1"
else expected="$1" elif [ ! -t 0 ]; then
local expected=$(cat -)
if [[ -n $expected ]]; then
assert_output "$expected"
fi
fi fi
assert_equal "$expected" "$output" }
assert_output() {
_assert_output_as text "$@"
}
assert_output_glob() {
_assert_output_as glob "$@"
}
_assert_output_as() {
local kind="${1:?}"; shift
local expected
if [ $# -eq 0 ]
then expected="$(cat -)"
else expected="$1"
fi
_assert_equal_as "$kind" "$expected" "$output"
} }
assert_line() { assert_line() {
@ -135,7 +175,7 @@ path_without() {
if [ "$found" != "${PYENV_ROOT}/shims" ]; then if [ "$found" != "${PYENV_ROOT}/shims" ]; then
alt="${PYENV_TEST_DIR}/$(echo "${found#/}" | tr '/' '-')" alt="${PYENV_TEST_DIR}/$(echo "${found#/}" | tr '/' '-')"
mkdir -p "$alt" mkdir -p "$alt"
for util in bash head cut readlink greadlink tr sed xargs basename sort; do for util in basename bash cut dirname find greadlink gzip head mkdir readlink sed sort tar tr xargs; do
if [ -x "${found}/$util" ]; then if [ -x "${found}/$util" ]; then
ln -s "${found}/$util" "${alt}/$util" ln -s "${found}/$util" "${alt}/$util"
fi fi
@ -193,3 +233,8 @@ create_hook() {
cat > "${PYENV_HOOK_PATH}/$1/$2" cat > "${PYENV_HOOK_PATH}/$1/$2"
fi fi
} }
skip_if_nonposix_security() {
true "${1:?}" "${2:?}"
test "$@" && skip "UNIX permission bits are being overridden" || true
}

View file

@ -90,13 +90,13 @@ IN
} }
@test "skips glob path traversal" { @test "skips glob path traversal" {
cat > my-version <<IN cat > my-version <<'IN'
../* ../*
3.9.3 3.9.3
IN IN
run pyenv-version-file-read my-version run pyenv-version-file-read my-version
assert_success <<OUT assert_success <<'OUT'
pyenv: invalid version \`../\*' ignored in \`my-version' pyenv: invalid version `../*' ignored in `my-version'
3.9.3 3.9.3
OUT OUT
} }

View file

@ -73,3 +73,15 @@ create_file() {
run pyenv-version-file "$PWD" run pyenv-version-file "$PWD"
assert_failure "" assert_failure ""
} }
@test "walks up beyond cwd for a relative path" {
create_file ".python-version"
mkdir -p project/subdir
cd project
# Run with CPU-time limit because this used to loop forever
run bash -c 'ulimit -t 5; pyenv-version-file .'
assert_success "${PYENV_TEST_DIR}/.python-version"
run pyenv-version-file ./subdir
assert_success "${PYENV_TEST_DIR}/.python-version"
}

View file

@ -83,8 +83,7 @@ OUT
create_version "3.4.0/envs/bar" create_version "3.4.0/envs/bar"
create_version "3.5.2" create_version "3.5.2"
run pyenv-versions run pyenv-versions
assert_success assert_success <<OUT
assert_output <<OUT
* system (set by ${PYENV_ROOT}/version) * system (set by ${PYENV_ROOT}/version)
2.7.6 2.7.6
3.4.0 3.4.0
@ -95,6 +94,7 @@ OUT
} }
@test "skips envs with --skip-envs" { @test "skips envs with --skip-envs" {
stub_system_python
create_version "3.3.3" create_version "3.3.3"
create_version "3.4.0" create_version "3.4.0"
create_version "3.4.0/envs/foo" create_version "3.4.0/envs/foo"
@ -102,7 +102,7 @@ OUT
create_version "3.5.0" create_version "3.5.0"
run pyenv-versions --skip-envs run pyenv-versions --skip-envs
assert_success <<OUT assert_success <<OUT
* system (set by ${PYENV_ROOT}/version) * system (set by ${PYENV_ROOT}/version)
3.3.3 3.3.3
3.4.0 3.4.0
@ -188,9 +188,7 @@ OUT
create_external_version "moo" create_external_version "moo"
run pyenv-versions --bare --skip-aliases run pyenv-versions --bare --skip-aliases
assert_success assert_success <<OUT
assert_output <<OUT
1.8.7 1.8.7
moo moo
OUT OUT

View file

@ -64,7 +64,7 @@ load test_helper
assert_failure <<OUT assert_failure <<OUT
pyenv: version \`3.3' is not installed (set by PYENV_VERSION environment variable) pyenv: version \`3.3' is not installed (set by PYENV_VERSION environment variable)
pyenv: py.test: command not found pyenv: py.test: command not found
The \`py.test' command exists in these Python versions: The \`py.test' command exists in these Python versions:
3.4 3.4
@ -81,7 +81,7 @@ OUT
pyenv: version \`2.7' is not installed (set by PYENV_VERSION environment variable) pyenv: version \`2.7' is not installed (set by PYENV_VERSION environment variable)
pyenv: version \`3.3' is not installed (set by PYENV_VERSION environment variable) pyenv: version \`3.3' is not installed (set by PYENV_VERSION environment variable)
pyenv: py.test: command not found pyenv: py.test: command not found
The \`py.test' command exists in these Python versions: The \`py.test' command exists in these Python versions:
3.4 3.4