mirror of
https://github.com/pyenv/pyenv.git
synced 2026-09-10 15:46:17 -04:00
Compare commits
195 commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
10e96bfc47 | ||
|
|
896e76c3d5 | ||
|
|
228fbf4c4f | ||
|
|
84839ae589 | ||
|
|
75aee988b3 | ||
|
|
1d08efe089 | ||
|
|
2e3ef01abb | ||
|
|
efeab7f8ee | ||
|
|
e5c7eb3399 | ||
|
|
a43095dc11 | ||
|
|
4aa904634f | ||
|
|
4a7d13d7ce | ||
|
|
c335ab83de | ||
|
|
bf1fcd346b | ||
|
|
873e0249a5 | ||
|
|
d6e547b94e | ||
|
|
3bac268cdb | ||
|
|
19fa774e42 | ||
|
|
af03af9593 | ||
|
|
1fcb988164 | ||
|
|
925e5ad0e7 | ||
|
|
35960ee19e | ||
|
|
c3ba994ec2 | ||
|
|
a3b98a4223 | ||
|
|
ac020225c2 | ||
|
|
f2ac882579 | ||
|
|
e8b7a27ee6 | ||
|
|
8d0ca21451 | ||
|
|
d7a5e87d75 | ||
|
|
5cae73944f | ||
|
|
325abac17d | ||
|
|
d10388a052 | ||
|
|
7c4350edf4 | ||
|
|
d6bb1c6396 | ||
|
|
ad6544409b | ||
|
|
ae8a0ee125 | ||
|
|
3646eb840b | ||
|
|
6e58140657 | ||
|
|
a7e508fcdf | ||
|
|
d1f1865c2a | ||
|
|
86b5797083 | ||
|
|
5d78e47399 | ||
|
|
59acc42647 | ||
|
|
4fec76f267 | ||
|
|
592fe6a087 | ||
|
|
906a6acc10 | ||
|
|
3112172081 | ||
|
|
cfe1c37d26 | ||
|
|
af9201ea1e | ||
|
|
56512aee3b | ||
|
|
e390b228c8 | ||
|
|
a632465cf4 | ||
|
|
54744db05e | ||
|
|
dd79c11f6c | ||
|
|
0704e65781 | ||
|
|
8644fb5519 | ||
|
|
41e242857e | ||
|
|
6f21f76965 | ||
|
|
8be1b9bd0e | ||
|
|
7eafc5fe02 | ||
|
|
9fe4cb8e1e | ||
|
|
61747c06d4 | ||
|
|
7509eafdd0 | ||
|
|
593f820a7d | ||
|
|
5c12600625 | ||
|
|
6717c62dc1 | ||
|
|
5f9c0ba613 | ||
|
|
52acbdf83f | ||
|
|
85f304ef3b | ||
|
|
41580b69db | ||
|
|
3e5347be1e | ||
|
|
172a79e993 | ||
|
|
8275e15cb0 | ||
|
|
90c0357682 | ||
|
|
30aaf4edba | ||
|
|
d97713d1b5 | ||
|
|
43e30ef815 | ||
|
|
6b1cc34610 | ||
|
|
d2d3012f17 | ||
|
|
410e05bf8c | ||
|
|
a6cf6aeadb | ||
|
|
8406a2bc7f | ||
|
|
ed1a3a5545 | ||
|
|
22ee5d4175 | ||
|
|
7c7c4dc11c | ||
|
|
45ae8d2ebc | ||
|
|
396e65a461 | ||
|
|
959968c46d | ||
|
|
009ef3a2db | ||
|
|
acdd8a95bd | ||
|
|
98412dba80 | ||
|
|
6426f852d0 | ||
|
|
33f8621ec8 | ||
|
|
9572edf4bb | ||
|
|
117a381575 | ||
|
|
56a440e4a7 | ||
|
|
a8ecfc743e | ||
|
|
c4395e5820 | ||
|
|
a54b47e783 | ||
|
|
c6cc0a1959 | ||
|
|
b39d4291be | ||
|
|
cec6d46792 | ||
|
|
e4f61e67e2 | ||
|
|
42aa760e2e | ||
|
|
d2c527cdd7 | ||
|
|
a76c4aaafa | ||
|
|
5b5c60fb6e | ||
|
|
304cb7b6a7 | ||
|
|
25fdc1caf9 | ||
|
|
264cb65a1e | ||
|
|
00d93c1d91 | ||
|
|
68fca03bb8 | ||
|
|
6cc7bff383 | ||
|
|
38e1fbb08e | ||
|
|
69323e77cc | ||
|
|
526f2de13d | ||
|
|
28cd6f123e | ||
|
|
d3d4606d2f | ||
|
|
0767d64344 | ||
|
|
76e64ff2ea | ||
|
|
b0fb351419 | ||
|
|
e7fd07dd91 | ||
|
|
faf999211b | ||
|
|
585ed84283 | ||
|
|
d061cb4651 | ||
|
|
059bb2c151 | ||
|
|
b904ea54cc | ||
|
|
dcba8b4064 | ||
|
|
633436706f | ||
|
|
4092eba274 | ||
|
|
064e1c48ba | ||
|
|
462bb67709 | ||
|
|
b424d452d0 | ||
|
|
80af359232 | ||
|
|
ccb4601f3a | ||
|
|
5d6f998c52 | ||
|
|
6b842a7670 | ||
|
|
45951d2cbb | ||
|
|
d604acb78a | ||
|
|
37405c3249 | ||
|
|
268c61a69c | ||
|
|
b5429624c2 | ||
|
|
5f7597e754 | ||
|
|
62d7798270 | ||
|
|
4086bbe562 | ||
|
|
60c9339685 | ||
|
|
d3f8de4c04 | ||
|
|
0843745be9 | ||
|
|
d4d69ed0cd | ||
|
|
0493a33f59 | ||
|
|
8bc71e9161 | ||
|
|
a5a1c4d50d | ||
|
|
c879cb0f2f | ||
|
|
59004d77ed | ||
|
|
c2cfbd1e8b | ||
|
|
a17c5fb596 | ||
|
|
c6324ff45a | ||
|
|
74c2486a2c | ||
|
|
ac5dce9014 | ||
|
|
19ae300eb8 | ||
|
|
e429cc0bd8 | ||
|
|
d58cf6ec71 | ||
|
|
143b2c9c02 | ||
|
|
f977248086 | ||
|
|
569d464d36 | ||
|
|
7795476af1 | ||
|
|
137e705db7 | ||
|
|
302797ba41 | ||
|
|
40db754168 | ||
|
|
5c3268c9af | ||
|
|
dd86f543fc | ||
|
|
c46a970595 | ||
|
|
8bb5b1607e | ||
|
|
cc9726c641 | ||
|
|
a574a74042 | ||
|
|
0c3967aa32 | ||
|
|
af454a32dc | ||
|
|
d38d18ec25 | ||
|
|
577f04653d | ||
|
|
8ebf088360 | ||
|
|
4e923221ce | ||
|
|
370c26a6c9 | ||
|
|
a3fa9b73b8 | ||
|
|
483e7f9bdf | ||
|
|
ae2e7a3f0b | ||
|
|
59785f6762 | ||
|
|
806f3f6ae2 | ||
|
|
1c772d5ff2 | ||
|
|
8103febc62 | ||
|
|
8b18b962a3 | ||
|
|
199e598351 | ||
|
|
e55e3c05eb | ||
|
|
bc1b66250f | ||
|
|
dfba9f7608 | ||
|
|
fb9130e85a |
|
|
@ -1,4 +0,0 @@
|
|||
.git/
|
||||
.python-version
|
||||
.vscode/
|
||||
.idea/
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
# Editor configuration, see https://editorconfig.org
|
||||
root = true
|
||||
|
||||
[*]
|
||||
end_of_line = lf
|
||||
charset = utf-8
|
||||
|
||||
# Makefiles always use tabs for indentation
|
||||
[Makefile]
|
||||
indent_style = tab
|
||||
indent_size = unset # Allow user-defined tab width
|
||||
1
.gitattributes
vendored
Normal file
1
.gitattributes
vendored
Normal file
|
|
@ -0,0 +1 @@
|
|||
/share/man/man[1-8]/*.[1-8] linguist-generated
|
||||
1
.github/CODEOWNERS
vendored
1
.github/CODEOWNERS
vendored
|
|
@ -1 +0,0 @@
|
|||
* @pyenv/pyenv-core-maintainers @pyenv/pyenv-core-committers
|
||||
12
.github/FUNDING.yml
vendored
12
.github/FUNDING.yml
vendored
|
|
@ -1,12 +0,0 @@
|
|||
# These are supported funding model platforms
|
||||
|
||||
github: [pyenv] # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
|
||||
patreon: # Replace with a single Patreon username
|
||||
open_collective: pyenv # Replace with a single Open Collective username
|
||||
ko_fi: # Replace with a single Ko-fi username
|
||||
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
|
||||
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
|
||||
liberapay: # Replace with a single Liberapay username
|
||||
issuehunt: # Replace with a single IssueHunt username
|
||||
otechie: # Replace with a single Otechie username
|
||||
custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
|
||||
54
.github/ISSUE_TEMPLATE/bug_report.md
vendored
54
.github/ISSUE_TEMPLATE/bug_report.md
vendored
|
|
@ -1,54 +0,0 @@
|
|||
---
|
||||
name: Bug report
|
||||
about: Create a report to help us improve
|
||||
title: ''
|
||||
labels: ''
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
### Prerequisites
|
||||
* [ ] Make sure your problem is not listed in [the common build problems](https://github.com/pyenv/pyenv/wiki/Common-build-problems).
|
||||
* [ ] Make sure no duplicated issue has already been reported in [the pyenv issues](https://github.com/pyenv/pyenv/issues?q=is%3Aissue). For build errors, a reported issue typically mentions a key error message. This key error message is often not in the 10 last build log lines reported to the console but is rather earlier in the build log -- typically, it's the first error message encountered in the log.
|
||||
* [ ] Make sure you are reporting a problem in Pyenv and not seeking consultation with Pyenv usage.
|
||||
* GitHub issues are intended mainly for Pyenv development purposes. If you are seeking help with Pyenv usage, check [Pyenv documentation](https://github.com/pyenv/pyenv?tab=readme-ov-file#simple-python-version-management-pyenv), go to a user community site like [Gitter](https://gitter.im/yyuu/pyenv), [StackOverflow](https://stackoverflow.com/questions/tagged/pyenv), etc, or to [Discussions](https://github.com/orgs/pyenv/discussions).
|
||||
* [ ] Make sure your problem is not derived from packaging (e.g. [Homebrew](https://brew.sh)).
|
||||
* Please refer to the package documentation for the installation issues, etc.
|
||||
* [ ] Make sure your problem is not derived from plugins.
|
||||
* This repository is maintaining `pyenv` and the default `python-build` plugin only. Please refrain from reporting issues of other plugins here.
|
||||
|
||||
### Describe the bug
|
||||
A clear and concise description of what the bug is.
|
||||
Do specify what the expected behaviour is if that's not obvious from the bug's nature.
|
||||
|
||||
#### Reproduction steps
|
||||
Listing the commands to run in a new console session and their output is usually sufficient.
|
||||
Please use a Markdown code block (three backticks on a line by themselves before and after the text) to denote a console output excerpt.
|
||||
Usually not needed for build errors (since the arguments can already be seen in the debug trace) unless you are using an unusual invocation (e.g. setting environment variables that affect the build).
|
||||
|
||||
#### Diagnostic details
|
||||
- [ ] Platform information (e.g. Ubuntu Linux 24.04):
|
||||
- [ ] OS architecture (e.g. amd64):
|
||||
- [ ] pyenv version:
|
||||
- [ ] Python version:
|
||||
- [ ] C Compiler information (e.g. gcc 7.3):
|
||||
- [ ] Please attach the debug trace of the failing command as a [gist](https://gist.github.com/):
|
||||
* Run `env PYENV_DEBUG=1 <faulty command> 2>&1 | tee trace.log` and attach `trace.log`. E.g. if you have a problem with installing Python, run `env PYENV_DEBUG=1 pyenv install -v <version> 2>&1 | tee trace.log` (note the `-v` option to `pyenv install`).
|
||||
- [ ] If you have a problem with installing Python, please also attach `config.log` from the build directory
|
||||
* The build directory is reported after the "BUILD FAILED" message and is usually under `/tmp`.
|
||||
- [ ] If the build succeeds but the problem is still with the build process (e.g. the resulting Python is missing a feature), please attach
|
||||
* the debug trace from reinstalling the faulty version with `env PYENV_DEBUG=1 pyenv install -f -k -v <version> 2>&1 | tee trace.log`
|
||||
* `config.log` from the build directory. When using `pyenv install` with `-k` as per above, the build directory will be under `$PYENV_ROOT/sources`.
|
||||
- [ ] If the problem happens in another Pyenv invocation, turn on debug logging by setting `PYENV_DEBUG=1`, e.g. `env PYENV_DEBUG=1 pyenv local 3.6.4`, and attach the resulting trace as a gist
|
||||
- [ ] If the problem happens outside of a Pyenv invocation, get the debug trace like this:
|
||||
```
|
||||
export PYENV_DEBUG=1
|
||||
# for Bash
|
||||
export PS4='+(${BASH_SOURCE}:${LINENO}): ${FUNCNAME[0]:+${FUNCNAME[0]}(): }'
|
||||
# for Zsh
|
||||
export PS4='+(%x:%I): %N(%i): '
|
||||
|
||||
set -x
|
||||
<reproduce the problem>
|
||||
set +x
|
||||
```
|
||||
24
.github/ISSUE_TEMPLATE/feature_request.md
vendored
24
.github/ISSUE_TEMPLATE/feature_request.md
vendored
|
|
@ -1,24 +0,0 @@
|
|||
---
|
||||
name: Feature request
|
||||
about: Suggest an idea for this project
|
||||
title: ''
|
||||
labels: ''
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
**Describe the intended use case**
|
||||
* What your general environment is if it's relevant to the feature request and is not a generic console with a typical Pyenv installation (CI, server with a custom setup, cloud environment, IDE)
|
||||
* What you are trying to achieve
|
||||
* What specifically you are doing for that regarding Pyenv
|
||||
* Where you are stuck
|
||||
|
||||
**Describe the solution you'd like**
|
||||
A clear and concise description of what you want to happen.
|
||||
|
||||
**Describe alternatives you've considered**
|
||||
A clear and concise description of any alternative solutions or features you've considered.
|
||||
[ ] In particular, did you consider [writing a plugin](https://github.com/pyenv/pyenv/blob/master/README.md#pyenv-plugins)? Note that if your plugin has general applicability, you can publish it in the 3rd-party plugin catalog on the Pyenv Wiki as per the link above.
|
||||
|
||||
**Additional context**
|
||||
Add any other context or screenshots about the feature request here.
|
||||
13
.github/PULL_REQUEST_TEMPLATE.md
vendored
13
.github/PULL_REQUEST_TEMPLATE.md
vendored
|
|
@ -1,13 +0,0 @@
|
|||
Make sure you have checked all steps below.
|
||||
|
||||
### Prerequisite
|
||||
* [ ] 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.
|
||||
* [ ] My PR addresses the following pyenv issue (if any)
|
||||
- Closes https://github.com/pyenv/pyenv/issues/XXXX
|
||||
|
||||
### Description
|
||||
- [ ] Here are some details about my PR
|
||||
|
||||
### Tests
|
||||
- [ ] My PR adds the following unit tests (if any)
|
||||
44
.github/actions/build-python/action.yml
vendored
44
.github/actions/build-python/action.yml
vendored
|
|
@ -1,44 +0,0 @@
|
|||
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"))
|
||||
12
.github/dependabot.yml
vendored
12
.github/dependabot.yml
vendored
|
|
@ -1,12 +1,6 @@
|
|||
version: 2
|
||||
updates:
|
||||
- package-ecosystem: "github-actions"
|
||||
directory: "/"
|
||||
- package-ecosystem: 'github-actions'
|
||||
directory: '/'
|
||||
schedule:
|
||||
interval: "monthly"
|
||||
cooldown:
|
||||
default-days: 7
|
||||
groups:
|
||||
github-actions:
|
||||
patterns:
|
||||
- "*"
|
||||
interval: 'weekly'
|
||||
|
|
|
|||
364
.github/scripts/generate_release_notes_sponsors.py
vendored
364
.github/scripts/generate_release_notes_sponsors.py
vendored
|
|
@ -1,364 +0,0 @@
|
|||
#!/usr/bin/env python3
|
||||
"""Generate a "Sponsors since <date>" section for release notes.
|
||||
|
||||
Queries GitHub Sponsors and OpenCollective for new sponsors since the latest
|
||||
pyenv release or one month ago, whichever is longer. The output is Markdown
|
||||
suitable for GitHub Releases.
|
||||
|
||||
Requirements:
|
||||
* Python 3.8+
|
||||
* The ``gh`` CLI authenticated with the ``read:user`` scope.
|
||||
* Network access to https://opencollective.com.
|
||||
"""
|
||||
|
||||
import argparse
|
||||
import calendar
|
||||
import datetime
|
||||
import json
|
||||
import pathlib
|
||||
import subprocess
|
||||
import sys
|
||||
import typing
|
||||
import urllib.error
|
||||
import urllib.request
|
||||
|
||||
|
||||
GITHUB_ORG = "pyenv"
|
||||
OPENCOLLECTIVE_MEMBERS_URL = "https://opencollective.com/pyenv/members.json"
|
||||
|
||||
|
||||
class SponsorDataError(RuntimeError):
|
||||
"""Raised when a sponsors data source cannot be queried or parsed."""
|
||||
|
||||
|
||||
def parse_date(value: str) -> datetime.date:
|
||||
return datetime.datetime.fromisoformat(value).date()
|
||||
|
||||
|
||||
def one_month_ago(today: typing.Optional[datetime.date] = None) -> datetime.date:
|
||||
today = today or datetime.date.today()
|
||||
year = today.year
|
||||
month = today.month - 1
|
||||
if month == 0:
|
||||
year -= 1
|
||||
month = 12
|
||||
try:
|
||||
return datetime.date(year, month, today.day)
|
||||
except ValueError:
|
||||
last_day = calendar.monthrange(year, month)[1]
|
||||
return datetime.date(year, month, last_day)
|
||||
|
||||
|
||||
def latest_release_date() -> datetime.date:
|
||||
"""Return the publish date of the latest GitHub release."""
|
||||
latest_release_error = None
|
||||
try:
|
||||
result = subprocess.run(
|
||||
["gh", "api", f"repos/{GITHUB_ORG}/{GITHUB_ORG}/releases/latest"],
|
||||
capture_output=True,
|
||||
text=True,
|
||||
check=True,
|
||||
)
|
||||
data = json.loads(result.stdout)
|
||||
published = data["published_at"].replace("Z", "+00:00")
|
||||
return datetime.datetime.fromisoformat(published).date()
|
||||
except (
|
||||
subprocess.CalledProcessError,
|
||||
OSError,
|
||||
json.JSONDecodeError,
|
||||
KeyError,
|
||||
) as exc:
|
||||
latest_release_error = exc
|
||||
|
||||
try:
|
||||
tag = subprocess.run(
|
||||
["git", "describe", "--tags", "--abbrev=0"],
|
||||
capture_output=True,
|
||||
text=True,
|
||||
check=True,
|
||||
).stdout.strip()
|
||||
date_str = subprocess.run(
|
||||
["git", "log", "-1", "--format=%cI", tag],
|
||||
capture_output=True,
|
||||
text=True,
|
||||
check=True,
|
||||
).stdout.strip()
|
||||
return datetime.datetime.fromisoformat(date_str).date()
|
||||
except (subprocess.CalledProcessError, OSError) as exc:
|
||||
detail = ""
|
||||
if latest_release_error is not None:
|
||||
detail = f" GitHub release lookup failed first: {latest_release_error}."
|
||||
raise SponsorDataError(
|
||||
"Could not determine the latest release date. "
|
||||
"Pass --since explicitly or run from a clone with release tags."
|
||||
f"{detail}"
|
||||
) from exc
|
||||
|
||||
|
||||
def compute_since_date(explicit_since: typing.Optional[datetime.date]) -> datetime.date:
|
||||
if explicit_since is not None:
|
||||
return explicit_since
|
||||
return min(latest_release_date(), one_month_ago())
|
||||
|
||||
|
||||
def github_sponsors(since: datetime.date) -> typing.List[typing.Dict]:
|
||||
"""Return GitHub Sponsors created on or after *since*."""
|
||||
query = """
|
||||
query($org: String!, $after: String) {
|
||||
organization(login: $org) {
|
||||
sponsorshipsAsMaintainer(
|
||||
first: 100,
|
||||
after: $after,
|
||||
activeOnly: false,
|
||||
orderBy: {field: CREATED_AT, direction: DESC}
|
||||
) {
|
||||
pageInfo {
|
||||
hasNextPage
|
||||
endCursor
|
||||
}
|
||||
nodes {
|
||||
createdAt
|
||||
sponsorEntity {
|
||||
... on User { login, name }
|
||||
... on Organization { login, name }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
"""
|
||||
since_dt = datetime.datetime.combine(
|
||||
since, datetime.time.min, tzinfo=datetime.timezone.utc
|
||||
)
|
||||
sponsors = []
|
||||
cursor = None
|
||||
while True:
|
||||
command = [
|
||||
"gh",
|
||||
"api",
|
||||
"graphql",
|
||||
"-F",
|
||||
f"org={GITHUB_ORG}",
|
||||
"-f",
|
||||
f"query={query}",
|
||||
]
|
||||
if cursor is not None:
|
||||
command.extend(["-F", f"after={cursor}"])
|
||||
|
||||
result = subprocess.run(
|
||||
command,
|
||||
capture_output=True,
|
||||
text=True,
|
||||
)
|
||||
if result.returncode != 0:
|
||||
detail = result.stderr.strip() or result.stdout.strip() or "no output"
|
||||
raise SponsorDataError(
|
||||
"GitHub Sponsors query failed. "
|
||||
"Check that `gh auth status` shows access to the pyenv org "
|
||||
"and that the token has the scopes required to read sponsorships. "
|
||||
f"`gh api graphql` exited {result.returncode}: {detail}"
|
||||
)
|
||||
|
||||
try:
|
||||
data = json.loads(result.stdout)
|
||||
except json.JSONDecodeError as exc:
|
||||
raise SponsorDataError(
|
||||
"GitHub Sponsors query returned invalid JSON."
|
||||
) from exc
|
||||
|
||||
if "errors" in data:
|
||||
raise SponsorDataError(
|
||||
f"GitHub Sponsors query returned errors: {data['errors']}"
|
||||
)
|
||||
|
||||
try:
|
||||
sponsorships = data["data"]["organization"]["sponsorshipsAsMaintainer"]
|
||||
except (TypeError, KeyError) as exc:
|
||||
raise SponsorDataError(
|
||||
"GitHub Sponsors query returned an unexpected response shape."
|
||||
) from exc
|
||||
try:
|
||||
nodes = sponsorships["nodes"]
|
||||
page_info = sponsorships["pageInfo"]
|
||||
except (TypeError, KeyError) as exc:
|
||||
raise SponsorDataError(
|
||||
"GitHub Sponsors query returned incomplete pagination data."
|
||||
) from exc
|
||||
|
||||
for node in nodes:
|
||||
try:
|
||||
created = datetime.datetime.fromisoformat(
|
||||
node["createdAt"].replace("Z", "+00:00")
|
||||
)
|
||||
entity = node["sponsorEntity"]
|
||||
login = entity["login"]
|
||||
except (AttributeError, KeyError, TypeError, ValueError) as exc:
|
||||
raise SponsorDataError(
|
||||
"GitHub Sponsors query returned an unexpected sponsor record."
|
||||
) from exc
|
||||
if created < since_dt:
|
||||
return sponsors
|
||||
sponsors.append({
|
||||
"login": login,
|
||||
"name": entity.get("name") or login,
|
||||
})
|
||||
|
||||
try:
|
||||
has_next_page = page_info["hasNextPage"]
|
||||
cursor = page_info["endCursor"]
|
||||
except (TypeError, KeyError) as exc:
|
||||
raise SponsorDataError(
|
||||
"GitHub Sponsors query returned incomplete pagination data."
|
||||
) from exc
|
||||
if not has_next_page:
|
||||
return sponsors
|
||||
|
||||
|
||||
def opencollective_sponsors(since: datetime.date, data: typing.Union[str, None]) -> typing.List[typing.Dict]:
|
||||
"""Return OpenCollective backers active on or after *since*."""
|
||||
if data is None:
|
||||
req = urllib.request.Request(
|
||||
f"{OPENCOLLECTIVE_MEMBERS_URL}?limit=1000",
|
||||
headers={"User-Agent": f"{GITHUB_ORG}/release-notes-sponsors"},
|
||||
)
|
||||
try:
|
||||
with urllib.request.urlopen(req, timeout=30) as resp:
|
||||
data = resp.read()
|
||||
except urllib.error.HTTPError as exc:
|
||||
raise SponsorDataError(
|
||||
f"OpenCollective sponsors query failed for {OPENCOLLECTIVE_MEMBERS_URL}: "
|
||||
f"HTTP {exc.code} {exc.reason}"
|
||||
) from exc
|
||||
except urllib.error.URLError as exc:
|
||||
raise SponsorDataError(
|
||||
f"OpenCollective sponsors query failed for {OPENCOLLECTIVE_MEMBERS_URL}: "
|
||||
f"{exc.reason}"
|
||||
) from exc
|
||||
try:
|
||||
members = json.loads(data)
|
||||
except json.JSONDecodeError as exc:
|
||||
raise SponsorDataError(
|
||||
"OpenCollective sponsors query returned invalid JSON."
|
||||
) from exc
|
||||
|
||||
since_dt = datetime.datetime.combine(since, datetime.time.min)
|
||||
sponsors = []
|
||||
for member in members:
|
||||
if member.get("role") != "BACKER":
|
||||
continue
|
||||
try:
|
||||
last_transaction_at = datetime.datetime.strptime(member["lastTransactionAt"], "%Y-%m-%d %H:%M")
|
||||
profile = member["profile"].rstrip("/")
|
||||
except (KeyError, TypeError, ValueError) as exc:
|
||||
raise SponsorDataError(
|
||||
"OpenCollective sponsors query returned an unexpected member record."
|
||||
) from exc
|
||||
if last_transaction_at < since_dt:
|
||||
continue
|
||||
slug = profile.split("/")[-1]
|
||||
if slug == "github-sponsors":
|
||||
# Listed separately under GitHub Sponsors.
|
||||
continue
|
||||
sponsors.append({
|
||||
"name": member.get("name") or slug,
|
||||
"profile": profile,
|
||||
})
|
||||
return sponsors
|
||||
|
||||
|
||||
def render(
|
||||
since: datetime.date,
|
||||
gh_sponsors: typing.List[typing.Dict],
|
||||
oc_sponsors: typing.List[typing.Dict],
|
||||
) -> str:
|
||||
lines = [f"## Sponsors since {since.isoformat()}", ""]
|
||||
|
||||
if gh_sponsors:
|
||||
lines.append("### GitHub Sponsors")
|
||||
for sponsor in gh_sponsors:
|
||||
lines.append(
|
||||
markdown_link(
|
||||
sponsor["name"],
|
||||
f"https://github.com/{sponsor['login']}",
|
||||
)
|
||||
)
|
||||
lines.append("")
|
||||
|
||||
if oc_sponsors:
|
||||
lines.append("### Open Collective")
|
||||
for sponsor in oc_sponsors:
|
||||
lines.append(markdown_link(sponsor["name"], sponsor["profile"]))
|
||||
lines.append("")
|
||||
|
||||
if not gh_sponsors and not oc_sponsors:
|
||||
lines.append("*No new sponsors in this period.*")
|
||||
lines.append("")
|
||||
|
||||
return "\n".join(lines)
|
||||
|
||||
|
||||
def markdown_link(text: str, url: str) -> str:
|
||||
escaped_text = escape_markdown_text(text)
|
||||
escaped_url = url.replace(")", "%29")
|
||||
return f"- [{escaped_text}]({escaped_url})"
|
||||
|
||||
|
||||
def escape_markdown_text(text: str) -> str:
|
||||
escaped = text.replace("\\", "\\\\")
|
||||
for char in r"`*_{}[]()#+-.!|>":
|
||||
escaped = escaped.replace(char, f"\\{char}")
|
||||
return escaped
|
||||
|
||||
|
||||
def main() -> int:
|
||||
parser = argparse.ArgumentParser(
|
||||
description="Generate a sponsors section for GitHub release notes."
|
||||
)
|
||||
parser.add_argument(
|
||||
"--since",
|
||||
type=parse_date,
|
||||
metavar="YYYY-MM-DD",
|
||||
help="Include sponsors created on or after this date.",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--output",
|
||||
metavar="FILE",
|
||||
help="Write the section to FILE instead of stdout.",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--skip-opencollective",
|
||||
action="store_true",
|
||||
help="Skip OpenCollective backers if the members endpoint is unavailable.",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--opencollective-data",
|
||||
metavar="FILE",
|
||||
help="Take OpenCollective API reply from FILE.",
|
||||
)
|
||||
args = parser.parse_args()
|
||||
|
||||
try:
|
||||
since = compute_since_date(args.since)
|
||||
oc_sponsors = []
|
||||
if not args.skip_opencollective:
|
||||
manual_data = (
|
||||
pathlib.Path(args.opencollective_data).read_text()) \
|
||||
if args.opencollective_data \
|
||||
else None
|
||||
oc_sponsors = opencollective_sponsors(since, manual_data)
|
||||
section = render(since, github_sponsors(since), oc_sponsors)
|
||||
except SponsorDataError as exc:
|
||||
print(f"error: {exc}", file=sys.stderr)
|
||||
return 1
|
||||
|
||||
if args.output:
|
||||
with open(args.output, "w", encoding="utf-8") as f:
|
||||
f.write(section)
|
||||
else:
|
||||
print(section, end="")
|
||||
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
58
.github/workflows/add_version.yml
vendored
58
.github/workflows/add_version.yml
vendored
|
|
@ -1,58 +0,0 @@
|
|||
name: Add versions
|
||||
|
||||
on:
|
||||
workflow_dispatch: {}
|
||||
schedule:
|
||||
# Every N hours
|
||||
- cron: '25 */4 * * *'
|
||||
|
||||
permissions:
|
||||
contents: write
|
||||
pull-requests: write
|
||||
|
||||
jobs:
|
||||
add_cpython:
|
||||
runs-on: ubuntu-slim
|
||||
steps:
|
||||
- uses: actions/checkout@v7
|
||||
- uses: actions/setup-python@v7
|
||||
with:
|
||||
python-version: 3
|
||||
cache: 'pip'
|
||||
cache-dependency-path: plugins/python-build/scripts/requirements.txt
|
||||
- run: pip install -r plugins/python-build/scripts/requirements.txt
|
||||
|
||||
- name: check for a release
|
||||
run: |
|
||||
python plugins/python-build/scripts/add_cpython.py --verbose >added_versions.lst && rc=$? || rc=$?
|
||||
#0 means new version found, 1 not found, 2 another error
|
||||
[[ $rc -gt 1 ]] && false
|
||||
echo "rc=$rc" >> $GITHUB_ENV
|
||||
- name: set PR properties
|
||||
if: env.rc == 0
|
||||
shell: python
|
||||
run: |
|
||||
import os
|
||||
import sys
|
||||
versions=[l.rstrip() for l in open("added_versions.lst")]
|
||||
with open(os.environ['GITHUB_ENV'],'a') as f:
|
||||
f.write(f'branch_name=auto_add_version/{"_".join(versions)}\n')
|
||||
f.write(f'pr_name=Add CPython {", ".join(versions)}\n')
|
||||
os.remove("added_versions.lst")
|
||||
|
||||
# https://github.com/peter-evans/create-pull-request/blob/main/docs/concepts-guidelines.md#authenticating-with-github-app-generated-tokens
|
||||
- name: Generate Github token
|
||||
if: env.rc == 0
|
||||
uses: actions/create-github-app-token@v3
|
||||
id: generate-token
|
||||
with:
|
||||
app-id: ${{ vars.PYENV_BOT_APP_ID }}
|
||||
private-key: ${{ secrets.PYENV_BOT_PRIVATE_KEY }}
|
||||
- name: Create Pull Request
|
||||
uses: peter-evans/create-pull-request@v8
|
||||
if: env.rc == 0
|
||||
with:
|
||||
branch: ${{ env.branch_name }}
|
||||
title: ${{ env.pr_name }}
|
||||
commit-message: ${{ env.pr_name }}
|
||||
token: ${{ steps.generate-token.outputs.token }}
|
||||
62
.github/workflows/build.yml
vendored
62
.github/workflows/build.yml
vendored
|
|
@ -1,62 +0,0 @@
|
|||
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 }}
|
||||
|
||||
17
.github/workflows/ci.yml
vendored
Normal file
17
.github/workflows/ci.yml
vendored
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
name: CI
|
||||
on: [push, pull_request]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ${{ matrix.os }}
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
os: [ubuntu-latest, macos-latest]
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- name: Install bats
|
||||
run: git clone --depth 1 --branch v1.10.0 https://github.com/bats-core/bats-core.git bats
|
||||
- name: Run tests
|
||||
run: PATH="./bats/bin:$PATH" test/run
|
||||
29
.github/workflows/lint.yml
vendored
Normal file
29
.github/workflows/lint.yml
vendored
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
---
|
||||
|
||||
name: Lint
|
||||
on:
|
||||
push:
|
||||
branches: [master]
|
||||
pull_request:
|
||||
branches: [master]
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
jobs:
|
||||
shellcheck:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
permissions:
|
||||
security-events: write
|
||||
|
||||
steps:
|
||||
- name: Repository checkout
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Differential ShellCheck
|
||||
uses: redhat-plumbers-in-action/differential-shellcheck@v5
|
||||
with:
|
||||
token: ${{ secrets.GITHUB_TOKEN }}
|
||||
304
.github/workflows/modified_scripts_build.yml
vendored
304
.github/workflows/modified_scripts_build.yml
vendored
|
|
@ -1,304 +0,0 @@
|
|||
name: modified_scripts
|
||||
on: [pull_request]
|
||||
jobs:
|
||||
discover_modified_scripts:
|
||||
runs-on: ubuntu-slim
|
||||
outputs:
|
||||
versions: ${{steps.modified-versions.outputs.versions}}
|
||||
versions_cpython_only: ${{steps.modified-versions.outputs.versions_cpython_only}}
|
||||
versions_macos_build_exclude: ${{steps.modified-versions.outputs.versions_macos_build_exclude}}
|
||||
steps:
|
||||
- uses: actions/checkout@v7
|
||||
- run: git fetch origin "$GITHUB_BASE_REF"
|
||||
- shell: bash
|
||||
run: >
|
||||
versions=$(git diff "origin/$GITHUB_BASE_REF" --name-only -z
|
||||
| perl -ne 'BEGIN {$\="\n";$/="\0";} chomp;
|
||||
if (/^(plugins\/python-build\/share\/python-build\/)(?:([^\/]+)|patches\/([^\/]+)\/.*)$/ and -e $& )
|
||||
{
|
||||
print $2.$3;
|
||||
if ( -e $1.$2.$3.t ) { print $2.$3.t; }
|
||||
}' \
|
||||
| sort -u);
|
||||
EOF=$(dd if=/dev/urandom bs=15 count=1 status=none | base64);
|
||||
echo "versions<<$EOF" >> $GITHUB_ENV;
|
||||
echo "$versions" >> $GITHUB_ENV;
|
||||
echo "$EOF" >> $GITHUB_ENV;
|
||||
|
||||
versions_cpython_only=$(grep -Ee '^[[:digit:]]' <<<"$versions")
|
||||
EOF=$(dd if=/dev/urandom bs=15 count=1 status=none | base64);
|
||||
echo "versions_cpython_only<<$EOF" >> $GITHUB_ENV;
|
||||
echo "$versions_cpython_only" >> $GITHUB_ENV;
|
||||
echo "$EOF" >> $GITHUB_ENV;
|
||||
- run: pip install packaging
|
||||
- name: Build exclusions JSON
|
||||
shell: python
|
||||
run: |
|
||||
import os
|
||||
import json
|
||||
import random
|
||||
import re
|
||||
import subprocess
|
||||
|
||||
import packaging.version
|
||||
|
||||
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():
|
||||
if m:=re.match(r'miniconda3-\d+\.\d+-(\d+\.\d+\.\d+)', line):
|
||||
version = packaging.version.Version(m.group(1))
|
||||
|
||||
# Miniconda dropped MacOS x64 support
|
||||
if version >= packaging.version.Version('25.9.1'):
|
||||
exclude_macos_intel(result, line)
|
||||
|
||||
if m:=re.match(r'anaconda3-(\d+\.\d+)', line):
|
||||
version = packaging.version.Version(m.group(1))
|
||||
|
||||
# Anaconda dropped MacOS x64 support
|
||||
if version >= packaging.version.Version('2025.12'):
|
||||
exclude_macos_intel(result, line)
|
||||
|
||||
if m:=re.match(r'graalpy[^-]*-(community-)?(\d+\.\d+\.\d+)', line):
|
||||
version = packaging.version.Version(m.group(2))
|
||||
|
||||
# GraalPy dropped MacOS x64 support
|
||||
if version >= packaging.version.Version('25.0.2'):
|
||||
exclude_macos_intel(result, line)
|
||||
|
||||
|
||||
EOF = str(random.getrandbits(15*8))
|
||||
|
||||
with open(os.environ['GITHUB_ENV'],'w') as f:
|
||||
f.write(f"versions_macos_build_exclude_json<<{EOF}\n")
|
||||
json.dump(result, f)
|
||||
f.write(f'\n{EOF}\n')
|
||||
|
||||
- id: modified-versions
|
||||
run: |
|
||||
echo "versions=`echo "${{ env.versions }}" | jq -R . | jq -sc .`" >> $GITHUB_OUTPUT
|
||||
echo "versions_cpython_only=`echo "${{ env.versions_cpython_only }}" | jq -R . | jq -sc .`" >> $GITHUB_OUTPUT
|
||||
echo 'versions_macos_build_exclude=${{ env.versions_macos_build_exclude_json }}' >> $GITHUB_OUTPUT
|
||||
macos_build:
|
||||
needs: discover_modified_scripts
|
||||
if: needs.discover_modified_scripts.outputs.versions != '[""]'
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
python-version: ${{fromJson(needs.discover_modified_scripts.outputs.versions)}}
|
||||
os:
|
||||
- macos-14
|
||||
- macos-15
|
||||
- macos-15-intel
|
||||
- macos-26
|
||||
- macos-26-intel
|
||||
exclude: ${{fromJson(needs.discover_modified_scripts.outputs.versions_macos_build_exclude)}}
|
||||
runs-on: ${{ matrix.os }}
|
||||
steps:
|
||||
- uses: actions/checkout@v7
|
||||
- run: |
|
||||
#envvars
|
||||
export PYENV_ROOT="$GITHUB_WORKSPACE"
|
||||
echo "PYENV_ROOT=$PYENV_ROOT" >> $GITHUB_ENV
|
||||
echo "$PYENV_ROOT/shims:$PYENV_ROOT/bin" >> $GITHUB_PATH
|
||||
- run: |
|
||||
#prerequisites
|
||||
brew install openssl readline sqlite3 xz tcl-tk@8 libb2 zstd
|
||||
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: |
|
||||
#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 }}
|
||||
# Micropython doesn't support --version
|
||||
- run: |
|
||||
#print version
|
||||
if [[ "${{ matrix.python-version }}" == "micropython-"* ]]; then
|
||||
python -c 'import sys; print(sys.version)'
|
||||
else
|
||||
python --version
|
||||
python -m pip --version
|
||||
fi
|
||||
# Micropython doesn't support sys.executable, os.path, older versions even os
|
||||
- env:
|
||||
EXPECTED_PYTHON: ${{ matrix.python-version }}
|
||||
run: |
|
||||
#check
|
||||
if [[ "${{ matrix.python-version }}" == "micropython-"* ]]; then
|
||||
[[ $(pyenv which python) == "${{ env.PYENV_ROOT }}/versions/${{ matrix.python-version }}/bin/python" ]] || exit 1
|
||||
python -c 'import sys; assert sys.implementation.name == "micropython"'
|
||||
else
|
||||
python -c 'if True:
|
||||
import os, sys, os.path
|
||||
correct_dir = os.path.join(
|
||||
os.environ["PYENV_ROOT"],
|
||||
"versions",
|
||||
os.environ["EXPECTED_PYTHON"],
|
||||
"bin")
|
||||
assert os.path.dirname(sys.executable) == correct_dir'
|
||||
fi
|
||||
# bundled executables in some Anaconda releases cause the post-run step to hang in MacOS
|
||||
- run: |
|
||||
pyenv global system
|
||||
rm -f "$(pyenv root)"/shims/*
|
||||
|
||||
|
||||
macos_build_bundled_dependencies:
|
||||
needs: discover_modified_scripts
|
||||
if: needs.discover_modified_scripts.outputs.versions_cpython_only != '[""]'
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
python-version: ${{fromJson(needs.discover_modified_scripts.outputs.versions_cpython_only)}}
|
||||
os:
|
||||
- macos-14
|
||||
- macos-15
|
||||
- macos-15-intel
|
||||
- macos-26
|
||||
- macos-26-intel
|
||||
runs-on: ${{ matrix.os }}
|
||||
steps:
|
||||
- uses: actions/checkout@v7
|
||||
- run: |
|
||||
#envvars
|
||||
export PYENV_ROOT="$GITHUB_WORKSPACE"
|
||||
echo "PYENV_ROOT=$PYENV_ROOT" >> $GITHUB_ENV
|
||||
echo "$PYENV_ROOT/shims:$PYENV_ROOT/bin" >> $GITHUB_PATH
|
||||
- run: |
|
||||
#prerequisites
|
||||
brew install sqlite3 xz tcl-tk@8 libb2 zstd
|
||||
"$GITHUB_WORKSPACE/.github/workflows/scripts/brew-uninstall-cascade.sh" $(brew list | grep -E '^openssl(@|$)') readline
|
||||
- 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
|
||||
- env:
|
||||
EXPECTED_PYTHON: ${{ matrix.python-version }}
|
||||
run: |
|
||||
#check
|
||||
python -c '
|
||||
import os, sys, os.path
|
||||
correct_dir = os.path.join(
|
||||
os.environ["PYENV_ROOT"],
|
||||
"versions",
|
||||
os.environ["EXPECTED_PYTHON"],
|
||||
"bin")
|
||||
assert os.path.dirname(sys.executable) == correct_dir'
|
||||
|
||||
ubuntu_build:
|
||||
needs: discover_modified_scripts
|
||||
if: needs.discover_modified_scripts.outputs.versions != '[""]'
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
python-version: ${{fromJson(needs.discover_modified_scripts.outputs.versions)}}
|
||||
os:
|
||||
- ubuntu-22.04
|
||||
- ubuntu-22.04-arm
|
||||
- ubuntu-24.04
|
||||
- ubuntu-24.04-arm
|
||||
runs-on: ${{ matrix.os }}
|
||||
steps:
|
||||
- uses: actions/checkout@v7
|
||||
- run: |
|
||||
#envvars
|
||||
export PYENV_ROOT="$GITHUB_WORKSPACE"
|
||||
echo "PYENV_ROOT=$PYENV_ROOT" >> $GITHUB_ENV
|
||||
echo "$PYENV_ROOT/shims:$PYENV_ROOT/bin" >> $GITHUB_PATH
|
||||
- run: |
|
||||
#prerequisites
|
||||
pyenv install-prerequisites
|
||||
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: |
|
||||
#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 }}
|
||||
# Micropython doesn't support --version
|
||||
- run: |
|
||||
#print version
|
||||
if [[ "${{ matrix.python-version }}" == "micropython-"* ]]; then
|
||||
python -c 'import sys; print(sys.version)'
|
||||
else
|
||||
python --version
|
||||
python -m pip --version
|
||||
fi
|
||||
# Micropython doesn't support sys.executable, os.path, older versions even os
|
||||
- env:
|
||||
EXPECTED_PYTHON: ${{ matrix.python-version }}
|
||||
run: |
|
||||
#check
|
||||
if [[ "${{ matrix.python-version }}" == "micropython-"* ]]; then
|
||||
[[ $(pyenv which python) == "${{ env.PYENV_ROOT }}/versions/${{ matrix.python-version }}/bin/python" ]] || exit 1
|
||||
python -c 'import sys; assert sys.implementation.name == "micropython"'
|
||||
else
|
||||
python -c 'if True:
|
||||
import os, sys, os.path
|
||||
correct_dir = os.path.join(
|
||||
os.environ["PYENV_ROOT"],
|
||||
"versions",
|
||||
os.environ["EXPECTED_PYTHON"],
|
||||
"bin")
|
||||
assert os.path.dirname(sys.executable) == correct_dir'
|
||||
fi
|
||||
# bundled executables in some Anaconda releases cause the post-run step to break
|
||||
- run: |
|
||||
pyenv global system
|
||||
rm -f "$(pyenv root)"/shims/*
|
||||
ubuntu_build_tar_gz:
|
||||
needs: discover_modified_scripts
|
||||
if: needs.discover_modified_scripts.outputs.versions_cpython_only != '[""]'
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
python-version: ${{fromJson(needs.discover_modified_scripts.outputs.versions_cpython_only)}}
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v7
|
||||
- run: |
|
||||
#envvars
|
||||
export PYENV_ROOT="$GITHUB_WORKSPACE"
|
||||
echo "PYENV_ROOT=$PYENV_ROOT" >> $GITHUB_ENV
|
||||
echo "$PYENV_ROOT/shims:$PYENV_ROOT/bin" >> $GITHUB_PATH
|
||||
echo "_PYTHON_BUILD_FORCE_SKIP_XZ=1" >> $GITHUB_ENV
|
||||
- run: |
|
||||
#prerequisites
|
||||
pyenv install-prerequisites
|
||||
- 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
|
||||
- env:
|
||||
EXPECTED_PYTHON: ${{ matrix.python-version }}
|
||||
run: |
|
||||
#check
|
||||
python -c '
|
||||
import os, sys, os.path
|
||||
correct_dir = os.path.join(
|
||||
os.environ["PYENV_ROOT"],
|
||||
"versions",
|
||||
os.environ["EXPECTED_PYTHON"],
|
||||
"bin")
|
||||
assert os.path.dirname(sys.executable) == correct_dir'
|
||||
30
.github/workflows/no-response.yml
vendored
30
.github/workflows/no-response.yml
vendored
|
|
@ -1,30 +0,0 @@
|
|||
name: No Response
|
||||
|
||||
# Both `issue_comment` and `scheduled` event types are required for this Action
|
||||
# to work properly.
|
||||
on:
|
||||
issue_comment:
|
||||
types: [created]
|
||||
schedule:
|
||||
# Schedule for ten minutes after the hour, every 2 hours
|
||||
- cron: '10 */2 * * *'
|
||||
|
||||
permissions: {}
|
||||
jobs:
|
||||
noResponse:
|
||||
permissions:
|
||||
issues: write # to update issues (lee-dohm/no-response)
|
||||
|
||||
runs-on: ubuntu-slim
|
||||
steps:
|
||||
- uses: lee-dohm/no-response@v0.5.0
|
||||
with:
|
||||
token: ${{ github.token }}
|
||||
daysUntilClose: 30
|
||||
responseRequiredLabel: need-feedback
|
||||
closeComment: >
|
||||
This issue has been automatically closed because there has been no response
|
||||
to our request for more information from the original author. With only the
|
||||
information that is currently in the issue, we don't have enough information
|
||||
to take action. Please reach out if you have or find the answers we need so
|
||||
that we can investigate further.
|
||||
45
.github/workflows/pyenv_tests.yml
vendored
45
.github/workflows/pyenv_tests.yml
vendored
|
|
@ -1,45 +0,0 @@
|
|||
name: pyenv_tests
|
||||
on:
|
||||
push:
|
||||
branches: [master]
|
||||
pull_request: {}
|
||||
|
||||
permissions:
|
||||
contents: read # to fetch code (actions/checkout)
|
||||
|
||||
jobs:
|
||||
pyenv_tests:
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
os:
|
||||
- ubuntu-22.04
|
||||
- ubuntu-22.04-arm
|
||||
- ubuntu-24.04
|
||||
- ubuntu-24.04-arm
|
||||
- macos-14
|
||||
- macos-15
|
||||
- macos-15-intel
|
||||
- macos-26
|
||||
runs-on: ${{ matrix.os }}
|
||||
steps:
|
||||
- uses: actions/checkout@v7
|
||||
- name: Install prerequisites
|
||||
run: |
|
||||
if test "$RUNNER_OS" == "macOS"; then
|
||||
brew install coreutils fish
|
||||
fi
|
||||
- name: Run tests
|
||||
run: |
|
||||
make test
|
||||
- env:
|
||||
PYENV_NATIVE_EXT: 1
|
||||
run: |
|
||||
(cd src; ./configure; make)
|
||||
bats/bin/bats test/{pyenv,hooks,versions}.bats
|
||||
pyenv_tests_docker:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v7
|
||||
- run: |
|
||||
make test-docker
|
||||
16
.github/workflows/release.yml
vendored
Normal file
16
.github/workflows/release.yml
vendored
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
name: Release
|
||||
on:
|
||||
push:
|
||||
tags: 'v*'
|
||||
|
||||
jobs:
|
||||
homebrew:
|
||||
name: Bump Homebrew formula
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: mislav/bump-homebrew-formula-action@v3.2
|
||||
if: "!contains(github.ref, '-')" # skip prereleases
|
||||
with:
|
||||
formula-name: rbenv
|
||||
env:
|
||||
COMMITTER_TOKEN: ${{ secrets.COMMITTER_TOKEN }}
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
#!/bin/bash
|
||||
|
||||
declare -a packages rdepends
|
||||
packages=("$@")
|
||||
|
||||
# have to try one by one, otherwise `brew uses` would only print
|
||||
# packages that require them all rather than any of them
|
||||
for package in "${packages[@]}"; do
|
||||
rdepends+=($(brew uses --installed --include-build --include-test --include-optional --recursive "$package"))
|
||||
done
|
||||
brew uninstall "${packages[@]}" "${rdepends[@]}"
|
||||
8
.gitignore
vendored
8
.gitignore
vendored
|
|
@ -1,3 +1,4 @@
|
|||
/plugins
|
||||
/shims
|
||||
/version
|
||||
/versions
|
||||
|
|
@ -6,9 +7,4 @@
|
|||
/libexec/*.dylib
|
||||
/src/Makefile
|
||||
/src/*.o
|
||||
/bats
|
||||
/bats-*/
|
||||
/default-packages
|
||||
.idea
|
||||
*.un~
|
||||
*.swp
|
||||
/gems
|
||||
|
|
|
|||
1709
CHANGELOG.md
1709
CHANGELOG.md
File diff suppressed because it is too large
Load diff
|
|
@ -67,9 +67,9 @@ members of the project's leadership.
|
|||
|
||||
## Project Maintainers
|
||||
|
||||
* Yamashita, Yuu <<peek824545201@gmail.com>>
|
||||
* Daniel Hahler <<git@thequod.de>>
|
||||
* Josh Friend <<josh@fueledbycaffeine.com>>
|
||||
* Sam Stephenson <<sstephenson@gmail.com>>
|
||||
* Mislav Marohnić <<mislav.marohnic@gmail.com>>
|
||||
* Erik Michaels-Ober <<sferik@gmail.com>>
|
||||
|
||||
## Attribution
|
||||
|
||||
411
COMMANDS.md
411
COMMANDS.md
|
|
@ -1,411 +0,0 @@
|
|||
# Command Reference
|
||||
|
||||
Like `git`, the `pyenv` command delegates to subcommands based on its
|
||||
first argument.
|
||||
|
||||
The most common subcommands are:
|
||||
|
||||
* [`pyenv help`](#pyenv-help)
|
||||
* [`pyenv commands`](#pyenv-commands)
|
||||
* [`pyenv local`](#pyenv-local)
|
||||
* [`pyenv global`](#pyenv-global)
|
||||
* [`pyenv shell`](#pyenv-shell)
|
||||
* [`pyenv install`](#pyenv-install)
|
||||
* [`pyenv uninstall`](#pyenv-uninstall)
|
||||
* [`pyenv rehash`](#pyenv-rehash)
|
||||
* [`pyenv version`](#pyenv-version)
|
||||
* [`pyenv versions`](#pyenv-versions)
|
||||
* [`pyenv which`](#pyenv-which)
|
||||
* [`pyenv whence`](#pyenv-whence)
|
||||
* [`pyenv exec`](#pyenv-exec)
|
||||
* [`pyenv root`](#pyenv-root)
|
||||
* [`pyenv prefix`](#pyenv-prefix)
|
||||
* [`pyenv latest`](#pyenv-latest)
|
||||
* [`pyenv hooks`](#pyenv-hooks)
|
||||
* [`pyenv shims`](#pyenv-shims)
|
||||
* [`pyenv init`](#pyenv-init)
|
||||
* [`pyenv completions`](#pyenv-completions)
|
||||
|
||||
## `pyenv help`
|
||||
|
||||
List all available pyenv commands along with a brief description of what they do. Run `pyenv help <command>` for information on a specific command. For full documentation, see: https://github.com/pyenv/pyenv#readme
|
||||
|
||||
|
||||
## `pyenv commands`
|
||||
|
||||
Lists all available pyenv commands.
|
||||
|
||||
|
||||
## `pyenv local`
|
||||
|
||||
Sets a local application-specific Python version by writing the version
|
||||
name to a `.python-version` file in the current directory. This version
|
||||
overrides the [global version](#pyenv-global), and can be overridden
|
||||
itself with the [`pyenv shell`](#pyenv-shell) command.
|
||||
|
||||
$ pyenv local 2.7.6
|
||||
|
||||
When run without a version number, `pyenv local` reports the currently
|
||||
configured local version. You can also unset the local version:
|
||||
|
||||
$ pyenv local --unset
|
||||
|
||||
Previous versions of pyenv stored local version specifications in a
|
||||
file named `.pyenv-version`. For backwards compatibility, pyenv will
|
||||
read a local version specified in an `.pyenv-version` file, but a
|
||||
`.python-version` file in the same directory will take precedence.
|
||||
|
||||
|
||||
### `pyenv local` (advanced)
|
||||
|
||||
You can specify multiple versions as local Python at once.
|
||||
|
||||
Let's say if you have two versions of 2.7.6 and 3.3.3. If you prefer 2.7.6 over 3.3.3,
|
||||
|
||||
$ pyenv local 2.7.6 3.3.3
|
||||
$ pyenv versions
|
||||
system
|
||||
* 2.7.6 (set by /Users/yyuu/path/to/project/.python-version)
|
||||
* 3.3.3 (set by /Users/yyuu/path/to/project/.python-version)
|
||||
$ python --version
|
||||
Python 2.7.6
|
||||
$ python2.7 --version
|
||||
Python 2.7.6
|
||||
$ python3.3 --version
|
||||
Python 3.3.3
|
||||
|
||||
or, if you prefer 3.3.3 over 2.7.6,
|
||||
|
||||
$ pyenv local 3.3.3 2.7.6
|
||||
$ pyenv versions
|
||||
system
|
||||
* 2.7.6 (set by /Users/yyuu/path/to/project/.python-version)
|
||||
* 3.3.3 (set by /Users/yyuu/path/to/project/.python-version)
|
||||
venv27
|
||||
$ python --version
|
||||
Python 3.3.3
|
||||
$ python2.7 --version
|
||||
Python 2.7.6
|
||||
$ python3.3 --version
|
||||
Python 3.3.3
|
||||
|
||||
|
||||
You can use the `-f/--force` flag to force setting versions even if some aren't installed.
|
||||
This is mainly useful in special cases like provisioning scripts.
|
||||
|
||||
|
||||
## `pyenv global`
|
||||
|
||||
Sets the global version of Python to be used in all shells by writing
|
||||
the version name to the `$PYENV_ROOT/version` file. This version can be
|
||||
overridden with [`pyenv local`](#pyenv-local) or [`pyenv shell`](#pyenv-shell).
|
||||
|
||||
$ pyenv global 2.7.6
|
||||
|
||||
The special version name `system` tells pyenv to use the system Python
|
||||
(detected by searching your `$PATH`).
|
||||
|
||||
When run without a version number, `pyenv global` reports the
|
||||
currently configured global version.
|
||||
|
||||
|
||||
### `pyenv global` (advanced)
|
||||
|
||||
You can specify multiple versions as global Python at once.
|
||||
|
||||
Let's say if you have two versions of 2.7.6 and 3.3.3. If you prefer 2.7.6 over 3.3.3,
|
||||
|
||||
$ pyenv global 2.7.6 3.3.3
|
||||
$ pyenv versions
|
||||
system
|
||||
* 2.7.6 (set by /Users/yyuu/.pyenv/version)
|
||||
* 3.3.3 (set by /Users/yyuu/.pyenv/version)
|
||||
$ python --version
|
||||
Python 2.7.6
|
||||
$ python2.7 --version
|
||||
Python 2.7.6
|
||||
$ python3.3 --version
|
||||
Python 3.3.3
|
||||
|
||||
or, if you prefer 3.3.3 over 2.7.6,
|
||||
|
||||
$ pyenv global 3.3.3 2.7.6
|
||||
$ pyenv versions
|
||||
system
|
||||
* 2.7.6 (set by /Users/yyuu/.pyenv/version)
|
||||
* 3.3.3 (set by /Users/yyuu/.pyenv/version)
|
||||
venv27
|
||||
$ python --version
|
||||
Python 3.3.3
|
||||
$ python2.7 --version
|
||||
Python 2.7.6
|
||||
$ python3.3 --version
|
||||
Python 3.3.3
|
||||
|
||||
|
||||
## `pyenv shell`
|
||||
|
||||
Sets a shell-specific Python version by setting the `PYENV_VERSION`
|
||||
environment variable in your shell. This version overrides
|
||||
application-specific versions and the global version.
|
||||
|
||||
$ pyenv shell pypy-2.2.1
|
||||
|
||||
When run without a version number, `pyenv shell` reports the current
|
||||
value of `PYENV_VERSION`. You can also unset the shell version:
|
||||
|
||||
$ pyenv shell --unset
|
||||
|
||||
Note that you'll need pyenv's shell integration enabled (step 3 of
|
||||
the installation instructions) in order to use this command. If you
|
||||
prefer not to use shell integration, you may simply set the
|
||||
`PYENV_VERSION` variable yourself:
|
||||
|
||||
$ export PYENV_VERSION=pypy-2.2.1
|
||||
|
||||
|
||||
### `pyenv shell` (advanced)
|
||||
|
||||
You can specify multiple versions via `PYENV_VERSION` at once.
|
||||
|
||||
Let's say if you have two versions of 2.7.6 and 3.3.3. If you prefer 2.7.6 over 3.3.3,
|
||||
|
||||
$ pyenv shell 2.7.6 3.3.3
|
||||
$ pyenv versions
|
||||
system
|
||||
* 2.7.6 (set by PYENV_VERSION environment variable)
|
||||
* 3.3.3 (set by PYENV_VERSION environment variable)
|
||||
$ python --version
|
||||
Python 2.7.6
|
||||
$ python2.7 --version
|
||||
Python 2.7.6
|
||||
$ python3.3 --version
|
||||
Python 3.3.3
|
||||
|
||||
or, if you prefer 3.3.3 over 2.7.6,
|
||||
|
||||
$ pyenv shell 3.3.3 2.7.6
|
||||
$ pyenv versions
|
||||
system
|
||||
* 2.7.6 (set by PYENV_VERSION environment variable)
|
||||
* 3.3.3 (set by PYENV_VERSION environment variable)
|
||||
venv27
|
||||
$ python --version
|
||||
Python 3.3.3
|
||||
$ python2.7 --version
|
||||
Python 2.7.6
|
||||
$ python3.3 --version
|
||||
Python 3.3.3
|
||||
|
||||
|
||||
## `pyenv install`
|
||||
|
||||
Install a Python version (using [`python-build`](https://github.com/pyenv/pyenv/tree/master/plugins/python-build)).
|
||||
|
||||
Usage: pyenv install [-f] [-kvp] <version>[:<alias>]
|
||||
pyenv install [-f] [-kvp] <definition-file>[:<alias>]
|
||||
pyenv install -l|--list
|
||||
|
||||
-l/--list List all available versions
|
||||
-f/--force Install even if the version appears to be installed already
|
||||
-s/--skip-existing Skip the installation if the version appears to be installed already
|
||||
|
||||
python-build options:
|
||||
|
||||
-k/--keep Keep source tree in $PYENV_BUILD_ROOT after installation
|
||||
(defaults to $PYENV_ROOT/sources)
|
||||
-v/--verbose Verbose mode: print compilation status to stdout
|
||||
-p/--patch Apply a patch from stdin before building
|
||||
-g/--debug Build a debug version
|
||||
|
||||
To list the all available versions of Python, including Anaconda, Jython, pypy, and stackless, use:
|
||||
|
||||
$ pyenv install --list
|
||||
|
||||
Then install the desired versions:
|
||||
|
||||
$ pyenv install 2.7.6
|
||||
$ pyenv install 2.6.8
|
||||
$ pyenv versions
|
||||
system
|
||||
2.6.8
|
||||
* 2.7.6 (set by /home/yyuu/.pyenv/version)
|
||||
|
||||
You can also install the latest version of Python in a specific version line by supplying a prefix instead of a complete name:
|
||||
|
||||
$ pyenv install 3.10
|
||||
$ pyenv install 3
|
||||
|
||||
See the [`pyenv latest` documentation](#pyenv-latest) for details on prefix resolution.
|
||||
|
||||
An older option is to use the `:latest` syntax. For example, to install the latest patch version for Python 3.8 you could do:
|
||||
|
||||
pyenv install 3.8:latest
|
||||
|
||||
|
||||
## `pyenv uninstall`
|
||||
|
||||
Uninstall Python versions.
|
||||
|
||||
Usage: pyenv uninstall [-f|--force] <version> ...
|
||||
|
||||
-f Attempt to remove the specified version without prompting
|
||||
for confirmation. If the version does not exist, do not
|
||||
display an error message.
|
||||
|
||||
|
||||
## `pyenv rehash`
|
||||
|
||||
Installs shims for all Python binaries known to pyenv (i.e.,
|
||||
`~/.pyenv/versions/*/bin/*`). Run this command after you install a new
|
||||
version of Python, or install a package that provides binaries.
|
||||
|
||||
$ pyenv rehash
|
||||
|
||||
|
||||
## `pyenv version`
|
||||
|
||||
Displays the currently active Python version, along with information on
|
||||
how it was set.
|
||||
|
||||
Usage: pyenv version [--bare]
|
||||
|
||||
--bare show just the version name. An alias to `pyenv version-name'
|
||||
|
||||
|
||||
$ pyenv version
|
||||
2.7.6 (set by /home/yyuu/.pyenv/version)
|
||||
$ pyenv version --bare
|
||||
2.7.6
|
||||
|
||||
|
||||
## `pyenv versions`
|
||||
|
||||
Lists all Python versions known to pyenv, and shows an asterisk next to
|
||||
the currently active version.
|
||||
|
||||
$ pyenv versions
|
||||
2.5.6
|
||||
2.6.8
|
||||
* 2.7.6 (set by /home/yyuu/.pyenv/version)
|
||||
3.3.3
|
||||
jython-2.5.3
|
||||
pypy-2.2.1
|
||||
|
||||
|
||||
## `pyenv which`
|
||||
|
||||
Displays the full path to the executable that pyenv will invoke when
|
||||
you run the given command.
|
||||
|
||||
$ pyenv which python3.3
|
||||
/home/yyuu/.pyenv/versions/3.3.3/bin/python3.3
|
||||
|
||||
Use --nosystem argument in case when you don't need to search command in the
|
||||
system environment.
|
||||
|
||||
## `pyenv whence`
|
||||
|
||||
Lists all Python versions with the given command installed.
|
||||
|
||||
$ pyenv whence 2to3
|
||||
2.6.8
|
||||
2.7.6
|
||||
3.3.3
|
||||
|
||||
## `pyenv exec`
|
||||
|
||||
Usage: pyenv exec <command> [arg1 arg2...]
|
||||
|
||||
Runs an executable by first preparing PATH so that the selected Python
|
||||
version's `bin` directory is at the front.
|
||||
|
||||
For example, if the currently selected Python version is 3.9.7:
|
||||
|
||||
pyenv exec pip install -r requirements.txt
|
||||
|
||||
is equivalent to:
|
||||
|
||||
PATH="$PYENV_ROOT/versions/3.9.7/bin:$PATH" pip install -r requirements.txt
|
||||
|
||||
## `pyenv root`
|
||||
|
||||
Displays the root directory where versions and shims are kept.
|
||||
|
||||
$ pyenv root
|
||||
/home/user/.pyenv
|
||||
|
||||
## `pyenv prefix`
|
||||
|
||||
Displays the directories where the given Python versions are installed,
|
||||
separated by colons. If no version is given, `pyenv prefix` displays the
|
||||
locations of the currently selected versions.
|
||||
|
||||
$ pyenv prefix 3.9.7
|
||||
/home/user/.pyenv/versions/3.9.7
|
||||
|
||||
## `pyenv latest`
|
||||
|
||||
Displays the latest installed or known version with the given prefix
|
||||
|
||||
Usage: pyenv latest [-k|--known] <prefix>
|
||||
|
||||
-k/--known Select from all known versions instead of installed
|
||||
|
||||
Only full prefixes are searched: in the actual name, the given prefix must be followed by a dot or a dash.
|
||||
|
||||
Prereleases and versions with specific suffixes (e.g. `-src`) are ignored.
|
||||
|
||||
## `pyenv hooks`
|
||||
|
||||
Lists installed hook scripts for a given pyenv command.
|
||||
|
||||
Usage: pyenv hooks <command>
|
||||
|
||||
## `pyenv shims`
|
||||
|
||||
List existing pyenv shims.
|
||||
|
||||
Usage: pyenv shims [--short]
|
||||
|
||||
$ pyenv shims
|
||||
/home/user/.pyenv/shims/2to3
|
||||
/home/user/.pyenv/shims/2to3-3.9
|
||||
/home/user/.pyenv/shims/idle
|
||||
/home/user/.pyenv/shims/idle3
|
||||
/home/user/.pyenv/shims/idle3.9
|
||||
/home/user/.pyenv/shims/pip
|
||||
/home/user/.pyenv/shims/pip3
|
||||
/home/user/.pyenv/shims/pip3.9
|
||||
/home/user/.pyenv/shims/pydoc
|
||||
/home/user/.pyenv/shims/pydoc3
|
||||
/home/user/.pyenv/shims/pydoc3.9
|
||||
/home/user/.pyenv/shims/python
|
||||
/home/user/.pyenv/shims/python3
|
||||
/home/user/.pyenv/shims/python3.9
|
||||
/home/user/.pyenv/shims/python3.9-config
|
||||
/home/user/.pyenv/shims/python3.9-gdb.py
|
||||
/home/user/.pyenv/shims/python3-config
|
||||
/home/user/.pyenv/shims/python-config
|
||||
|
||||
## `pyenv init`
|
||||
|
||||
Configure the shell environment for pyenv
|
||||
|
||||
Usage: eval "$(pyenv init [-|--path] [--no-push-path] [--no-rehash] [<shell>])"
|
||||
pyenv init --install [<shell>]
|
||||
pyenv init --detect-shell [<shell>]
|
||||
|
||||
- Initialize shims directory, print PYENV_SHELL variable, completions path
|
||||
and shell function
|
||||
--path Print shims path
|
||||
--install Configure detected shell startup files
|
||||
--no-push-path Do not push shim to the start of PATH if they're already there
|
||||
--detect-shell Print shell startup files detected for the current shell
|
||||
--no-rehash Add no rehash command to output
|
||||
|
||||
## `pyenv completions`
|
||||
|
||||
Lists available completions for a given pyenv command.
|
||||
|
||||
Usage: pyenv completions <command> [arg1 arg2...]
|
||||
103
CONTRIBUTING.md
103
CONTRIBUTING.md
|
|
@ -1,103 +0,0 @@
|
|||
General guidance
|
||||
================
|
||||
|
||||
* The usual principles of respecting existing conventions and making sure that your changes
|
||||
are in line with the overall product design apply when contributing code to Pyenv.
|
||||
|
||||
* We are limited to Bash 3.2 features
|
||||
|
||||
That's because that's the version shipped with MacOS.
|
||||
(They didn't upgrade past it and switched to Zsh because later versions
|
||||
are covered by GPLv3 which has additional restrictions unacceptable for Apple.)
|
||||
|
||||
You can still add performance optimizations etc that take advantage of newer Bash features
|
||||
as long as there is a fallback execution route for Bash 3.
|
||||
|
||||
Formatting PRs
|
||||
==============
|
||||
|
||||
We strive to keep commit history one-concern-per-commit to keep it meaningful and easy to follow.
|
||||
If a pull request (PR) addresses a single concern (the typical case), we usually squash commits
|
||||
from it together when merging so its commit history doesn't matter.
|
||||
If however a PR addresses multiple separate concerns, each of them should be presented as a separate commit.
|
||||
Adding multiple new Python releases of the same flavor is okay with either a single or multiple commits.
|
||||
|
||||
|
||||
Authoring installation scripts
|
||||
==============================
|
||||
|
||||
Adding new Python release support
|
||||
---------------------------------
|
||||
|
||||
The easiest way to add support for a new Python release is to copy the script from the previous one
|
||||
and adjust it as necessary. In many cases, just changing version numbers, URLs and hashes is enough.
|
||||
Do pay attention to other "magic numbers" that may be present in a script --
|
||||
e.g. the set of architectures and OS versions supported by a release -- since those change from time to time, too.
|
||||
|
||||
Make sure to also copy any patches for the previous release that still apply to the new one.
|
||||
Typically, a patch no longer applies if it addresses a problem that's already fixed in the new release.
|
||||
|
||||
For prereleases, we only create an entry for the latest prerelease in a specific version line.
|
||||
When submitting a newer prerelease, replace the older one.
|
||||
|
||||
|
||||
Adding version-specific fixes/patches
|
||||
-------------------------------------
|
||||
|
||||
We accept fixes to issues in specific Python releases that prevent users from using them with Pyenv.
|
||||
|
||||
In the default configuration for a Python release, we strive to provide as close to vanilla experience as practical,
|
||||
to maintain [the principle of the least surprise](https://en.wikipedia.org/wiki/Principle_of_least_astonishment).
|
||||
As such, any such fixes:
|
||||
|
||||
* Must not break or degrade (e.g. disable features) the build in any of the environments that the release officially supports
|
||||
* Must not introduce incompatibilities with the vanilla release (including binary incompatibilities)
|
||||
* Should not patch things unnecessarily, to minimize the risk of the aforementioned undesirable side effects.
|
||||
* E.g. if the fix is for a specific environment, its logic ought to only fire in this specific environment and not touch execution paths for other environments.
|
||||
* As such, it's advisable to briefly explain in the PR what each added patch does and why it is necessary to fix the declared problem
|
||||
|
||||
Generally, version-specific fixes belong in the scripts for the affected releases and/or patches for them -- this guarantees that their effect is limited to only those releases.
|
||||
|
||||
<h3>Backporting upstream patches</h3>
|
||||
|
||||
Usually, this is the easiest way to backport a fix for a problem that is fixed in a newer release.
|
||||
|
||||
* Clone Python, check out the tag for the appropriate release and create a branch
|
||||
* Apply existing patches if there are any (with either `patch` or `git am`) and commit
|
||||
* Cherry-pick the upstream commit that fixes the problem in a newer release
|
||||
* Commit and `git format-patch`
|
||||
* Commit the generated patch file into Pyenv, test your changes and submit a PR
|
||||
|
||||
|
||||
Deprecation policy
|
||||
------------------
|
||||
|
||||
We do not provide official support for EOL releases and environments or otherwise provide any kind of extended support for old Python releases.
|
||||
|
||||
We do however accept fixes from interested parties that would allow running older, including EOL, releases in environments that they do not officially support.
|
||||
In addition to the above requirements for release-specific fixes,
|
||||
|
||||
* Such a fix must not add maintenance burden (e.g. add new logic to `python-build` that has to be kept there indefinitely)
|
||||
* Unless the added logic is useful for both EOL and non-EOL releases. In this case, it will be considered as being primarily an improvement for non-EOL releases.
|
||||
* Support is provided on a "best effort" basis: we do not actively maintain these fixes but won't actively break them, either, and will accept any corrections.
|
||||
Since old releases never change, it's pretty safe to assume that the fixes will continue to work until a later version
|
||||
of an environment introduces further incompatible changes.
|
||||
|
||||
|
||||
Advanced changes / adding new Python flavor support
|
||||
---------------------------------------------------
|
||||
|
||||
An installation script is sourced from `python-build`. All installation scripts are based on the same logic:
|
||||
|
||||
1. Select the source to download and other variable parameters as needed.
|
||||
|
||||
This includes showing an error if the user's environment (OS, architecture) is not supported by the release.
|
||||
Binary releases that only officially support specific distro(s) typically show a warning in other distros instead.
|
||||
|
||||
2. Run one of the `install_*` shell functions
|
||||
|
||||
`install_*` shell functions defined in `python-build` install Python from different kinds of sources -- compressed package (binary or source), upstream installation script, VCS checkout. Pick one that's the most appropriate for your packaging.
|
||||
|
||||
Each of them accepts a couple of function-specific arguments which are followed by arguments that constitute the build sequence. Each `<argument>` in the build sequence corresponds to the `install_*_<argument>` function in `python-build`. Check what's available and add any functions with logic specific to your flavor if needed.
|
||||
|
||||
We strive to keep out of `python-build` parts of build logic that are release-specific and/or tend to change abruptly between releases -- e.g. sets of supported architectures and other software's versions. This results in logic duplication between installation scripts -- but since old releases never change once released, this doesn't really add to the maintenance burden. As a rule of thumb, `python-build` can host parts of logic that are expected to stay the same for an indefinite amount of time -- for an entire Python flavor or release line.
|
||||
1
LICENSE
1
LICENSE
|
|
@ -1,4 +1,3 @@
|
|||
Copyright (c) 2013 Yamashita, Yuu
|
||||
Copyright (c) 2013 Sam Stephenson
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
|
|
|
|||
|
|
@ -1,25 +0,0 @@
|
|||
Creating a release
|
||||
==================
|
||||
|
||||
The release of the new version of Pyenv is done via GitHub Releases.
|
||||
|
||||
Release checklist:
|
||||
* Start [drafting a new release on GitHub](https://github.com/pyenv/pyenv/releases) to generate a summary of changes.
|
||||
Type the would-be tag name in the "Choose a tag" field and press "Generate release notes"
|
||||
* The summary may need editing. E.g. rephrase entries, delete/merge entries that are too minor or irrelevant to the users (e.g. typo fixes, CI)
|
||||
* Add a sponsors section to the release notes by running:
|
||||
```bash
|
||||
.github/scripts/generate_release_notes_sponsors.py
|
||||
```
|
||||
Paste the output at the end of the release notes.
|
||||
* This lists new GitHub Sponsors and OpenCollective backers since the last release or within the last month, whichever is longer.
|
||||
* The GitHub Sponsors query requires the `gh` CLI with the `read:user` scope.
|
||||
* If OpenCollective is unavailable, pass `--skip-opencollective` and add those backers manually.
|
||||
* Update `CHANGELOG.md` with the new version number and the edited summary (only the changes section)
|
||||
* Push the version number in `libexec/pyenv---version` and `plugins/python-build/bin/python-build`
|
||||
* Minor version is pushed if there are significant functional changes (not e.g. bugfixes/formula adaptations/supporting niche use cases).
|
||||
* Major version is pushed if there are breaking changes
|
||||
* Commit the changes locally into `master`
|
||||
* Create a new tag locally with the same name as specified in the new release window
|
||||
* Push the changes including the tag
|
||||
* In the still open new release window, press "Publish release". The now-existing tag will be used.
|
||||
172
Makefile
172
Makefile
|
|
@ -1,170 +1,4 @@
|
|||
TEST_BATS_VERSION = v1.10.0
|
||||
TEST_BASH_VERSIONS = 3.2.57 4.1.17
|
||||
release_version := $(shell GIT_CEILING_DIRECTORIES=$(PWD) bin/rbenv --version | cut -d' ' -f2)
|
||||
|
||||
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_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_TARGETS = $(foreach bash,$(TEST_BASH_VERSIONS),$(addsuffix -$(bash),$(TEST_BATS_IMAGE_PREFIX)) $(addsuffix -gnu-$(bash),$(TEST_BATS_IMAGE_PREFIX)))
|
||||
|
||||
.PHONY: test-docker
|
||||
test-docker: $(TEST_UNIT_DOCKER_PREFIX) $(TEST_PYTHON_BUILD_DOCKER_PREFIX) $(TEST_BINARY_DOCKER_PREFIX) $(TEST_LINK_DOCKER_PREFIX)
|
||||
|
||||
.PHONY: $(TEST_UNIT_DOCKER_PREFIX)
|
||||
$(TEST_UNIT_DOCKER_PREFIX): $(TEST_UNIT_DOCKER_TARGETS)
|
||||
|
||||
# Run each unit test under bats docker
|
||||
.PHONY: $(TEST_UNIT_DOCKER_TARGETS)
|
||||
$(TEST_UNIT_DOCKER_TARGETS): DOCKER_IMAGE = $(TEST_BATS_IMAGE_PREFIX)
|
||||
$(TEST_UNIT_DOCKER_TARGETS): GNU = $(if $(findstring -gnu-,$@),True,False)
|
||||
$(TEST_UNIT_DOCKER_TARGETS): BASH = $(filter $(TEST_BASH_VERSIONS),$(subst -, ,$@))
|
||||
$(TEST_UNIT_DOCKER_TARGETS): DOCKER_TAG = bash-$(BASH)-gnu-$(GNU)
|
||||
$(TEST_UNIT_DOCKER_TARGETS): INTERACTIVE = $(if $(findstring true,$(CI)),,-ti)
|
||||
$(TEST_UNIT_DOCKER_TARGETS): $(TEST_UNIT_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))" \
|
||||
$${BATS_TEST_FILTER:+-e BATS_TEST_FILTER="$${BATS_TEST_FILTER}"} \
|
||||
$${BATS_FILE_FILTER:+-e BATS_FILE_FILTER="$${BATS_FILE_FILTER}"} \
|
||||
$${CI+-e CI="$${CI}"} \
|
||||
$(INTERACTIVE) \
|
||||
$(DOCKER_IMAGE):$(DOCKER_TAG) \
|
||||
test/run
|
||||
|
||||
.PHONY: $(TEST_PYTHON_BUILD_DOCKER_PREFIX)
|
||||
$(TEST_PYTHON_BUILD_DOCKER_PREFIX): $(TEST_PYTHON_BUILD_DOCKER_TARGETS)
|
||||
|
||||
# Run each plugin test under bats docker
|
||||
.PHONY: $(TEST_PYTHON_BUILD_DOCKER_TARGETS)
|
||||
$(TEST_PYTHON_BUILD_DOCKER_TARGETS): DOCKER_IMAGE = $(TEST_BATS_IMAGE_PREFIX)
|
||||
$(TEST_PYTHON_BUILD_DOCKER_TARGETS): GNU = $(if $(findstring -gnu-,$@),True,False)
|
||||
$(TEST_PYTHON_BUILD_DOCKER_TARGETS): BASH = $(filter $(TEST_BASH_VERSIONS),$(subst -, ,$@))
|
||||
$(TEST_PYTHON_BUILD_DOCKER_TARGETS): DOCKER_TAG = bash-$(BASH)-gnu-$(GNU)
|
||||
$(TEST_PYTHON_BUILD_DOCKER_TARGETS): INTERACTIVE = $(if $(findstring true,$(CI)),,-ti)
|
||||
$(TEST_PYTHON_BUILD_DOCKER_TARGETS): $(TEST_PYTHON_BUILD_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/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
|
||||
.PHONY: $(TEST_BATS_IMAGE_PREFIX)
|
||||
$(TEST_BATS_IMAGE_PREFIX): $(TEST_BATS_IMAGE_TARGETS)
|
||||
|
||||
# Build each image needed for bats under docker
|
||||
.PHONY: $(TEST_BATS_IMAGE_TARGETS)
|
||||
$(TEST_BATS_IMAGE_TARGETS): DOCKER_IMAGE = $(TEST_BATS_IMAGE_PREFIX)
|
||||
$(TEST_BATS_IMAGE_TARGETS): GNU = $(if $(findstring -gnu-,$@),True,False)
|
||||
$(TEST_BATS_IMAGE_TARGETS): BASH = $(filter $(TEST_BASH_VERSIONS),$(subst -, ,$@))
|
||||
$(TEST_BATS_IMAGE_TARGETS): DOCKER_TAG = bash-$(BASH)-gnu-$(GNU)
|
||||
$(TEST_BATS_IMAGE_TARGETS):
|
||||
if [ -z "$$(docker images -q '$(DOCKER_IMAGE):$(DOCKER_TAG)')" ]]; then \
|
||||
docker build \
|
||||
--quiet \
|
||||
-f "$(PWD)/test/Dockerfile" \
|
||||
--build-arg GNU="$(GNU)" \
|
||||
--build-arg BASH="$(BASH)" \
|
||||
--build-arg BATS_VERSION="$(TEST_BATS_VERSION)" \
|
||||
-t $(DOCKER_IMAGE):$(DOCKER_TAG) \
|
||||
./ ; \
|
||||
fi
|
||||
|
||||
.PHONY: test test-unit test-python-build test-binary test-link
|
||||
|
||||
# Do not pass in user flags to build tests.
|
||||
unexport PYTHON_CFLAGS
|
||||
unexport PYTHON_CONFIGURE_OPTS
|
||||
|
||||
test: test-unit test-python-build test-binary test-link
|
||||
|
||||
test-unit: bats
|
||||
PATH="./bats/bin:$$PATH" test/run
|
||||
|
||||
test-python-build: bats
|
||||
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}
|
||||
|
||||
test-binary: bats
|
||||
cd plugins/pyenv-binary && $(PWD)/bats/bin/bats $${CI:+-F "$(PWD)/test/libexec/bats-format-tap-suite"} \
|
||||
$${BATS_TEST_FILTER:+--filter "$${BATS_TEST_FILTER}"} test/$${BATS_FILE_FILTER}
|
||||
|
||||
test-link: bats
|
||||
cd plugins/pyenv-link && $(PWD)/bats/bin/bats $${CI:+-F "$(PWD)/test/libexec/bats-format-tap-suite"} \
|
||||
$${BATS_TEST_FILTER:+--filter "$${BATS_TEST_FILTER}"} test/$${BATS_FILE_FILTER}
|
||||
|
||||
.SECONDARY: bats-$(TEST_BATS_VERSION)
|
||||
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
|
||||
bats: bats-$(TEST_BATS_VERSION)
|
||||
if [ \( ! -L bats \) -o \( "x$$(readlink bats)" != "xbats-$(TEST_BATS_VERSION)" \) ]; then \
|
||||
rm -rf bats; ln -s bats-$(TEST_BATS_VERSION) bats; \
|
||||
fi
|
||||
share/man/man1/rbenv.1: share/man/man1/rbenv.1.adoc
|
||||
asciidoctor -b manpage -a version=$(release_version:v%=%) $<
|
||||
|
|
|
|||
13
completions/_rbenv
Normal file
13
completions/_rbenv
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
#compdef rbenv
|
||||
|
||||
_rbenv() {
|
||||
local completions
|
||||
|
||||
if [ "${#words}" -eq 2 ]; then
|
||||
completions=(${(f)"$(rbenv help --complete-commands "${words[2]}")"})
|
||||
_describe 'rbenv commands' completions
|
||||
else
|
||||
completions="$(rbenv completions ${words[2,-2]})"
|
||||
compadd - "${(ps:\n:)completions}"
|
||||
fi
|
||||
}
|
||||
|
|
@ -1,16 +0,0 @@
|
|||
_pyenv() {
|
||||
COMPREPLY=()
|
||||
local word="${COMP_WORDS[COMP_CWORD]}"
|
||||
|
||||
if [ "$COMP_CWORD" -eq 1 ]; then
|
||||
COMPREPLY=( $(compgen -W "$(pyenv commands)" -- "$word") )
|
||||
else
|
||||
local words=("${COMP_WORDS[@]}")
|
||||
unset words[0]
|
||||
unset words[$COMP_CWORD]
|
||||
local completions=$(pyenv completions "${words[@]}")
|
||||
COMPREPLY=( $(compgen -W "$completions" -- "$word") )
|
||||
fi
|
||||
}
|
||||
|
||||
complete -F _pyenv pyenv
|
||||
|
|
@ -1,23 +0,0 @@
|
|||
function __fish_pyenv_needs_command
|
||||
set cmd (commandline -opc)
|
||||
if [ (count $cmd) -eq 1 -a $cmd[1] = 'pyenv' ]
|
||||
return 0
|
||||
end
|
||||
return 1
|
||||
end
|
||||
|
||||
function __fish_pyenv_using_command
|
||||
set cmd (commandline -opc)
|
||||
if [ (count $cmd) -gt 1 ]
|
||||
if [ $argv[1] = $cmd[2] ]
|
||||
return 0
|
||||
end
|
||||
end
|
||||
return 1
|
||||
end
|
||||
|
||||
complete -f -c pyenv -n '__fish_pyenv_needs_command' -a '(pyenv commands)'
|
||||
for cmd in (pyenv commands)
|
||||
complete -f -c pyenv -n "__fish_pyenv_using_command $cmd" -a \
|
||||
"(pyenv completions (commandline -opc)[2..-1])"
|
||||
end
|
||||
|
|
@ -1,17 +0,0 @@
|
|||
$scriptblock = {
|
||||
param($wordToComplete, $commandAst, $cursorPosition)
|
||||
$words = $commandAst.ToString()
|
||||
if ( $wordToComplete ) {
|
||||
$matches = (($words[0..$cursorPosition] -join '') | Select-String -Pattern "\s+" -AllMatches).Matches
|
||||
if ( $matches ) {
|
||||
$cursorPosition = $matches[-1].Index - 1
|
||||
}
|
||||
}
|
||||
$words = $words[0..$cursorPosition] -join '' -split "\s+"
|
||||
if ( $words.Count -ge 2 ) {
|
||||
pyenv completions $words[1] | where { $_ -match $wordToComplete }
|
||||
} else {
|
||||
pyenv commands | where { $_ -match $wordToComplete }
|
||||
}
|
||||
}
|
||||
Register-ArgumentCompleter -Native -CommandName pyenv -ScriptBlock $scriptblock
|
||||
|
|
@ -1,18 +0,0 @@
|
|||
if [[ ! -o interactive ]]; then
|
||||
return
|
||||
fi
|
||||
|
||||
compctl -K _pyenv pyenv
|
||||
|
||||
_pyenv() {
|
||||
local words completions
|
||||
read -cA words
|
||||
|
||||
if [ "${#words}" -eq 2 ]; then
|
||||
completions="$(pyenv commands)"
|
||||
else
|
||||
completions="$(pyenv completions ${words[2,-2]})"
|
||||
fi
|
||||
|
||||
reply=(${(ps:\n:)completions})
|
||||
}
|
||||
16
completions/rbenv.bash
Normal file
16
completions/rbenv.bash
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
_rbenv() {
|
||||
COMPREPLY=()
|
||||
local word="${COMP_WORDS[COMP_CWORD]}"
|
||||
|
||||
if [ "$COMP_CWORD" -eq 1 ]; then
|
||||
COMPREPLY=( $(compgen -W "$(rbenv commands)" -- "$word") )
|
||||
else
|
||||
local words=("${COMP_WORDS[@]}")
|
||||
unset "words[0]"
|
||||
unset "words[$COMP_CWORD]"
|
||||
local completions=$(rbenv completions "${words[@]}")
|
||||
COMPREPLY=( $(compgen -W "$completions" -- "$word") )
|
||||
fi
|
||||
}
|
||||
|
||||
complete -F _rbenv rbenv
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 531 KiB |
145
libexec/pyenv
145
libexec/pyenv
|
|
@ -1,145 +0,0 @@
|
|||
#!/usr/bin/env bash
|
||||
set -e
|
||||
|
||||
if [ "$1" = "--debug" ]; then
|
||||
export PYENV_DEBUG=1
|
||||
shift
|
||||
fi
|
||||
|
||||
if [ -n "$PYENV_DEBUG" ]; then
|
||||
# https://wiki-dev.bash-hackers.org/scripting/debuggingtips#making_xtrace_more_useful
|
||||
export PS4='+(${BASH_SOURCE}:${LINENO}): ${FUNCNAME[0]:+${FUNCNAME[0]}(): }'
|
||||
set -x
|
||||
fi
|
||||
|
||||
abort() {
|
||||
{ if [ "$#" -eq 0 ]; then cat -
|
||||
else echo "pyenv: $*"
|
||||
fi
|
||||
} >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
if enable -f "${BASH_SOURCE%/*}"/../libexec/pyenv-realpath.dylib realpath 2>/dev/null; then
|
||||
abs_dirname() {
|
||||
local path
|
||||
path="$(realpath "$1")"
|
||||
echo "${path%/*}"
|
||||
}
|
||||
else
|
||||
[ -z "$PYENV_NATIVE_EXT" ] || abort "failed to load \`realpath' builtin"
|
||||
|
||||
READLINK=$(type -P readlink)
|
||||
[ -n "$READLINK" ] || abort "cannot find readlink - are you missing GNU coreutils?"
|
||||
|
||||
resolve_link() {
|
||||
$READLINK "$1"
|
||||
}
|
||||
|
||||
abs_dirname() {
|
||||
local path="$1"
|
||||
|
||||
# Use a subshell to avoid changing the current path
|
||||
(
|
||||
while [ -n "$path" ]; do
|
||||
cd_path="${path%/*}"
|
||||
if [[ "$cd_path" != "$path" ]]; then
|
||||
cd "$cd_path"
|
||||
fi
|
||||
name="${path##*/}"
|
||||
path="$(resolve_link "$name" || true)"
|
||||
done
|
||||
|
||||
echo "$PWD"
|
||||
)
|
||||
}
|
||||
fi
|
||||
|
||||
if [ -z "${PYENV_ROOT}" ]; then
|
||||
PYENV_ROOT="${HOME}/.pyenv"
|
||||
else
|
||||
PYENV_ROOT="${PYENV_ROOT%/}"
|
||||
fi
|
||||
export PYENV_ROOT
|
||||
|
||||
if [ -z "${PYENV_DIR}" ]; then
|
||||
PYENV_DIR="$PWD"
|
||||
fi
|
||||
|
||||
if [ ! -d "$PYENV_DIR" ] || [ ! -e "$PYENV_DIR" ]; then
|
||||
abort "cannot change working directory to \`$PYENV_DIR'"
|
||||
fi
|
||||
|
||||
PYENV_DIR=$(cd "$PYENV_DIR" && echo "$PWD")
|
||||
export PYENV_DIR
|
||||
|
||||
|
||||
shopt -s nullglob
|
||||
|
||||
_PYENV_INSTALL_PREFIX="$(abs_dirname "$0")"
|
||||
_PYENV_INSTALL_PREFIX="${_PYENV_INSTALL_PREFIX%/*}"
|
||||
|
||||
export _PYENV_INSTALL_PREFIX
|
||||
|
||||
for plugin_bin in "${_PYENV_INSTALL_PREFIX}"/plugins/*/bin; do
|
||||
PATH="${plugin_bin}:${PATH}"
|
||||
done
|
||||
# PYENV_ROOT can be set to anything, so it may happen to be equal to the base path above,
|
||||
# resulting in duplicate PATH entries
|
||||
if [ "${_PYENV_INSTALL_PREFIX}" != "$PYENV_ROOT" ]; then
|
||||
for plugin_bin in "${PYENV_ROOT}"/plugins/*/bin; do
|
||||
PATH="${plugin_bin}:${PATH}"
|
||||
done
|
||||
fi
|
||||
export PATH="${_PYENV_INSTALL_PREFIX}/libexec:${PATH}"
|
||||
|
||||
PYENV_HOOK_PATH="${PYENV_HOOK_PATH}:${PYENV_ROOT}/pyenv.d"
|
||||
if [ "${_PYENV_INSTALL_PREFIX}" != "$PYENV_ROOT" ]; then
|
||||
# Add pyenv's own `pyenv.d` unless pyenv was cloned to PYENV_ROOT
|
||||
PYENV_HOOK_PATH="${PYENV_HOOK_PATH}:${_PYENV_INSTALL_PREFIX}/pyenv.d"
|
||||
fi
|
||||
PYENV_HOOK_PATH="${PYENV_HOOK_PATH}:/usr/etc/pyenv.d:/usr/local/etc/pyenv.d:/etc/pyenv.d:/usr/lib/pyenv/hooks"
|
||||
for plugin_hook in "${PYENV_ROOT}/plugins/"*/etc/pyenv.d; do
|
||||
PYENV_HOOK_PATH="${PYENV_HOOK_PATH}:${plugin_hook}"
|
||||
done
|
||||
PYENV_HOOK_PATH="${PYENV_HOOK_PATH#:}"
|
||||
export PYENV_HOOK_PATH
|
||||
|
||||
shopt -u nullglob
|
||||
|
||||
|
||||
command="$1"
|
||||
case "$command" in
|
||||
"" )
|
||||
{ pyenv---version
|
||||
pyenv-help
|
||||
} | abort
|
||||
;;
|
||||
-v | --version )
|
||||
exec pyenv---version
|
||||
;;
|
||||
-h | --help )
|
||||
exec pyenv-help
|
||||
;;
|
||||
* )
|
||||
command_path="$(command -v "pyenv-$command" || true)"
|
||||
if [ -z "$command_path" ]; then
|
||||
if [ "$command" == "shell" ]; then
|
||||
abort "shell integration not enabled. Run \`pyenv init' for instructions."
|
||||
else
|
||||
abort "no such command \`$command'"
|
||||
fi
|
||||
fi
|
||||
|
||||
shift 1
|
||||
if [ "$1" = --help ]; then
|
||||
if [[ "$command" == "sh-"* ]]; then
|
||||
echo "pyenv help \"$command\""
|
||||
else
|
||||
exec pyenv-help "$command"
|
||||
fi
|
||||
else
|
||||
exec "$command_path" "$@"
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
|
|
@ -1,48 +0,0 @@
|
|||
#!/usr/bin/env bash
|
||||
# Summary: List all available pyenv commands
|
||||
# Usage: pyenv commands [--sh|--no-sh]
|
||||
|
||||
set -e
|
||||
[[ -n $PYENV_DEBUG ]] && set -x
|
||||
|
||||
# Provide pyenv completions
|
||||
if [[ $1 = "--complete" ]]; then
|
||||
echo --sh
|
||||
echo --no-sh
|
||||
exit
|
||||
fi
|
||||
|
||||
if [[ $1 = "--sh" ]]; then
|
||||
sh=1
|
||||
shift
|
||||
elif [[ $1 = "--no-sh" ]]; then
|
||||
nosh=1
|
||||
shift
|
||||
fi
|
||||
|
||||
IFS=: paths=($PATH)
|
||||
|
||||
shopt -s nullglob
|
||||
|
||||
{
|
||||
if [[ -n $sh ]]; then
|
||||
for path in "${paths[@]}"; do
|
||||
for command in "${path}"/pyenv-sh-*; do
|
||||
echo "${command##*/pyenv-sh-}"
|
||||
done
|
||||
done
|
||||
else
|
||||
for path in "${paths[@]}"; do
|
||||
for command in "${path}"/pyenv-*; do
|
||||
command="${command##*/pyenv-}"
|
||||
if [[ -n $nosh ]]; then
|
||||
if [[ ${command:0:3} != "sh-" ]]; then
|
||||
echo "$command"
|
||||
fi
|
||||
else
|
||||
echo "${command##sh-}"
|
||||
fi
|
||||
done
|
||||
done
|
||||
fi
|
||||
} | sort -u
|
||||
|
|
@ -1,26 +0,0 @@
|
|||
#!/usr/bin/env bash
|
||||
# Usage: pyenv completions <command> [arg1 arg2...]
|
||||
|
||||
set -e
|
||||
[ -n "$PYENV_DEBUG" ] && set -x
|
||||
|
||||
COMMAND="$1"
|
||||
if [ -z "$COMMAND" ]; then
|
||||
pyenv-help --usage completions >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Provide pyenv completions
|
||||
if [ "$COMMAND" = "--complete" ]; then
|
||||
exec pyenv-commands
|
||||
fi
|
||||
|
||||
COMMAND_PATH="$(command -v "pyenv-$COMMAND" || command -v "pyenv-sh-$COMMAND")"
|
||||
|
||||
# --help is provided automatically
|
||||
echo --help
|
||||
|
||||
if grep -iE "^([#%]|--|//) provide pyenv completions" "$COMMAND_PATH" >/dev/null; then
|
||||
shift
|
||||
exec "$COMMAND_PATH" --complete "$@"
|
||||
fi
|
||||
|
|
@ -1,57 +0,0 @@
|
|||
#!/usr/bin/env bash
|
||||
#
|
||||
# Summary: Run an executable with the selected Python version
|
||||
#
|
||||
# Usage: pyenv exec <command> [arg1 arg2...]
|
||||
#
|
||||
# Runs an executable by first preparing PATH so that the selected Python
|
||||
# version's `bin' directory is at the front.
|
||||
#
|
||||
# For example, if the currently selected Python version is 2.7.6:
|
||||
# pyenv exec pip install -r requirements.txt
|
||||
#
|
||||
# is equivalent to:
|
||||
# PATH="$PYENV_ROOT/versions/2.7.6/bin:$PATH" pip install -r requirements.txt
|
||||
|
||||
set -e
|
||||
[ -n "$PYENV_DEBUG" ] && set -x
|
||||
|
||||
# Provide pyenv completions
|
||||
if [ "$1" = "--complete" ]; then
|
||||
exec pyenv-shims --short
|
||||
fi
|
||||
|
||||
PYENV_VERSION="$(pyenv-version-name -f)"
|
||||
PYENV_COMMAND="$1"
|
||||
|
||||
if [ -z "$PYENV_COMMAND" ]; then
|
||||
pyenv-help --usage exec >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [[ -n $_PYENV_SHIM_PATH ]]; then
|
||||
PROGRAM="$(echo "$PYENV_COMMAND" | tr a-z- A-Z_ | sed 's/[^A-Z0-9_]/_/g')"
|
||||
NR_PYENV_SHIM_PATHS_PROGRAM="_PYENV_SHIM_PATHS_${PROGRAM}"
|
||||
export -- "$NR_PYENV_SHIM_PATHS_PROGRAM=$_PYENV_SHIM_PATH${!NR_PYENV_SHIM_PATHS_PROGRAM:+:${!NR_PYENV_SHIM_PATHS_PROGRAM}}"
|
||||
unset PROGRAM NR_PYENV_SHIM_PATHS_PROGRAM
|
||||
unset _PYENV_SHIM_PATH
|
||||
fi
|
||||
|
||||
PYENV_COMMAND_PATH="$(pyenv-which "$PYENV_COMMAND")"
|
||||
PYENV_BIN_PATH="${PYENV_COMMAND_PATH%/*}"
|
||||
|
||||
export PYENV_VERSION
|
||||
|
||||
OLDIFS="$IFS"
|
||||
IFS=$'\n' scripts=(`pyenv-hooks exec`)
|
||||
IFS="$OLDIFS"
|
||||
for script in "${scripts[@]}"; do
|
||||
source "$script"
|
||||
done
|
||||
|
||||
shift 1
|
||||
if [ "${PYENV_BIN_PATH#${PYENV_ROOT}}" != "${PYENV_BIN_PATH}" ]; then
|
||||
# Only add to $PATH for non-system version.
|
||||
export PATH="${PYENV_BIN_PATH}:${PATH}"
|
||||
fi
|
||||
exec "$PYENV_COMMAND_PATH" "$@"
|
||||
|
|
@ -1,53 +0,0 @@
|
|||
#!/usr/bin/env bash
|
||||
#
|
||||
# Summary: Set or show the global Python version(s)
|
||||
#
|
||||
# Usage: pyenv global <version> <version2> <..>
|
||||
#
|
||||
# Sets the global Python version(s). You can override the global version at
|
||||
# any time by setting a directory-specific version with `pyenv local'
|
||||
# or by setting the `PYENV_VERSION' environment variable.
|
||||
#
|
||||
# <version> can be specified multiple times and should be a version
|
||||
# tag known to pyenv. The special version string `system' will use
|
||||
# your default system Python. Run `pyenv versions' for a list of
|
||||
# available Python versions.
|
||||
#
|
||||
# Example: To enable the python2.7 and python3.7 shims to find their
|
||||
# respective executables you could set both versions with:
|
||||
#
|
||||
# 'pyenv global 3.7.0 2.7.15'
|
||||
#
|
||||
|
||||
|
||||
set -e
|
||||
[ -n "$PYENV_DEBUG" ] && set -x
|
||||
|
||||
# Provide pyenv completions
|
||||
if [ "$1" = "--complete" ]; then
|
||||
echo system
|
||||
exec pyenv-versions --bare
|
||||
fi
|
||||
|
||||
versions=("$@")
|
||||
PYENV_VERSION_FILE="${PYENV_ROOT}/version"
|
||||
|
||||
if [ -n "$versions" ]; then
|
||||
pyenv-version-file-write "$PYENV_VERSION_FILE" "${versions[@]}"
|
||||
else
|
||||
OLDIFS="$IFS"
|
||||
# VAR=() of unquoted value does glob expansion (against the current dir's contents) after IFS-splitting
|
||||
# which is undesired
|
||||
set -f
|
||||
IFS=: versions=($(
|
||||
pyenv-version-file-read "$PYENV_VERSION_FILE" ||
|
||||
pyenv-version-file-read "${PYENV_ROOT}/global" ||
|
||||
pyenv-version-file-read "${PYENV_ROOT}/default" ||
|
||||
echo system
|
||||
))
|
||||
set +f
|
||||
IFS="$OLDIFS"
|
||||
for version in "${versions[@]}"; do
|
||||
echo "$version"
|
||||
done
|
||||
fi
|
||||
|
|
@ -1,63 +0,0 @@
|
|||
#!/usr/bin/env bash
|
||||
# Summary: List hook scripts for a given pyenv command
|
||||
# Usage: pyenv hooks <command>
|
||||
|
||||
set -e
|
||||
[ -n "$PYENV_DEBUG" ] && set -x
|
||||
|
||||
# Provide pyenv completions
|
||||
if [ "$1" = "--complete" ]; then
|
||||
echo exec
|
||||
echo rehash
|
||||
echo version-name
|
||||
echo version-origin
|
||||
echo which
|
||||
exit
|
||||
fi
|
||||
|
||||
PYENV_COMMAND="$1"
|
||||
if [ -z "$PYENV_COMMAND" ]; then
|
||||
pyenv-help --usage hooks >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if ! enable -f "${BASH_SOURCE%/*}"/pyenv-realpath.dylib realpath 2>/dev/null; then
|
||||
if [ -n "$PYENV_NATIVE_EXT" ]; then
|
||||
echo "pyenv: failed to load \`realpath' builtin" >&2
|
||||
exit 1
|
||||
fi
|
||||
READLINK=$(type -P readlink)
|
||||
if [ -z "$READLINK" ]; then
|
||||
echo "pyenv: cannot find readlink - are you missing GNU coreutils?" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
resolve_link() {
|
||||
$READLINK "$1"
|
||||
}
|
||||
|
||||
realpath() {
|
||||
local path="$1"
|
||||
local name
|
||||
# Use a subshell to avoid changing the current path
|
||||
(
|
||||
while [ -n "$path" ]; do
|
||||
name="${path##*/}"
|
||||
[ "$name" = "$path" ] || cd "${path%/*}"
|
||||
path="$(resolve_link "$name" || true)"
|
||||
done
|
||||
|
||||
echo "${PWD}/$name"
|
||||
)
|
||||
}
|
||||
fi
|
||||
|
||||
IFS=: hook_paths=($PYENV_HOOK_PATH)
|
||||
|
||||
shopt -s nullglob
|
||||
for path in "${hook_paths[@]}"; do
|
||||
for script in "$path/$PYENV_COMMAND"/*.bash; do
|
||||
realpath "$script"
|
||||
done
|
||||
done
|
||||
shopt -u nullglob
|
||||
|
|
@ -1,514 +0,0 @@
|
|||
#!/usr/bin/env bash
|
||||
# Summary: Configure the shell environment for pyenv
|
||||
# Usage: eval "$(pyenv init [-|--path] [--no-push-path] [--no-rehash] [<shell>])"
|
||||
# pyenv init --install [<shell>]
|
||||
# pyenv init --detect-shell [<shell>]
|
||||
|
||||
set -e
|
||||
[ -n "$PYENV_DEBUG" ] && set -x
|
||||
|
||||
# Provide pyenv completions
|
||||
if [ "$1" = "--complete" ]; then
|
||||
echo -
|
||||
echo --path
|
||||
echo --install
|
||||
echo --no-push-path
|
||||
echo --no-rehash
|
||||
echo --detect-shell
|
||||
echo bash
|
||||
echo fish
|
||||
echo ksh
|
||||
echo pwsh
|
||||
echo zsh
|
||||
exit
|
||||
fi
|
||||
|
||||
mode="help"
|
||||
|
||||
while [ "$#" -gt 0 ]; do
|
||||
case "$1" in
|
||||
-)
|
||||
mode="print"
|
||||
;;
|
||||
--path)
|
||||
mode="path"
|
||||
;;
|
||||
--install)
|
||||
mode="install"
|
||||
;;
|
||||
--detect-shell)
|
||||
mode="detect-shell"
|
||||
;;
|
||||
--no-push-path)
|
||||
no_push_path=1
|
||||
;;
|
||||
--no-rehash)
|
||||
no_rehash=1
|
||||
;;
|
||||
*)
|
||||
shell="$1"
|
||||
;;
|
||||
esac
|
||||
shift
|
||||
done
|
||||
|
||||
# If shell is not provided, detect it.
|
||||
if [ -z "$shell" ]; then
|
||||
if shell=$(tr '\0' ' ' 2>/dev/null </proc/"$PPID"/cmdline);then
|
||||
:
|
||||
else
|
||||
shell=$(ps p "$PPID" -o 'args=' 2>/dev/null || true)
|
||||
fi
|
||||
shell="${shell%% *}"
|
||||
shell="${shell##-}"
|
||||
shell="${shell:-$SHELL}"
|
||||
shell="${shell##*/}"
|
||||
shell="${shell%%-*}"
|
||||
fi
|
||||
|
||||
function main() {
|
||||
case "$mode" in
|
||||
"help")
|
||||
help_
|
||||
exit 1
|
||||
;;
|
||||
"path")
|
||||
print_path
|
||||
print_rehash
|
||||
exit 0
|
||||
;;
|
||||
"print")
|
||||
init_dirs
|
||||
print_path
|
||||
print_env
|
||||
print_completion
|
||||
print_rehash
|
||||
print_shell_function
|
||||
exit 0
|
||||
;;
|
||||
"detect-shell")
|
||||
detect_profile
|
||||
print_detect_shell
|
||||
exit 0
|
||||
;;
|
||||
"install")
|
||||
install_shell_startup_files
|
||||
exit 0
|
||||
;;
|
||||
esac
|
||||
# should never get here
|
||||
exit 2
|
||||
}
|
||||
|
||||
function detect_profile() {
|
||||
case "$shell" in
|
||||
bash )
|
||||
if [ -e "${HOME}/.bash_profile" ]; then
|
||||
profile='~/.bash_profile'
|
||||
else
|
||||
profile='~/.profile'
|
||||
fi
|
||||
profile_explain="~/.bash_profile if it exists, otherwise ~/.profile"
|
||||
rc='~/.bashrc'
|
||||
;;
|
||||
fish )
|
||||
profile='~/.config/fish/config.fish'
|
||||
rc='~/.config/fish/config.fish'
|
||||
;;
|
||||
pwsh )
|
||||
profile='~/.config/powershell/profile.ps1'
|
||||
rc='~/.config/powershell/profile.ps1'
|
||||
;;
|
||||
zsh )
|
||||
profile='~/.zprofile'
|
||||
rc='~/.zshrc'
|
||||
;;
|
||||
ksh | ksh93 | mksh )
|
||||
# There are two implementations of Korn shell: AT&T (ksh93) and Mir (mksh).
|
||||
# Systems may have them installed under those names, or as ksh, so those
|
||||
# are recognized here. The obsolete ksh88 (subsumed by ksh93) and pdksh
|
||||
# (subsumed by mksh) are not included, since they are unlikely to still
|
||||
# be in use as interactive shells anywhere.
|
||||
profile='~/.profile'
|
||||
rc='~/.profile'
|
||||
;;
|
||||
* )
|
||||
profile=
|
||||
rc=
|
||||
profile_explain='your shell'\''s login startup file'
|
||||
rc_explain='your shell'\''s interactive startup file'
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
function print_detect_shell() {
|
||||
echo "PYENV_SHELL_DETECT=$shell"
|
||||
echo "PYENV_PROFILE_DETECT=$profile"
|
||||
echo "PYENV_RC_DETECT=$rc"
|
||||
}
|
||||
|
||||
function help_() {
|
||||
detect_profile
|
||||
{
|
||||
case "$shell" in
|
||||
fish )
|
||||
echo "# Add pyenv executable to PATH by running"
|
||||
echo "# the following interactively:"
|
||||
echo
|
||||
print_fish_user_path_setup
|
||||
echo
|
||||
echo "# Load pyenv automatically by appending"
|
||||
echo "# the following to ~/.config/fish/config.fish:"
|
||||
echo
|
||||
print_fish_shell_setup
|
||||
echo
|
||||
;;
|
||||
pwsh )
|
||||
echo '# Load pyenv automatically by appending'
|
||||
echo "# the following to $profile :"
|
||||
echo
|
||||
print_pwsh_shell_setup
|
||||
;;
|
||||
* )
|
||||
echo '# Load pyenv automatically by appending'
|
||||
echo -n "# the following to "
|
||||
if [[ "$profile" == "$rc" && -z $rc_explain ]]; then
|
||||
echo "${profile_explain:-$profile} :"
|
||||
else
|
||||
echo
|
||||
echo "# ${profile_explain:-$profile} (for login shells)"
|
||||
echo "# and ${rc_explain:-$rc} (for interactive shells) :"
|
||||
fi
|
||||
echo
|
||||
print_posix_shell_setup
|
||||
;;
|
||||
esac
|
||||
echo
|
||||
echo '# Restart your shell for the changes to take effect.'
|
||||
echo
|
||||
} >&2
|
||||
}
|
||||
|
||||
function print_posix_shell_setup() {
|
||||
echo 'export PYENV_ROOT="$HOME/.pyenv"'
|
||||
echo '[[ -d $PYENV_ROOT/bin ]] && export PATH="$PYENV_ROOT/bin:$PATH"'
|
||||
echo 'eval "$(pyenv init - '$shell')"'
|
||||
}
|
||||
|
||||
function print_fish_shell_setup() {
|
||||
echo 'pyenv init - fish | source'
|
||||
}
|
||||
|
||||
function print_fish_user_path_setup() {
|
||||
echo 'set -Ux PYENV_ROOT $HOME/.pyenv'
|
||||
echo 'if functions -q fish_add_path'
|
||||
echo ' test -d $PYENV_ROOT/bin; and fish_add_path $PYENV_ROOT/bin'
|
||||
echo 'else'
|
||||
echo ' test -d $PYENV_ROOT/bin; and set -U fish_user_paths $PYENV_ROOT/bin $fish_user_paths'
|
||||
echo 'end'
|
||||
}
|
||||
|
||||
function print_pwsh_shell_setup() {
|
||||
echo '$Env:PYENV_ROOT="$Env:HOME/.pyenv"'
|
||||
echo 'if (Test-Path -LP "$Env:PYENV_ROOT/bin" -PathType Container) {'
|
||||
echo ' $Env:PATH="$Env:PYENV_ROOT/bin:$Env:PATH" }'
|
||||
echo 'iex ((pyenv init -) -join "`n")'
|
||||
}
|
||||
|
||||
function expand_home_path() {
|
||||
local path="$1"
|
||||
printf '%s\n' "${path/#\~/$HOME}"
|
||||
}
|
||||
|
||||
function install_shell_startup_files() {
|
||||
if [[ -z $HOME ]]; then
|
||||
echo "pyenv: HOME must be set to configure shell startup files" >&2
|
||||
return 1
|
||||
fi
|
||||
|
||||
detect_profile
|
||||
|
||||
local files=()
|
||||
local lines=()
|
||||
local profile_path rc_path setup
|
||||
|
||||
case "$shell" in
|
||||
bash | zsh | ksh | ksh93 | mksh )
|
||||
rc_path="$(expand_home_path "$rc")"
|
||||
profile_path="$(expand_home_path "$profile")"
|
||||
setup="$(print_posix_shell_setup)"
|
||||
files=("$rc_path")
|
||||
lines=("$setup")
|
||||
if [[ $profile_path != "$rc_path" ]]; then
|
||||
files+=("$profile_path")
|
||||
lines+=("$setup")
|
||||
fi
|
||||
;;
|
||||
fish )
|
||||
rc_path="$(expand_home_path "$rc")"
|
||||
files=("$rc_path")
|
||||
lines=("$(print_fish_shell_setup)")
|
||||
;;
|
||||
pwsh )
|
||||
rc_path="$(expand_home_path "$rc")"
|
||||
files=("$rc_path")
|
||||
lines=("$(print_pwsh_shell_setup)")
|
||||
;;
|
||||
* )
|
||||
echo "pyenv: cannot automatically configure startup files for $shell" >&2
|
||||
return 1
|
||||
;;
|
||||
esac
|
||||
|
||||
local index
|
||||
for ((index = 0; index < ${#files[@]}; index++)); do
|
||||
check_startup_file "${files[$index]}" || return 1
|
||||
done
|
||||
|
||||
if [[ $shell == fish ]]; then
|
||||
install_fish_user_paths || return 1
|
||||
fi
|
||||
|
||||
for ((index = 0; index < ${#files[@]}; index++)); do
|
||||
append_lines "${files[$index]}" "${lines[$index]}"
|
||||
done
|
||||
}
|
||||
|
||||
function check_startup_file() {
|
||||
local file="$1"
|
||||
local grep_status
|
||||
|
||||
if [[ ! -e $file ]]; then
|
||||
return 0
|
||||
fi
|
||||
|
||||
if [[ ! -f $file || ! -r $file ]]; then
|
||||
echo "pyenv: failed to inspect $file" >&2
|
||||
return 1
|
||||
fi
|
||||
|
||||
if grep -Fi pyenv "$file" >/dev/null; then
|
||||
echo "pyenv: cannot automatically apply changes to $file: it appears to already contain Pyenv-related code." >&2
|
||||
echo "pyenv: review the file's contents and apply changes manually if necessary." >&2
|
||||
echo "pyenv: run \`pyenv init $shell\` to see the suggested setup." >&2
|
||||
return 1
|
||||
else
|
||||
grep_status=$?
|
||||
if [[ $grep_status == 1 ]]; then
|
||||
return 0
|
||||
fi
|
||||
echo "pyenv: failed to inspect $file" >&2
|
||||
return "$grep_status"
|
||||
fi
|
||||
}
|
||||
|
||||
function install_fish_user_paths() {
|
||||
local fish_setup
|
||||
|
||||
if ! command -v fish >/dev/null; then
|
||||
echo "pyenv: fish is not available to configure fish universal variables" >&2
|
||||
return 1
|
||||
fi
|
||||
|
||||
fish_setup="$(print_fish_user_path_setup)"
|
||||
if ! fish -c "$fish_setup"; then
|
||||
echo "pyenv: failed to configure fish universal variables" >&2
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
function append_lines() {
|
||||
local file="$1"
|
||||
local lines="$2"
|
||||
local dir last_char
|
||||
|
||||
dir="${file%/*}"
|
||||
if [[ $dir != "$file" ]]; then
|
||||
mkdir -p "$dir"
|
||||
fi
|
||||
|
||||
if [[ -s $file ]]; then
|
||||
last_char="$(tail -c 1 "$file")" || return 1
|
||||
if [[ -n $last_char ]]; then
|
||||
echo >> "$file"
|
||||
fi
|
||||
fi
|
||||
|
||||
printf '%s\n' "$lines" >> "$file"
|
||||
}
|
||||
|
||||
function init_dirs() {
|
||||
mkdir -p "${PYENV_ROOT}/"{shims,versions}
|
||||
}
|
||||
|
||||
function print_path() {
|
||||
# if no_push_path is set, guard the PATH manipulation with a check on whether
|
||||
# the shim is already in the PATH.
|
||||
if [ -n "$no_push_path" ]; then
|
||||
case "$shell" in
|
||||
fish )
|
||||
echo 'if not contains -- "'"${PYENV_ROOT}/shims"'" $PATH'
|
||||
print_path_prepend_shims
|
||||
echo 'end'
|
||||
;;
|
||||
pwsh )
|
||||
echo 'if ( $Env:PATH -notmatch "'"${PYENV_ROOT}/shims"'" ) {'
|
||||
print_path_prepend_shims
|
||||
echo '}'
|
||||
;;
|
||||
* )
|
||||
echo 'if [[ ":$PATH:" != *'\':"${PYENV_ROOT}"/shims:\''* ]]; then'
|
||||
print_path_prepend_shims
|
||||
echo 'fi'
|
||||
;;
|
||||
esac
|
||||
else
|
||||
case "$shell" in
|
||||
fish )
|
||||
echo 'while set pyenv_index (contains -i -- "'"${PYENV_ROOT}/shims"'" $PATH)'
|
||||
echo 'set -eg PATH[$pyenv_index]; end; set -e pyenv_index'
|
||||
print_path_prepend_shims
|
||||
;;
|
||||
pwsh )
|
||||
echo '$Env:PATH="$(($Env:PATH -split '"':'"' | where { -not ($_ -match '"'${PYENV_ROOT}/shims'"') }) -join '"':'"')"'
|
||||
print_path_prepend_shims
|
||||
;;
|
||||
* )
|
||||
# Some distros (notably Debian-based) set Bash's SSH_SOURCE_BASHRC compilation option
|
||||
# that makes it source `bashrc` under SSH even when not interactive.
|
||||
# This is inhibited by a guard in Debian's stock `bashrc` but some people remove it
|
||||
# in order to get proper environment for noninteractive remote commands
|
||||
# (SSH provides /etc/ssh/sshrc and ~/.ssh/rc for that but no-one seems to use them for some reason).
|
||||
# This has caused an infinite `bashrc` execution loop for those people in the below nested Bash invocation (#2367).
|
||||
# --norc negates this behavior of such a customized Bash.
|
||||
echo 'PATH="$(bash --norc -ec '\''IFS=:; paths=($PATH); '
|
||||
echo 'for i in ${!paths[@]}; do '
|
||||
echo 'if [[ ${paths[i]} == "'\'\'"${PYENV_ROOT}/shims"\'\''" ]]; then unset '\'\\\'\''paths[i]'\'\\\'\''; '
|
||||
echo 'fi; done; '
|
||||
echo 'echo "${paths[*]}"'\'')"'
|
||||
print_path_prepend_shims
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
}
|
||||
|
||||
function print_path_prepend_shims() {
|
||||
case "$shell" in
|
||||
fish )
|
||||
echo 'set -gx PATH '\'"${PYENV_ROOT}/shims"\'' $PATH'
|
||||
;;
|
||||
pwsh )
|
||||
echo '$Env:PATH="'"${PYENV_ROOT}"'/shims:$Env:PATH"'
|
||||
;;
|
||||
* )
|
||||
echo 'export PATH="'"${PYENV_ROOT}"'/shims:${PATH}"'
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
function print_env() {
|
||||
case "$shell" in
|
||||
fish )
|
||||
echo "set -gx PYENV_SHELL $shell"
|
||||
;;
|
||||
pwsh )
|
||||
echo '$Env:PYENV_SHELL="'"$shell"'"'
|
||||
;;
|
||||
* )
|
||||
echo "export PYENV_SHELL=$shell"
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
function print_completion() {
|
||||
completion="${_PYENV_INSTALL_PREFIX}/completions/pyenv.${shell}"
|
||||
if [ -r "$completion" ]; then
|
||||
case "$shell" in
|
||||
pwsh )
|
||||
echo "iex (gc $completion -Raw)"
|
||||
;;
|
||||
* )
|
||||
echo "source '$completion'"
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
}
|
||||
|
||||
function print_rehash() {
|
||||
if [ -z "$no_rehash" ]; then
|
||||
case "$shell" in
|
||||
pwsh )
|
||||
echo '& pyenv rehash'
|
||||
;;
|
||||
* )
|
||||
echo 'command pyenv rehash'
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
}
|
||||
|
||||
function print_shell_function() {
|
||||
commands=(`pyenv-commands --sh`)
|
||||
case "$shell" in
|
||||
fish )
|
||||
echo \
|
||||
'function pyenv
|
||||
set command $argv[1]
|
||||
set -e argv[1]
|
||||
|
||||
switch "$command"
|
||||
case '"${commands[*]}"'
|
||||
source (pyenv "sh-$command" $argv|psub)
|
||||
case "*"
|
||||
command pyenv "$command" $argv
|
||||
end
|
||||
end'
|
||||
;;
|
||||
pwsh )
|
||||
cat <<EOS
|
||||
function pyenv {
|
||||
\$command=""
|
||||
if ( \$args.Count -gt 0 ) {
|
||||
\$command, \$args = \$args
|
||||
}
|
||||
|
||||
if ( ("${commands[*]}" -split ' ') -contains \$command ) {
|
||||
\$shell_cmds = (& (get-command -commandtype application pyenv -totalcount 1) sh-\$command \$args)
|
||||
if ( \$shell_cmds.Count -gt 0 ) {
|
||||
iex (\$shell_cmds -join "\`n")
|
||||
}
|
||||
} else {
|
||||
& (get-command -commandtype application pyenv -totalcount 1) \$command \$args
|
||||
}
|
||||
}
|
||||
EOS
|
||||
;;
|
||||
ksh | ksh93 | mksh )
|
||||
echo \
|
||||
'function pyenv {
|
||||
typeset command=${1:-}'
|
||||
;;
|
||||
* )
|
||||
echo \
|
||||
'pyenv() {
|
||||
local command=${1:-}'
|
||||
;;
|
||||
esac
|
||||
|
||||
if [ "$shell" != "fish" ] && [ "$shell" != "pwsh" ]; then
|
||||
IFS="|"
|
||||
echo \
|
||||
' [ "$#" -gt 0 ] && shift
|
||||
case "$command" in
|
||||
'"${commands[*]:-/}"')
|
||||
eval "$(pyenv "sh-$command" "$@")"
|
||||
;;
|
||||
*)
|
||||
command pyenv "$command" "$@"
|
||||
;;
|
||||
esac
|
||||
}'
|
||||
fi
|
||||
}
|
||||
|
||||
main
|
||||
|
|
@ -1,105 +0,0 @@
|
|||
#!/usr/bin/env bash
|
||||
# Summary: Print the latest installed or known version with the given prefix
|
||||
# Usage: pyenv latest [-k|--known] <prefix>
|
||||
#
|
||||
# -k/--known Select from all known versions instead of installed
|
||||
# -b/--bypass (internal) On a resolution failure, do not print an error message
|
||||
# but rather print the argument unchanged
|
||||
# -f/--force (internal) Same as -b but also do not return a failure exit code
|
||||
|
||||
set -e
|
||||
[ -n "$PYENV_DEBUG" ] && set -x
|
||||
|
||||
|
||||
while [[ $# -gt 0 ]]
|
||||
do
|
||||
case "$1" in
|
||||
-k|--known)
|
||||
FROM_KNOWN=1
|
||||
shift
|
||||
;;
|
||||
-b|--bypass)
|
||||
BYPASS=1
|
||||
shift
|
||||
;;
|
||||
-f|--force)
|
||||
FORCE=1
|
||||
BYPASS=1
|
||||
shift
|
||||
;;
|
||||
*)
|
||||
break
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
prefix=$1
|
||||
exitcode=0
|
||||
|
||||
IFS=$'\n'
|
||||
|
||||
if [[ -z $FROM_KNOWN ]]; then
|
||||
if [[ -d $PYENV_ROOT/versions/$prefix ]]; then
|
||||
echo "$prefix"
|
||||
exit $exitcode;
|
||||
fi
|
||||
DEFINITION_CANDIDATES=( $(pyenv-versions --bare --skip-envs) )
|
||||
else
|
||||
DEFINITION_CANDIDATES=( $(python-build --definitions ) )
|
||||
fi
|
||||
|
||||
if printf '%s\n' "${DEFINITION_CANDIDATES[@]}" 2>/dev/null | grep -qxFe "$prefix"; then
|
||||
echo "$prefix"
|
||||
exit $exitcode;
|
||||
fi
|
||||
|
||||
suffix=""
|
||||
if [[ $prefix =~ ^(.*[0-9])t$ ]]; then
|
||||
suffix="t"
|
||||
prefix="${BASH_REMATCH[1]}"
|
||||
fi
|
||||
|
||||
# https://stackoverflow.com/questions/11856054/is-there-an-easy-way-to-pass-a-raw-string-to-grep/63483807#63483807
|
||||
prefix_re="$(sed 's/[^\^]/[&]/g;s/[\^]/\\&/g' <<< "$prefix")"
|
||||
suffix_re="$(sed 's/[^\^]/[&]/g;s/[\^]/\\&/g' <<< "$suffix")"
|
||||
# FIXME: more reliable and readable would probably be to loop over them and transform in pure Bash
|
||||
DEFINITION_CANDIDATES=(\
|
||||
$(printf '%s\n' "${DEFINITION_CANDIDATES[@]}" | \
|
||||
grep -Ee "^$prefix_re[-.].*$suffix_re\$" || true))
|
||||
|
||||
DEFINITION_CANDIDATES=(\
|
||||
$(printf '%s\n' "${DEFINITION_CANDIDATES[@]}" | \
|
||||
sed -E -e '/-dev$/d' -e '/-src$/d' -e '/-latest$/d' -e '/(a|b|rc)[0-9]+$/d' \
|
||||
$(if [[ -z $suffix ]]; then echo "-e /[0-9]t\$/d"; fi)
|
||||
));
|
||||
|
||||
# Compose a sorting key, followed by | and original value
|
||||
DEFINITION_CANDIDATES=(\
|
||||
$(printf '%s\n' "${DEFINITION_CANDIDATES[@]}" | \
|
||||
awk \
|
||||
'{ if (match($0,"^[[:alnum:]]+-"))
|
||||
{ print substr($0,0,RLENGTH-1) "." substr($0,RLENGTH+1) "..|" $0; }
|
||||
else
|
||||
{ print $0 "...|" $0; }
|
||||
}'))
|
||||
DEFINITION_CANDIDATES=(\
|
||||
$(printf '%s\n' "${DEFINITION_CANDIDATES[@]}" \
|
||||
| sort -t. -k1,1r -k 2,2nr -k 3,3nr -k4,4nr \
|
||||
| cut -f2 -d $'|' \
|
||||
|| true))
|
||||
DEFINITION="${DEFINITION_CANDIDATES[0]}"
|
||||
|
||||
if [[ -n "$DEFINITION" ]]; then
|
||||
echo "$DEFINITION"
|
||||
else
|
||||
if [[ -z $BYPASS ]]; then
|
||||
echo "pyenv: no $([[ -z $FROM_KNOWN ]] && echo installed || echo known) versions match the prefix \`$prefix'" >&2
|
||||
else
|
||||
echo "$prefix"
|
||||
fi
|
||||
if [[ -z $FORCE ]]; then
|
||||
exitcode=1
|
||||
fi
|
||||
fi
|
||||
|
||||
exit $exitcode
|
||||
|
|
@ -1,74 +0,0 @@
|
|||
#!/usr/bin/env bash
|
||||
#
|
||||
# Summary: Set or show the local application-specific Python version(s)
|
||||
#
|
||||
# Usage: pyenv local [-f|--force] [<version> [...]]
|
||||
# pyenv local --unset
|
||||
#
|
||||
# -f/--force Do not verify that the versions being set exist
|
||||
#
|
||||
# Sets the local application-specific Python version(s) by writing the
|
||||
# version name to a file named `.python-version'.
|
||||
#
|
||||
# When you run a Python command, pyenv will look for a `.python-version'
|
||||
# file in the current directory and each parent directory. If no such
|
||||
# file is found in the tree, pyenv will use the global Python version
|
||||
# specified with `pyenv global'. A version specified with the
|
||||
# `PYENV_VERSION' environment variable takes precedence over local
|
||||
# and global versions.
|
||||
#
|
||||
# <version> can be specified multiple times and should be a version
|
||||
# tag known to pyenv. The special version string `system' will use
|
||||
# your default system Python. Run `pyenv versions' for a list of
|
||||
# available Python versions.
|
||||
#
|
||||
# Example: To enable the python2.7 and python3.7 shims to find their
|
||||
# respective executables you could set both versions with:
|
||||
#
|
||||
# 'pyenv local 3.7.0 2.7.15'
|
||||
|
||||
|
||||
set -e
|
||||
[ -n "$PYENV_DEBUG" ] && set -x
|
||||
|
||||
# Provide pyenv completions
|
||||
if [ "$1" = "--complete" ]; then
|
||||
echo --unset
|
||||
echo system
|
||||
exec pyenv-versions --bare
|
||||
fi
|
||||
|
||||
while [[ $# -gt 0 ]]
|
||||
do
|
||||
case "$1" in
|
||||
-f|--force)
|
||||
FORCE=1
|
||||
shift
|
||||
;;
|
||||
*)
|
||||
break
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
versions=("$@")
|
||||
|
||||
if [ "$versions" = "--unset" ]; then
|
||||
rm -f .python-version
|
||||
elif [ -n "$versions" ]; then
|
||||
pyenv-version-file-write ${FORCE:+-f }.python-version "${versions[@]}"
|
||||
else
|
||||
if version_file="$(pyenv-version-file "$PWD")"; then
|
||||
# VAR=() of unquoted value does glob expansion (against the current dir's contents) after IFS-splitting
|
||||
# which is undesired
|
||||
set -f
|
||||
IFS=: versions=($(pyenv-version-file-read "$version_file"))
|
||||
set +f
|
||||
for version in "${versions[@]}"; do
|
||||
echo "$version"
|
||||
done
|
||||
else
|
||||
echo "pyenv: no local version configured for this directory" >&2
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
|
@ -1,66 +0,0 @@
|
|||
#!/usr/bin/env bash
|
||||
# Summary: Display prefixes for Python versions
|
||||
# Usage: pyenv prefix [<version>...]
|
||||
#
|
||||
# Displays the directories where the given Python versions are installed,
|
||||
# separated by colons. If no version is given, `pyenv prefix' displays the
|
||||
# locations of the currently selected versions.
|
||||
|
||||
set -e
|
||||
[ -n "$PYENV_DEBUG" ] && set -x
|
||||
|
||||
# Provide pyenv completions
|
||||
if [ "$1" = "--complete" ]; then
|
||||
echo system
|
||||
exec pyenv-versions --bare
|
||||
fi
|
||||
|
||||
if [ -n "$1" ]; then
|
||||
OLDIFS="$IFS"
|
||||
{ IFS=:
|
||||
export PYENV_VERSION="$*"
|
||||
}
|
||||
IFS="$OLDIFS"
|
||||
elif [ -z "$PYENV_VERSION" ]; then
|
||||
PYENV_VERSION="$(pyenv-version-name)"
|
||||
fi
|
||||
|
||||
PYENV_PREFIX_PATHS=()
|
||||
OLDIFS="$IFS"
|
||||
{ IFS=:
|
||||
# Unquoted $VAR does glob expansion (against the current dir's contents) after IFS-splitting
|
||||
# which is undesired
|
||||
set -f
|
||||
for version in ${PYENV_VERSION}; do
|
||||
if [ "$version" = "system" ]; then
|
||||
if PYTHON_PATH="$(PYENV_VERSION="${version}" pyenv-which python --skip-advice 2>/dev/null)" || \
|
||||
PYTHON_PATH="$(PYENV_VERSION="${version}" pyenv-which python3 --skip-advice 2>/dev/null)" || \
|
||||
PYTHON_PATH="$(PYENV_VERSION="${version}" pyenv-which python2 --skip-advice 2>/dev/null)"; then
|
||||
shopt -s extglob
|
||||
# In some distros (Arch), Python can be found in sbin as well as bin
|
||||
PYENV_PREFIX_PATH="${PYTHON_PATH%/?(s)bin/*}"
|
||||
PYENV_PREFIX_PATH="${PYENV_PREFIX_PATH:-/}"
|
||||
else
|
||||
echo "pyenv: system version not found in PATH" >&2
|
||||
exit 1
|
||||
fi
|
||||
else
|
||||
version="$(pyenv-latest -f "$version")"
|
||||
PYENV_PREFIX_PATH="${PYENV_ROOT}/versions/${version}"
|
||||
fi
|
||||
if [ -d "$PYENV_PREFIX_PATH" ]; then
|
||||
PYENV_PREFIX_PATHS=("${PYENV_PREFIX_PATHS[@]}" "$PYENV_PREFIX_PATH")
|
||||
else
|
||||
echo "pyenv: version \`${version}' not installed" >&2
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
set +f
|
||||
}
|
||||
IFS="$OLDIFS"
|
||||
|
||||
OLDIFS="$IFS"
|
||||
{ IFS=:
|
||||
echo "${PYENV_PREFIX_PATHS[*]}"
|
||||
}
|
||||
IFS="$OLDIFS"
|
||||
|
|
@ -1,206 +0,0 @@
|
|||
#!/usr/bin/env bash
|
||||
# Summary: Rehash pyenv shims (run this after installing executables)
|
||||
|
||||
set -e
|
||||
[[ -n "$PYENV_DEBUG" ]] && set -x
|
||||
|
||||
SHIM_PATH="${PYENV_ROOT}/shims"
|
||||
PROTOTYPE_SHIM_PATH="${SHIM_PATH}/.pyenv-shim"
|
||||
|
||||
# Create the shims directory if it doesn't already exist.
|
||||
mkdir -p "$SHIM_PATH"
|
||||
|
||||
declare last_acquire_error
|
||||
|
||||
acquire_lock() {
|
||||
local ret
|
||||
# An old lock file is presumed stale. We assume no healthy rehash takes this long.
|
||||
# The time is picked very small so that a killed rehash holds up new shell sessions
|
||||
# for as little as possible
|
||||
find "$PROTOTYPE_SHIM_PATH" -mmin +2 -exec rm -f {} \; 2>/dev/null || true
|
||||
set -o noclobber
|
||||
last_acquire_error="$( { ( echo -n > "$PROTOTYPE_SHIM_PATH"; ) 2>&1 1>&3 3>&1-; } 3>&1)" \
|
||||
&& trap release_lock EXIT \
|
||||
|| {
|
||||
# Linux Landlock and MacOS Seatbelt sandbox subsystems return false information in access(),
|
||||
# making -w "$SHIM_PATH" not catch the fact that the shims dir is not writable in this case.
|
||||
# Bash doesn't provide access to errno to check for non-EEXIST error code in `echo >'.
|
||||
# So check for writablity by trying to write to a different file,
|
||||
# in a way that taxes the usual use case as little as possible.
|
||||
if [[ -z $tested_for_other_write_errors ]]; then
|
||||
# if lots of (50+) rehashes run concurrently, another concurrent rehash
|
||||
# may delete the temporary file in remove_*_shims() before we do so
|
||||
( t="$(TMPDIR="$SHIM_PATH" mktemp)" && rm -f "$t" ) \
|
||||
&& tested_for_other_write_errors=1 \
|
||||
|| { echo "pyenv: cannot rehash: $SHIM_PATH isn't writable" >&2
|
||||
set +o noclobber
|
||||
exit 1; }
|
||||
fi
|
||||
ret=1
|
||||
}
|
||||
set +o noclobber
|
||||
[[ -z "${ret}" ]]
|
||||
}
|
||||
|
||||
remove_prototype_shim() {
|
||||
rm -f "$PROTOTYPE_SHIM_PATH"
|
||||
}
|
||||
|
||||
release_lock() {
|
||||
remove_prototype_shim
|
||||
trap - EXIT
|
||||
}
|
||||
|
||||
if [ ! -w "$SHIM_PATH" ]; then
|
||||
echo "pyenv: cannot rehash: $SHIM_PATH isn't writable" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
declare acquired tested_for_other_write_errors
|
||||
declare start=$SECONDS
|
||||
PYENV_REHASH_TIMEOUT=${PYENV_REHASH_TIMEOUT:-60}
|
||||
while (( SECONDS <= start + PYENV_REHASH_TIMEOUT )); do
|
||||
if acquire_lock; then
|
||||
acquired=1
|
||||
break
|
||||
else
|
||||
# POSIX sleep(1) doesn't provide subsecond precision, but many others do
|
||||
sleep 0.1 2>/dev/null || sleep 1
|
||||
fi
|
||||
done
|
||||
|
||||
if [ -z "${acquired}" ]; then
|
||||
if [[ -n $tested_for_other_write_errors ]]; then
|
||||
echo "pyenv: cannot rehash: couldn't acquire lock"\
|
||||
"$PROTOTYPE_SHIM_PATH for $PYENV_REHASH_TIMEOUT seconds. Last error message:" >&2
|
||||
echo "$last_acquire_error" >&2
|
||||
fi
|
||||
exit 1
|
||||
fi
|
||||
unset tested_for_other_write_errors
|
||||
|
||||
# The prototype shim file is a script that re-execs itself, passing
|
||||
# its filename and any arguments to `pyenv exec`. This file is
|
||||
# hard-linked for every executable and then removed. The linking
|
||||
# technique is fast, uses less disk space than unique files, and also
|
||||
# serves as a locking mechanism.
|
||||
create_prototype_shim() {
|
||||
cat > "$PROTOTYPE_SHIM_PATH" <<SH
|
||||
#!/usr/bin/env bash
|
||||
set -e
|
||||
[ -n "\$PYENV_DEBUG" ] && set -x
|
||||
|
||||
program="\${0##*/}"
|
||||
|
||||
export PYENV_ROOT="$PYENV_ROOT"
|
||||
SHIM_PATH=\${0%/*}
|
||||
if [[ \$SHIM_PATH != "$PYENV_ROOT/shims" ]]; then
|
||||
export _PYENV_SHIM_PATH="\$SHIM_PATH"
|
||||
fi
|
||||
exec "$(command -v pyenv)" exec "\$program" "\$@"
|
||||
SH
|
||||
chmod +x "$PROTOTYPE_SHIM_PATH"
|
||||
}
|
||||
|
||||
# If the contents of the prototype shim file differ from the contents
|
||||
# of the first shim in the shims directory, assume pyenv has been
|
||||
# upgraded and the existing shims need to be removed.
|
||||
remove_outdated_shims() {
|
||||
local shim
|
||||
for shim in "$SHIM_PATH"/*; do
|
||||
if ! diff "$PROTOTYPE_SHIM_PATH" "$shim" >/dev/null 2>&1; then
|
||||
rm -f "$SHIM_PATH"/*
|
||||
fi
|
||||
break
|
||||
done
|
||||
}
|
||||
|
||||
# The basename of each argument passed to `make_shims` will be
|
||||
# registered for installation as a shim. In this way, plugins may call
|
||||
# `make_shims` with a glob to register many shims at once.
|
||||
make_shims() {
|
||||
local file shim
|
||||
for file; do
|
||||
shim="${file##*/}"
|
||||
register_shim "$shim"
|
||||
done
|
||||
}
|
||||
|
||||
if ((${BASH_VERSINFO[0]} > 3)); then
|
||||
|
||||
declare -A registered_shims
|
||||
|
||||
# Registers the name of a shim to be generated.
|
||||
register_shim() {
|
||||
registered_shims["$1"]=1
|
||||
}
|
||||
|
||||
# Install all shims registered via `make_shims` or `register_shim` directly.
|
||||
install_registered_shims() {
|
||||
local shim file
|
||||
for shim in "${!registered_shims[@]}"; do
|
||||
file="${SHIM_PATH}/${shim}"
|
||||
[ -e "$file" ] || cp "$PROTOTYPE_SHIM_PATH" "$file"
|
||||
done
|
||||
}
|
||||
|
||||
# Once the registered shims have been installed, we make a second pass
|
||||
# over the contents of the shims directory. Any file that is present
|
||||
# in the directory but has not been registered as a shim should be
|
||||
# removed.
|
||||
remove_stale_shims() {
|
||||
local shim
|
||||
for shim in "$SHIM_PATH"/*; do
|
||||
if [[ ! ${registered_shims["${shim##*/}"]} ]]; then
|
||||
rm -f "$shim"
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
else # Same for bash < 4.
|
||||
|
||||
registered_shims=" "
|
||||
|
||||
register_shim() {
|
||||
registered_shims="${registered_shims}${1} "
|
||||
}
|
||||
|
||||
install_registered_shims() {
|
||||
local shim file
|
||||
for shim in $registered_shims; do
|
||||
file="${SHIM_PATH}/${shim}"
|
||||
[ -e "$file" ] || cp "$PROTOTYPE_SHIM_PATH" "$file"
|
||||
done
|
||||
}
|
||||
|
||||
remove_stale_shims() {
|
||||
local shim
|
||||
for shim in "$SHIM_PATH"/*; do
|
||||
if [[ "$registered_shims" != *" ${shim##*/} "* ]]; then
|
||||
rm -f "$shim"
|
||||
fi
|
||||
done
|
||||
}
|
||||
fi
|
||||
|
||||
shopt -s nullglob
|
||||
|
||||
# Create the prototype shim, then register shims for all known
|
||||
# executables.
|
||||
create_prototype_shim
|
||||
remove_outdated_shims
|
||||
# shellcheck disable=SC2046
|
||||
make_shims $(pyenv-versions --executables)
|
||||
|
||||
|
||||
# Allow plugins to register shims.
|
||||
OLDIFS="$IFS"
|
||||
IFS=$'\n' scripts=(`pyenv-hooks rehash`)
|
||||
IFS="$OLDIFS"
|
||||
|
||||
for script in "${scripts[@]}"; do
|
||||
source "$script"
|
||||
done
|
||||
|
||||
install_registered_shims
|
||||
remove_stale_shims
|
||||
|
|
@ -1,29 +0,0 @@
|
|||
#!/usr/bin/env bash
|
||||
set -e
|
||||
[ -n "$PYENV_DEBUG" ] && set -x
|
||||
|
||||
# Provide pyenv completions
|
||||
if [ "$1" = "--complete" ]; then
|
||||
exec pyenv-rehash --complete
|
||||
fi
|
||||
|
||||
shell="$(basename "${PYENV_SHELL:-$SHELL}")"
|
||||
|
||||
# When pyenv shell integration is enabled, delegate to pyenv-rehash,
|
||||
# then tell the shell to empty its command lookup cache.
|
||||
case "$shell" in
|
||||
pwsh)
|
||||
echo "& (get-command pyenv -commandtype application) rehash"
|
||||
;;
|
||||
*)
|
||||
echo "command pyenv rehash"
|
||||
esac
|
||||
|
||||
case "$shell" in
|
||||
fish | pwsh )
|
||||
# no executable cache
|
||||
;;
|
||||
* )
|
||||
echo "hash -r 2>/dev/null || true"
|
||||
;;
|
||||
esac
|
||||
|
|
@ -1,137 +0,0 @@
|
|||
#!/usr/bin/env bash
|
||||
#
|
||||
# Summary: Set or show the shell-specific Python version
|
||||
#
|
||||
# Usage: pyenv shell <version>...
|
||||
# pyenv shell -
|
||||
# pyenv shell --unset
|
||||
#
|
||||
# Sets a shell-specific Python version by setting the `PYENV_VERSION'
|
||||
# environment variable in your shell. This version overrides local
|
||||
# application-specific versions and the global version.
|
||||
#
|
||||
# <version> should be a string matching a Python version known to pyenv.
|
||||
# The special version string `system' will use your default system Python.
|
||||
# Run `pyenv versions' for a list of available Python versions.
|
||||
#
|
||||
# When `-` is passed instead of the version string, the previously set
|
||||
# version will be restored. With `--unset`, the `PYENV_VERSION`
|
||||
# environment variable gets unset, restoring the environment to the
|
||||
# state before the first `pyenv shell` call.
|
||||
|
||||
set -e
|
||||
[ -n "$PYENV_DEBUG" ] && set -x
|
||||
|
||||
# Provide pyenv completions
|
||||
if [ "$1" = "--complete" ]; then
|
||||
echo --unset
|
||||
echo system
|
||||
exec pyenv-versions --bare
|
||||
fi
|
||||
|
||||
versions=("$@")
|
||||
shell="$(basename "${PYENV_SHELL:-$SHELL}")"
|
||||
|
||||
if [ -z "$versions" ]; then
|
||||
if [ -z "$PYENV_VERSION" ]; then
|
||||
echo "pyenv: no shell-specific version configured" >&2
|
||||
exit 1
|
||||
else
|
||||
echo 'echo "$PYENV_VERSION"'
|
||||
exit
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ "$versions" = "--unset" ]; then
|
||||
case "$shell" in
|
||||
fish )
|
||||
echo 'set -gu PYENV_VERSION_OLD "$PYENV_VERSION"'
|
||||
echo "set -e PYENV_VERSION"
|
||||
;;
|
||||
pwsh )
|
||||
echo '$Env:PYENV_VERSION, $Env:PYENV_VERSION_OLD = $null, $Env:PYENV_VERSION'
|
||||
;;
|
||||
* )
|
||||
echo 'PYENV_VERSION_OLD="${PYENV_VERSION-}"'
|
||||
echo "unset PYENV_VERSION"
|
||||
;;
|
||||
esac
|
||||
exit
|
||||
fi
|
||||
|
||||
if [ "$versions" = "-" ]; then
|
||||
case "$shell" in
|
||||
fish )
|
||||
cat <<EOS
|
||||
if set -q PYENV_VERSION_OLD
|
||||
if [ -n "\$PYENV_VERSION_OLD" ]
|
||||
set PYENV_VERSION_OLD_ "\$PYENV_VERSION"
|
||||
set -gx PYENV_VERSION "\$PYENV_VERSION_OLD"
|
||||
set -gu PYENV_VERSION_OLD "\$PYENV_VERSION_OLD_"
|
||||
set -e PYENV_VERSION_OLD_
|
||||
else
|
||||
set -gu PYENV_VERSION_OLD "\$PYENV_VERSION"
|
||||
set -e PYENV_VERSION
|
||||
end
|
||||
else
|
||||
echo "pyenv: PYENV_VERSION_OLD is not set" >&2
|
||||
false
|
||||
end
|
||||
EOS
|
||||
;;
|
||||
pwsh )
|
||||
cat <<EOS
|
||||
if ( Get-Item -Path Env:\PYENV_VERSION* ) {
|
||||
\$Env:PYENV_VERSION, \$Env:PYENV_VERSION_OLD = \$Env:PYENV_VERSION_OLD, \$Env:PYENV_VERSION
|
||||
} else {
|
||||
Write-Error "pyenv: Env:PYENV_VERSION_OLD is not set"
|
||||
return \$false
|
||||
}
|
||||
EOS
|
||||
;;
|
||||
* )
|
||||
cat <<EOS
|
||||
if [ -n "\${PYENV_VERSION_OLD+x}" ]; then
|
||||
if [ -n "\$PYENV_VERSION_OLD" ]; then
|
||||
PYENV_VERSION_OLD_="\$PYENV_VERSION"
|
||||
export PYENV_VERSION="\$PYENV_VERSION_OLD"
|
||||
PYENV_VERSION_OLD="\$PYENV_VERSION_OLD_"
|
||||
unset PYENV_VERSION_OLD_
|
||||
else
|
||||
PYENV_VERSION_OLD="\$PYENV_VERSION"
|
||||
unset PYENV_VERSION
|
||||
fi
|
||||
else
|
||||
echo "pyenv: PYENV_VERSION_OLD is not set" >&2
|
||||
false
|
||||
fi
|
||||
EOS
|
||||
;;
|
||||
esac
|
||||
exit
|
||||
fi
|
||||
|
||||
# Make sure the specified version is installed.
|
||||
if pyenv-prefix "${versions[@]}" >/dev/null; then
|
||||
OLDIFS="$IFS"
|
||||
IFS=: version="${versions[*]}"
|
||||
IFS="$OLDIFS"
|
||||
if [ "$version" != "$PYENV_VERSION" ]; then
|
||||
case "$shell" in
|
||||
fish )
|
||||
echo 'set -gu PYENV_VERSION_OLD "$PYENV_VERSION"'
|
||||
echo "set -gx PYENV_VERSION \"$version\""
|
||||
;;
|
||||
pwsh )
|
||||
echo '$Env:PYENV_VERSION, $Env:PYENV_VERSION_OLD = "'"${version}"'", $Env:PYENV_VERSION'
|
||||
;;
|
||||
* )
|
||||
echo 'PYENV_VERSION_OLD="${PYENV_VERSION-}"'
|
||||
echo "export PYENV_VERSION=\"${version}\""
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
else
|
||||
echo "false"
|
||||
exit 1
|
||||
fi
|
||||
|
|
@ -1,40 +0,0 @@
|
|||
#!/usr/bin/env bash
|
||||
# Summary: Show the current Python version(s) and its origin
|
||||
# Usage: pyenv version [--bare]
|
||||
#
|
||||
# --bare show just the version name. An alias to `pyenv version-name'
|
||||
|
||||
set -e
|
||||
[ -n "$PYENV_DEBUG" ] && set -x
|
||||
|
||||
exitcode=0
|
||||
OLDIFS="$IFS"
|
||||
# VAR=() of unquoted value does glob expansion (against the current dir's contents) after IFS-splitting
|
||||
# which is undesired
|
||||
set -f
|
||||
IFS=: PYENV_VERSION_NAMES=($(pyenv-version-name)) || exitcode=$?
|
||||
set +f
|
||||
IFS="$OLDIFS"
|
||||
|
||||
unset bare
|
||||
for arg; do
|
||||
case "$arg" in
|
||||
--complete )
|
||||
echo --bare
|
||||
exit ;;
|
||||
--bare ) bare=1 ;;
|
||||
* )
|
||||
pyenv-help --usage version >&2
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
done
|
||||
for PYENV_VERSION_NAME in "${PYENV_VERSION_NAMES[@]}"; do
|
||||
if [[ -n $bare ]]; then
|
||||
echo "$PYENV_VERSION_NAME"
|
||||
else
|
||||
echo "$PYENV_VERSION_NAME (set by $(pyenv-version-origin))"
|
||||
fi
|
||||
done
|
||||
|
||||
exit $exitcode
|
||||
|
|
@ -1,46 +0,0 @@
|
|||
#!/usr/bin/env bash
|
||||
# Usage: pyenv version-file [<dir>]
|
||||
# Summary: Detect the file that sets the current pyenv version
|
||||
set -e
|
||||
[ -n "$PYENV_DEBUG" ] && set -x
|
||||
|
||||
target_dir="$1"
|
||||
|
||||
find_local_version_file() {
|
||||
local root="$1"
|
||||
# Nonexistent paths are UB as of this writing.
|
||||
# Relative ones cause a failure but absolute ones don't
|
||||
[[ $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
|
||||
fi
|
||||
[[ -n $root ]] || break
|
||||
root="${root%/*}"
|
||||
done
|
||||
return 1
|
||||
}
|
||||
|
||||
if [ -n "$target_dir" ]; then
|
||||
find_local_version_file "$target_dir"
|
||||
else
|
||||
# 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"
|
||||
} || echo "${PYENV_ROOT}/version"
|
||||
fi
|
||||
|
|
@ -1,43 +0,0 @@
|
|||
#!/usr/bin/env bash
|
||||
# Usage: pyenv version-file-read <file>
|
||||
set -e
|
||||
[ -n "$PYENV_DEBUG" ] && set -x
|
||||
|
||||
VERSION_FILE="$1"
|
||||
|
||||
function is_version_safe() {
|
||||
# As needed, check that the constructed path exists as a child path of PYENV_ROOT/versions
|
||||
version="$1"
|
||||
if [[ "$version" == ".." || "$version" == */* ]]; then
|
||||
# Sanity check the value of version to prevent malicious path-traversal
|
||||
(
|
||||
cd "$PYENV_ROOT/versions/$version" &>/dev/null || exit 1
|
||||
[[ "$PWD" == "$PYENV_ROOT/versions/"* ]]
|
||||
)
|
||||
return $?
|
||||
else
|
||||
return 0
|
||||
fi
|
||||
}
|
||||
|
||||
if [ -s "$VERSION_FILE" ]; then
|
||||
# Read the first non-whitespace word from the specified version file.
|
||||
# Be careful not to load it whole in case there's something crazy in it.
|
||||
IFS="$IFS"$'\r'
|
||||
sep=
|
||||
while read -n 1024 -r version _ || [[ $version ]]; do
|
||||
if [[ -z "$version" || "$version" == \#* ]]; then
|
||||
# Skip empty lines and comments
|
||||
continue
|
||||
elif ! is_version_safe "$version"; then
|
||||
# CVE-2022-35861 allowed arbitrary code execution in some contexts and is mitigated by is_version_safe.
|
||||
echo "pyenv: invalid version \`$version' ignored in \`$VERSION_FILE'" >&2
|
||||
continue
|
||||
fi
|
||||
printf "%s%s" "$sep" "$version"
|
||||
sep=:
|
||||
done <"$VERSION_FILE"
|
||||
[[ $sep ]] && { echo; exit; }
|
||||
fi
|
||||
|
||||
exit 1
|
||||
|
|
@ -1,40 +0,0 @@
|
|||
#!/usr/bin/env bash
|
||||
# Usage: pyenv version-file-write [-f|--force] <file> <version> [...]
|
||||
#
|
||||
# -f/--force Don't verify that the versions exist
|
||||
|
||||
set -e
|
||||
[ -n "$PYENV_DEBUG" ] && set -x
|
||||
|
||||
while [[ $# -gt 0 ]]
|
||||
do
|
||||
case "$1" in
|
||||
-f|--force)
|
||||
FORCE=1
|
||||
shift
|
||||
;;
|
||||
*)
|
||||
break
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
|
||||
PYENV_VERSION_FILE="$1"
|
||||
shift || true
|
||||
versions=("$@")
|
||||
|
||||
if [ -z "$versions" ] || [ -z "$PYENV_VERSION_FILE" ]; then
|
||||
pyenv-help --usage version-file-write >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Make sure the specified version is installed.
|
||||
[[ -z $FORCE ]] && pyenv-prefix "${versions[@]}" >/dev/null
|
||||
|
||||
# Write the version out to disk.
|
||||
# Create an empty file. Using "rm" might cause a permission error.
|
||||
> "$PYENV_VERSION_FILE"
|
||||
for version in "${versions[@]}"; do
|
||||
echo "$version" >> "$PYENV_VERSION_FILE"
|
||||
done
|
||||
|
|
@ -1,86 +0,0 @@
|
|||
#!/usr/bin/env bash
|
||||
# Summary: Show the current Python version
|
||||
#
|
||||
# -f/--force (Internal) If a version doesn't exist, print it as is rather than produce an error
|
||||
|
||||
set -e
|
||||
[ -n "$PYENV_DEBUG" ] && set -x
|
||||
|
||||
while [[ $# -gt 0 ]]
|
||||
do
|
||||
case "$1" in
|
||||
-f|--force)
|
||||
FORCE=1
|
||||
shift
|
||||
;;
|
||||
*)
|
||||
break
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
|
||||
if [ -z "$PYENV_VERSION" ]; then
|
||||
PYENV_VERSION_FILE="$(pyenv-version-file)"
|
||||
PYENV_VERSION="$(pyenv-version-file-read "$PYENV_VERSION_FILE" || true)"
|
||||
fi
|
||||
|
||||
OLDIFS="$IFS"
|
||||
IFS=$'\n' scripts=(`pyenv-hooks version-name`)
|
||||
IFS="$OLDIFS"
|
||||
for script in "${scripts[@]}"; do
|
||||
source "$script"
|
||||
done
|
||||
|
||||
if [ -z "$PYENV_VERSION" ] || [ "$PYENV_VERSION" = "system" ]; then
|
||||
echo "system"
|
||||
exit
|
||||
fi
|
||||
|
||||
version_exists() {
|
||||
local version="$1"
|
||||
[ -d "${PYENV_ROOT}/versions/${version}" ]
|
||||
}
|
||||
|
||||
versions=()
|
||||
OLDIFS="$IFS"
|
||||
{ IFS=:
|
||||
any_not_installed=0
|
||||
normalization_done=
|
||||
# Unquoted $VAR does glob expansion (against the current dir's contents) after IFS-splitting
|
||||
# which is undesired
|
||||
set -f
|
||||
for version in ${PYENV_VERSION}; do
|
||||
# Remove the explicit 'python-' prefix from versions like 'python-3.12'.
|
||||
normalised_version="${version#python-}"
|
||||
[[ $version != "${normalised_version}" ]] && normalization_done=1
|
||||
if [[ $version == "system" ]] || version_exists "${normalised_version}" ; then
|
||||
versions+=("${normalised_version}")
|
||||
elif [[ -n $normalization_done ]] && version_exists "${version}"; then
|
||||
versions+=("${version}")
|
||||
elif resolved_version="$(pyenv-latest -b "${normalised_version}")"; then
|
||||
versions+=("${resolved_version}")
|
||||
elif [[ -n $normalization_done ]] && resolved_version="$(pyenv-latest -b "${version}")"; then
|
||||
versions+=("${resolved_version}")
|
||||
else
|
||||
if [[ -n $FORCE ]]; then
|
||||
versions+=("${normalised_version}")
|
||||
else
|
||||
echo "pyenv: version \`$version' is not installed (set by $(pyenv-version-origin))" >&2
|
||||
any_not_installed=1
|
||||
fi
|
||||
fi
|
||||
done
|
||||
set +f
|
||||
}
|
||||
IFS="$OLDIFS"
|
||||
|
||||
OLDIFS="$IFS"
|
||||
{ IFS=:
|
||||
echo "${versions[*]}"
|
||||
}
|
||||
IFS="$OLDIFS"
|
||||
|
||||
if [ "$any_not_installed" = 1 ]; then
|
||||
exit 1
|
||||
fi
|
||||
|
|
@ -1,21 +0,0 @@
|
|||
#!/usr/bin/env bash
|
||||
# Summary: Explain how the current Python version is set
|
||||
set -e
|
||||
[ -n "$PYENV_DEBUG" ] && set -x
|
||||
|
||||
unset PYENV_VERSION_ORIGIN
|
||||
|
||||
OLDIFS="$IFS"
|
||||
IFS=$'\n' scripts=(`pyenv-hooks version-origin`)
|
||||
IFS="$OLDIFS"
|
||||
for script in "${scripts[@]}"; do
|
||||
source "$script"
|
||||
done
|
||||
|
||||
if [ -n "$PYENV_VERSION_ORIGIN" ]; then
|
||||
echo "$PYENV_VERSION_ORIGIN"
|
||||
elif [ -n "$PYENV_VERSION" ]; then
|
||||
echo "PYENV_VERSION environment variable"
|
||||
else
|
||||
pyenv-version-file
|
||||
fi
|
||||
|
|
@ -1,203 +0,0 @@
|
|||
#!/usr/bin/env bash
|
||||
# Summary: List all Python versions available to pyenv
|
||||
# Usage: pyenv versions [--bare] [--skip-aliases] [--skip-envs] [--executables]
|
||||
#
|
||||
# Lists all Python versions found in `$PYENV_ROOT/versions/*'.
|
||||
#
|
||||
# --bare List just the names, omit `system'
|
||||
# --skip-aliases Skip symlinks to other versions and to virtual environments
|
||||
# --skip-envs Skip virtual environments (under <version>/envs)
|
||||
# --executables Internal. Overrides other options.
|
||||
# Optimally get a deduplicated list of all executable names in Pyenv-managed
|
||||
# versions and environments for `pyenv rehash'
|
||||
#
|
||||
|
||||
set -e
|
||||
[ -n "$PYENV_DEBUG" ] && set -x
|
||||
|
||||
unset bare skip_aliases skip_envs executables
|
||||
# Provide pyenv completions
|
||||
for arg; do
|
||||
case "$arg" in
|
||||
--complete )
|
||||
echo --bare
|
||||
echo --skip-aliases
|
||||
echo --skip-envs
|
||||
exit ;;
|
||||
--executables ) executables=1; break ;;
|
||||
--bare ) bare=1 ;;
|
||||
--skip-aliases ) skip_aliases=1 ;;
|
||||
--skip-envs ) skip_envs=1 ;;
|
||||
* )
|
||||
pyenv-help --usage versions >&2
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
|
||||
versions_dir="${PYENV_ROOT}/versions"
|
||||
|
||||
# Fast path for rehash: skip filtering and link resolution
|
||||
if [[ -n "$executables" ]]; then
|
||||
if [ -d "$versions_dir" ]; then
|
||||
shopt -s dotglob nullglob
|
||||
# MacOS 12+ and FreeBSD 15 support `xargs -r -0' and `basename -a'
|
||||
# `sort -u` is simpler and a bit faster than `awk '!seen[$0]++'`, with the same result for rehash purposes
|
||||
printf '%s\0' "$versions_dir"/*/bin/* "$versions_dir"/*/envs/*/bin/* | xargs -0 -r basename -a | sort -u
|
||||
shopt -u dotglob nullglob
|
||||
fi
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if ! enable -f "${BASH_SOURCE%/*}"/pyenv-realpath.dylib realpath 2>/dev/null; then
|
||||
if [ -n "$PYENV_NATIVE_EXT" ]; then
|
||||
echo "pyenv: failed to load \`realpath' builtin" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
READLINK=$(type -P readlink)
|
||||
if [ -z "$READLINK" ]; then
|
||||
echo "pyenv: cannot find readlink - are you missing GNU coreutils?" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
resolve_link() {
|
||||
$READLINK "$1"
|
||||
}
|
||||
|
||||
realpath() {
|
||||
local path="$1"
|
||||
local name
|
||||
|
||||
# Use a subshell to avoid changing the current path
|
||||
(
|
||||
while [ -n "$path" ]; do
|
||||
name="${path##*/}"
|
||||
[ "$name" = "$path" ] || cd "${path%/*}"
|
||||
path="$(resolve_link "$name" || true)"
|
||||
done
|
||||
|
||||
echo "${PWD}/$name"
|
||||
)
|
||||
}
|
||||
fi
|
||||
|
||||
if [ -d "$versions_dir" ]; then
|
||||
versions_dir="$(realpath "$versions_dir")"
|
||||
fi
|
||||
|
||||
if ((${BASH_VERSINFO[0]} > 3)); then
|
||||
declare -A current_versions
|
||||
else
|
||||
current_versions=()
|
||||
fi
|
||||
if [ -n "$bare" ]; then
|
||||
include_system=""
|
||||
else
|
||||
hit_prefix="* "
|
||||
miss_prefix=" "
|
||||
OLDIFS="$IFS"
|
||||
IFS=:
|
||||
# VAR=() of unquoted value does glob expansion (against the current dir's contents) after IFS-splitting
|
||||
# which is undesired
|
||||
set -f
|
||||
if ((${BASH_VERSINFO[0]} > 3)); then
|
||||
for i in $(pyenv-version-name || true); do
|
||||
current_versions["$i"]="1"
|
||||
done
|
||||
else
|
||||
current_versions=($(pyenv-version-name || true))
|
||||
fi
|
||||
set +f
|
||||
IFS="$OLDIFS"
|
||||
include_system="1"
|
||||
fi
|
||||
|
||||
num_versions=0
|
||||
|
||||
exists() {
|
||||
local car="$1"
|
||||
local cdar
|
||||
shift
|
||||
for cdar in "$@"; do
|
||||
if [ "${car}" == "${cdar}" ]; then
|
||||
return 0
|
||||
fi
|
||||
done
|
||||
return 1
|
||||
}
|
||||
|
||||
print_version() {
|
||||
local version="${1:?}"
|
||||
if [[ -n $bare ]]; then
|
||||
echo "$version"
|
||||
return
|
||||
fi
|
||||
local path="${2:?}"
|
||||
if [[ -L "$path" ]]; then
|
||||
# Only resolve the link itself for printing, do not resolve further.
|
||||
# Doing otherwise would misinform the user of what the link contains.
|
||||
version_repr="$version --> $(readlink "$path")"
|
||||
else
|
||||
version_repr="$version"
|
||||
fi
|
||||
if [[ ${BASH_VERSINFO[0]} -ge 4 && ${current_versions["$1"]} ]]; then
|
||||
echo "${hit_prefix}${version_repr} (set by $(pyenv-version-origin))"
|
||||
elif (( ${BASH_VERSINFO[0]} <= 3 )) && exists "$1" "${current_versions[@]}"; then
|
||||
echo "${hit_prefix}${version_repr} (set by $(pyenv-version-origin))"
|
||||
else
|
||||
echo "${miss_prefix}${version_repr}"
|
||||
fi
|
||||
num_versions=$((num_versions + 1))
|
||||
}
|
||||
|
||||
# Include "system" in the non-bare output, if it exists
|
||||
if [ -n "$include_system" ] && \
|
||||
(PYENV_VERSION=system pyenv-which python --skip-advice >/dev/null 2>&1 || \
|
||||
PYENV_VERSION=system pyenv-which python3 --skip-advice >/dev/null 2>&1 || \
|
||||
PYENV_VERSION=system pyenv-which python2 --skip-advice >/dev/null 2>&1) ; then
|
||||
print_version system "/"
|
||||
fi
|
||||
|
||||
shopt -s dotglob nullglob
|
||||
versions_dir_entries=("$versions_dir"/*)
|
||||
if sort --version-sort </dev/null >/dev/null 2>&1; then
|
||||
# system sort supports version sorting
|
||||
OLDIFS="$IFS"
|
||||
# VAR=() of unquoted value does glob expansion (against the current dir's contents) after IFS-splitting
|
||||
# which is undesired
|
||||
set -f
|
||||
IFS=$'\n'
|
||||
versions_dir_entries=($(
|
||||
printf "%s\n" "${versions_dir_entries[@]}" |
|
||||
sort --version-sort
|
||||
))
|
||||
set +f
|
||||
IFS="$OLDIFS"
|
||||
fi
|
||||
|
||||
for path in "${versions_dir_entries[@]}"; do
|
||||
if [ -d "$path" ]; then
|
||||
if [ -n "$skip_aliases" ] && [ -L "$path" ]; then
|
||||
target="$(realpath "$path")"
|
||||
[ "${target%/*}" == "$versions_dir" ] && continue
|
||||
[ "${target%/*/envs/*}" == "$versions_dir" ] && continue
|
||||
fi
|
||||
print_version "${path##*/}" "$path"
|
||||
# virtual environments created by anaconda/miniconda/pyenv-virtualenv
|
||||
if [[ -z $skip_envs ]]; then
|
||||
for env_path in "${path}/envs/"*; do
|
||||
if [ -d "${env_path}" ]; then
|
||||
print_version "${env_path#${PYENV_ROOT}/versions/}" "${env_path}"
|
||||
fi
|
||||
done
|
||||
fi
|
||||
fi
|
||||
done
|
||||
shopt -u dotglob nullglob
|
||||
|
||||
if [ "$num_versions" -eq 0 ] && [ -n "$include_system" ]; then
|
||||
echo "Warning: no Python detected on the system" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
|
@ -1,38 +0,0 @@
|
|||
#!/usr/bin/env bash
|
||||
# Summary: List all Python versions that contain the given executable
|
||||
# Usage: pyenv whence [--path] <command>
|
||||
|
||||
set -e
|
||||
[ -n "$PYENV_DEBUG" ] && set -x
|
||||
|
||||
# Provide pyenv completions
|
||||
if [ "$1" = "--complete" ]; then
|
||||
echo --path
|
||||
exec pyenv-shims --short
|
||||
fi
|
||||
|
||||
if [ "$1" = "--path" ]; then
|
||||
print_paths="1"
|
||||
shift
|
||||
else
|
||||
print_paths=""
|
||||
fi
|
||||
|
||||
whence() {
|
||||
local command="$1"
|
||||
pyenv-versions --bare | while read -r version; do
|
||||
path="$(pyenv-prefix "$version")/bin/${command}"
|
||||
if [ -x "$path" ]; then
|
||||
[ "$print_paths" ] && echo "$path" || echo "$version"
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
PYENV_COMMAND="$1"
|
||||
if [ -z "$PYENV_COMMAND" ]; then
|
||||
pyenv-help --usage whence >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
result="$(whence "$PYENV_COMMAND")"
|
||||
[ -n "$result" ] && echo "$result"
|
||||
|
|
@ -1,126 +0,0 @@
|
|||
#!/usr/bin/env bash
|
||||
#
|
||||
# Summary: Display the full path to an executable
|
||||
#
|
||||
# Usage: pyenv which <command> [--nosystem] [--skip-advice]
|
||||
#
|
||||
# Displays the full path to the executable that pyenv will invoke when
|
||||
# you run the given command.
|
||||
# Use --nosystem argument in case when you don't need to search command in the
|
||||
# system environment.
|
||||
# Internal switch --skip-advice used to skip printing an error message on a
|
||||
# failed search.
|
||||
|
||||
set -e
|
||||
[ -n "$PYENV_DEBUG" ] && set -x
|
||||
|
||||
# Provide pyenv completions
|
||||
if [ "$1" = "--complete" ]; then
|
||||
exec pyenv-shims --short
|
||||
fi
|
||||
|
||||
system="system"
|
||||
SKIP_ADVICE=""
|
||||
PYENV_COMMAND="$1"
|
||||
|
||||
while [[ $# -gt 0 ]]
|
||||
do
|
||||
case "$1" in
|
||||
--skip-advice)
|
||||
SKIP_ADVICE=1
|
||||
shift
|
||||
;;
|
||||
--nosystem)
|
||||
system=""
|
||||
shift
|
||||
;;
|
||||
*)
|
||||
shift
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
|
||||
remove_from_path() {
|
||||
local -a paths_to_remove
|
||||
IFS=: paths_to_remove=($1)
|
||||
local path_to_remove path_before
|
||||
local result=":${PATH//\~/$HOME}:"
|
||||
for path_to_remove in "${paths_to_remove[@]}"; do
|
||||
while true; do
|
||||
path_before="$result"
|
||||
result="${result//:$path_to_remove:/:}"
|
||||
if [[ ${#path_before} == "${#result}" ]]; then break; fi
|
||||
done
|
||||
done
|
||||
result="${result:1:${#result}-2}"
|
||||
echo "$result"
|
||||
}
|
||||
|
||||
if [ -z "$PYENV_COMMAND" ]; then
|
||||
pyenv-help --usage which >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
OLDIFS="$IFS"
|
||||
# Unquoted $VAR or VAR=() of unquoted value does glob expansion (against the current dir's contents)
|
||||
# after IFS-splitting which is undesired
|
||||
set -f
|
||||
IFS=: versions=(${PYENV_VERSION:-$(pyenv-version-name -f)})
|
||||
set +f
|
||||
IFS="$OLDIFS"
|
||||
|
||||
declare -a nonexistent_versions
|
||||
|
||||
for version in "${versions[@]}" "$system"; do
|
||||
if [ "$version" = "system" ]; then
|
||||
PROGRAM="$(echo "$PYENV_COMMAND" | tr a-z- A-Z_ | sed 's/[^A-Z0-9_]/_/g')"
|
||||
NR_CUSTOM_SHIM_PATHS="_PYENV_SHIM_PATHS_$PROGRAM"
|
||||
SEARCH_PATH="$(remove_from_path "${PYENV_ROOT}/shims${!NR_CUSTOM_SHIM_PATHS:+:${!NR_CUSTOM_SHIM_PATHS}}")"
|
||||
PYENV_COMMAND_PATH="$(PATH="$SEARCH_PATH" command -v "$PYENV_COMMAND" || true)"
|
||||
else
|
||||
# $version may be a prefix to be resolved by pyenv-latest
|
||||
version_path="$(pyenv-prefix "${version}" 2>/dev/null)" || \
|
||||
{ nonexistent_versions+=("$version"); continue; }
|
||||
# resolve $version for hooks
|
||||
version="$(basename "$version_path")"
|
||||
PYENV_COMMAND_PATH="$version_path/bin/${PYENV_COMMAND}"
|
||||
unset version_path
|
||||
fi
|
||||
if [ -x "$PYENV_COMMAND_PATH" ]; then
|
||||
break
|
||||
fi
|
||||
done
|
||||
|
||||
OLDIFS="$IFS"
|
||||
IFS=$'\n' scripts=(`pyenv-hooks which`)
|
||||
IFS="$OLDIFS"
|
||||
for script in "${scripts[@]}"; do
|
||||
source "$script"
|
||||
done
|
||||
|
||||
if [ -x "$PYENV_COMMAND_PATH" ]; then
|
||||
echo "$PYENV_COMMAND_PATH"
|
||||
else
|
||||
if (( ${#nonexistent_versions[@]} )); then
|
||||
for version in "${nonexistent_versions[@]}"; do
|
||||
echo "pyenv: version \`$version' is not installed (set by $(pyenv-version-origin))" >&2
|
||||
done
|
||||
fi
|
||||
|
||||
echo "pyenv: $PYENV_COMMAND: command not found" >&2
|
||||
if [ -z "$SKIP_ADVICE" ]; then
|
||||
versions="$(pyenv-whence "$PYENV_COMMAND" || true)"
|
||||
if [ -n "$versions" ]; then
|
||||
{ echo
|
||||
echo "The \`$PYENV_COMMAND' command exists in these Python versions:"
|
||||
echo "$versions" | sed 's/^/ /g'
|
||||
echo
|
||||
echo "Note: See 'pyenv help global' for tips on allowing multiple"
|
||||
echo " Python versions to be found at the same time."
|
||||
} >&2
|
||||
fi
|
||||
fi
|
||||
|
||||
exit 127
|
||||
fi
|
||||
129
libexec/rbenv
Executable file
129
libexec/rbenv
Executable file
|
|
@ -0,0 +1,129 @@
|
|||
#!/usr/bin/env bash
|
||||
set -e
|
||||
|
||||
if [ "$1" = "--debug" ]; then
|
||||
export RBENV_DEBUG=1
|
||||
shift
|
||||
fi
|
||||
|
||||
if [ -n "$RBENV_DEBUG" ]; then
|
||||
# https://web.archive.org/web/20221105082147/https://wiki-dev.bash-hackers.org/scripting/debuggingtips#making_xtrace_more_useful
|
||||
export PS4='+(${BASH_SOURCE}:${LINENO}): ${FUNCNAME[0]:+${FUNCNAME[0]}(): }'
|
||||
set -x
|
||||
fi
|
||||
|
||||
abort() {
|
||||
{ if [ "$#" -eq 0 ]; then cat -
|
||||
else echo "rbenv: $*"
|
||||
fi
|
||||
} >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
if [ -z "${RBENV_ROOT}" ]; then
|
||||
RBENV_ROOT="${HOME}/.rbenv"
|
||||
else
|
||||
RBENV_ROOT="${RBENV_ROOT%/}"
|
||||
fi
|
||||
export RBENV_ROOT
|
||||
|
||||
if [ -z "${RBENV_DIR}" ]; then
|
||||
RBENV_DIR="$PWD"
|
||||
else
|
||||
[[ $RBENV_DIR == /* ]] || RBENV_DIR="$PWD/$RBENV_DIR"
|
||||
cd "$RBENV_DIR" 2>/dev/null || abort "cannot change working directory to \`$RBENV_DIR'"
|
||||
RBENV_DIR="$PWD"
|
||||
cd "$OLDPWD"
|
||||
fi
|
||||
export RBENV_DIR
|
||||
|
||||
[ -n "$RBENV_ORIG_PATH" ] || export RBENV_ORIG_PATH="$PATH"
|
||||
|
||||
canonicalize() {
|
||||
local readlink resolved_path
|
||||
if readlink="$(type -P greadlink)" || readlink="$(type -P readlink)"; then
|
||||
# happy path: GNU & BSD readlink, macOS 12.3+
|
||||
if resolved_path="$("$readlink" -f "$1" 2>/dev/null)"; then
|
||||
printf "%s\n" "$resolved_path"
|
||||
return 0
|
||||
fi
|
||||
# likely macOS < 12.3 with old readlink
|
||||
local path="$1"
|
||||
while [ -L "$path" ]; do
|
||||
resolved_path="$("$readlink" "$path" 2>/dev/null)"
|
||||
[[ $resolved_path == /* ]] || resolved_path="$(cd "${path%/*}/${resolved_path%/*}" && pwd)/${resolved_path##*/}"
|
||||
path="$resolved_path"
|
||||
done
|
||||
printf "%s\n" "$path"
|
||||
return 0
|
||||
fi
|
||||
# fail if the argument is a symlink and was not canonicalized
|
||||
[ ! -L "$1" ] || return 1
|
||||
}
|
||||
|
||||
shopt -s nullglob
|
||||
|
||||
# all this trouble just to find out where rbenv's executables live
|
||||
rbenv_bin="${BASH_SOURCE:-$0}"
|
||||
if libexec_dir="$(canonicalize "$rbenv_bin")"; then
|
||||
libexec_dir="${libexec_dir%/*}"
|
||||
else
|
||||
libexec_dir="${rbenv_bin%/*}"
|
||||
[ "$libexec_dir" != "." ] || libexec_dir="$PWD"
|
||||
fi
|
||||
|
||||
for plugin_bin in "${RBENV_ROOT}/plugins/"*/bin; do
|
||||
PATH="${plugin_bin}:${PATH}"
|
||||
done
|
||||
export PATH="${libexec_dir}:${PATH}"
|
||||
|
||||
RBENV_HOOK_PATH="${RBENV_HOOK_PATH}:${RBENV_ROOT}/rbenv.d"
|
||||
if [ ! "${libexec_dir%/*}"/rbenv.d -ef "$RBENV_ROOT"/rbenv.d ]; then
|
||||
# Add rbenv's own `rbenv.d` unless rbenv was cloned to RBENV_ROOT
|
||||
RBENV_HOOK_PATH="${RBENV_HOOK_PATH}:${libexec_dir%/*}/rbenv.d"
|
||||
fi
|
||||
RBENV_HOOK_PATH="${RBENV_HOOK_PATH}:/usr/etc/rbenv.d:/usr/local/etc/rbenv.d:/etc/rbenv.d:/usr/lib/rbenv/hooks"
|
||||
for plugin_hook in "${RBENV_ROOT}/plugins/"*/etc/rbenv.d; do
|
||||
RBENV_HOOK_PATH="${RBENV_HOOK_PATH}:${plugin_hook}"
|
||||
done
|
||||
RBENV_HOOK_PATH="${RBENV_HOOK_PATH#:}"
|
||||
export RBENV_HOOK_PATH
|
||||
|
||||
shopt -u nullglob
|
||||
|
||||
|
||||
command="$1"
|
||||
case "$command" in
|
||||
"" )
|
||||
{ rbenv---version
|
||||
rbenv-help
|
||||
} | abort
|
||||
;;
|
||||
-v | --version )
|
||||
exec rbenv---version
|
||||
;;
|
||||
-h | --help )
|
||||
exec rbenv-help
|
||||
;;
|
||||
* )
|
||||
command_path="$(type -P "rbenv-$command" || true)"
|
||||
if [ -z "$command_path" ]; then
|
||||
if [ "$command" == "shell" ]; then
|
||||
abort "shell integration not enabled. Run \`rbenv init' for instructions."
|
||||
else
|
||||
abort "no such command \`$command'"
|
||||
fi
|
||||
fi
|
||||
|
||||
shift 1
|
||||
if [ "$1" = --help ]; then
|
||||
if [[ "$command" == "sh-"* ]]; then
|
||||
echo "rbenv help \"$command\""
|
||||
else
|
||||
exec rbenv-help "$command"
|
||||
fi
|
||||
else
|
||||
exec "$command_path" "$@"
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
#!/usr/bin/env bash
|
||||
# Summary: Display the version of pyenv
|
||||
# Summary: Display the version of rbenv
|
||||
#
|
||||
# Displays the version number of this pyenv release, including the
|
||||
# Displays the version number of this rbenv release, including the
|
||||
# current revision from git, if available.
|
||||
#
|
||||
# The format of the git revision is:
|
||||
|
|
@ -10,14 +10,14 @@
|
|||
# tagged.
|
||||
|
||||
set -e
|
||||
[ -n "$PYENV_DEBUG" ] && set -x
|
||||
[ -n "$RBENV_DEBUG" ] && set -x
|
||||
|
||||
version="2.8.5"
|
||||
version="1.3.2"
|
||||
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 rbenv; then
|
||||
git_revision="$(git describe --tags HEAD 2>/dev/null || true)"
|
||||
git_revision="${git_revision#v}"
|
||||
fi
|
||||
|
||||
echo "pyenv ${git_revision:-$version}"
|
||||
echo "rbenv ${git_revision:-$version}"
|
||||
50
libexec/rbenv-commands
Executable file
50
libexec/rbenv-commands
Executable file
|
|
@ -0,0 +1,50 @@
|
|||
#!/usr/bin/env bash
|
||||
# Summary: List all available rbenv commands
|
||||
# Usage: rbenv commands [--sh|--no-sh]
|
||||
#
|
||||
# List names of all rbenv commands, including 3rd-party ones found in the
|
||||
# PATH or in rbenv plugins. With `--sh`, list only shell commands.
|
||||
#
|
||||
# This functionality is mainly meant for scripting. To see usage help for
|
||||
# rbenv, run `rbenv help`.
|
||||
|
||||
set -e
|
||||
[ -n "$RBENV_DEBUG" ] && set -x
|
||||
|
||||
# Provide rbenv completions
|
||||
if [ "$1" = "--complete" ]; then
|
||||
echo --sh
|
||||
echo --no-sh
|
||||
exit
|
||||
fi
|
||||
|
||||
exclude_shell=
|
||||
command_prefix="rbenv-"
|
||||
|
||||
if [ "$1" = "--sh" ]; then
|
||||
command_prefix="rbenv-sh-"
|
||||
shift
|
||||
elif [ "$1" = "--no-sh" ]; then
|
||||
exclude_shell=1
|
||||
shift
|
||||
fi
|
||||
|
||||
shopt -s nullglob
|
||||
|
||||
{
|
||||
PATH_remain="$PATH"
|
||||
# traverse PATH to find "rbenv-" prefixed commands
|
||||
while true; do
|
||||
path="${PATH_remain%%:*}"
|
||||
if [ -n "$path" ]; then
|
||||
for rbenv_command in "${path}/${command_prefix}"*; do
|
||||
rbenv_command="${rbenv_command##*rbenv-}"
|
||||
if [[ -z $exclude_shell || $rbenv_command != sh-* ]]; then
|
||||
echo "${rbenv_command##sh-}"
|
||||
fi
|
||||
done
|
||||
fi
|
||||
[[ $PATH_remain == *:* ]] || break
|
||||
PATH_remain="${PATH_remain#*:}"
|
||||
done
|
||||
} | sort | uniq
|
||||
26
libexec/rbenv-completions
Executable file
26
libexec/rbenv-completions
Executable file
|
|
@ -0,0 +1,26 @@
|
|||
#!/usr/bin/env bash
|
||||
# Usage: rbenv completions <command> [<args>...]
|
||||
|
||||
set -e
|
||||
[ -n "$RBENV_DEBUG" ] && set -x
|
||||
|
||||
COMMAND="$1"
|
||||
if [ -z "$COMMAND" ]; then
|
||||
rbenv-help --usage completions >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Provide rbenv completions
|
||||
if [ "$COMMAND" = "--complete" ]; then
|
||||
exec rbenv-commands
|
||||
fi
|
||||
|
||||
COMMAND_PATH="$(type -P "rbenv-$COMMAND" "rbenv-sh-$COMMAND" | head -n1)"
|
||||
|
||||
# --help is provided automatically
|
||||
echo --help
|
||||
|
||||
if grep -iE "^([#%]|--|//) provide rbenv completions" "$COMMAND_PATH" >/dev/null; then
|
||||
shift
|
||||
exec "$COMMAND_PATH" --complete "$@"
|
||||
fi
|
||||
46
libexec/rbenv-exec
Executable file
46
libexec/rbenv-exec
Executable file
|
|
@ -0,0 +1,46 @@
|
|||
#!/usr/bin/env bash
|
||||
#
|
||||
# Summary: Run an executable with the selected Ruby version
|
||||
#
|
||||
# Usage: rbenv exec <command> [<args>...]
|
||||
#
|
||||
# Runs an executable by first preparing PATH so that the selected Ruby
|
||||
# version's `bin' directory is at the front.
|
||||
#
|
||||
# For example, if the currently selected Ruby version is 1.9.3-p327:
|
||||
# rbenv exec bundle install
|
||||
#
|
||||
# is equivalent to:
|
||||
# PATH="$RBENV_ROOT/versions/1.9.3-p327/bin:$PATH" bundle install
|
||||
|
||||
set -e
|
||||
[ -n "$RBENV_DEBUG" ] && set -x
|
||||
|
||||
# Provide rbenv completions
|
||||
if [ "$1" = "--complete" ]; then
|
||||
exec rbenv-shims --short
|
||||
fi
|
||||
|
||||
RBENV_VERSION="$(rbenv-version-name)"
|
||||
RBENV_COMMAND="$1"
|
||||
|
||||
if [ -z "$RBENV_COMMAND" ]; then
|
||||
rbenv-help --usage exec >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
export RBENV_VERSION
|
||||
RBENV_COMMAND_PATH="$(rbenv-which "$RBENV_COMMAND")"
|
||||
RBENV_BIN_PATH="${RBENV_COMMAND_PATH%/*}"
|
||||
|
||||
IFS=$'\n' read -d '' -r -a scripts <<<"$(rbenv-hooks exec)" || true
|
||||
for script in "${scripts[@]}"; do
|
||||
# shellcheck disable=SC1090
|
||||
source "$script"
|
||||
done
|
||||
|
||||
shift 1
|
||||
if [ "$RBENV_VERSION" != "system" ]; then
|
||||
export PATH="${RBENV_BIN_PATH}:${PATH}"
|
||||
fi
|
||||
exec -a "$RBENV_COMMAND" "$RBENV_COMMAND_PATH" "$@"
|
||||
31
libexec/rbenv-global
Executable file
31
libexec/rbenv-global
Executable file
|
|
@ -0,0 +1,31 @@
|
|||
#!/usr/bin/env bash
|
||||
#
|
||||
# Summary: Set or show the global Ruby version
|
||||
#
|
||||
# Usage: rbenv global <version>
|
||||
#
|
||||
# Sets the global Ruby version. You can override the global version at
|
||||
# any time by setting a directory-specific version with `rbenv local'
|
||||
# or by setting the `RBENV_VERSION' environment variable.
|
||||
#
|
||||
# <version> should be a string matching a Ruby version known to rbenv.
|
||||
# The special version string `system' will use your default system Ruby.
|
||||
# Run `rbenv versions' for a list of available Ruby versions.
|
||||
|
||||
set -e
|
||||
[ -n "$RBENV_DEBUG" ] && set -x
|
||||
|
||||
# Provide rbenv completions
|
||||
if [ "$1" = "--complete" ]; then
|
||||
echo system
|
||||
exec rbenv-versions --bare
|
||||
fi
|
||||
|
||||
RBENV_VERSION="$1"
|
||||
RBENV_VERSION_FILE="${RBENV_ROOT}/version"
|
||||
|
||||
if [ -n "$RBENV_VERSION" ]; then
|
||||
rbenv-version-file-write "$RBENV_VERSION_FILE" "$RBENV_VERSION"
|
||||
else
|
||||
rbenv-version-file-read "$RBENV_VERSION_FILE" || echo system
|
||||
fi
|
||||
|
|
@ -2,7 +2,7 @@
|
|||
#
|
||||
# Summary: Display help for a command
|
||||
#
|
||||
# Usage: pyenv help [--usage] COMMAND
|
||||
# Usage: rbenv help [--usage] COMMAND
|
||||
#
|
||||
# Parses and displays help contents from a command's source file.
|
||||
#
|
||||
|
|
@ -13,22 +13,20 @@
|
|||
# documentation.
|
||||
|
||||
set -e
|
||||
[ -n "$PYENV_DEBUG" ] && set -x
|
||||
[ -n "$RBENV_DEBUG" ] && set -x
|
||||
|
||||
# Provide pyenv completions
|
||||
# Provide rbenv completions
|
||||
if [ "$1" = "--complete" ]; then
|
||||
echo --usage
|
||||
exec pyenv-commands
|
||||
exec rbenv-commands
|
||||
fi
|
||||
|
||||
command_path() {
|
||||
local command="$1"
|
||||
command -v pyenv-"$command" || command -v pyenv-sh-"$command" || true
|
||||
type -P rbenv-"$command" rbenv-sh-"$command" | head -n1
|
||||
}
|
||||
|
||||
extract_initial_comment_block() {
|
||||
LC_ALL= \
|
||||
LC_CTYPE=C \
|
||||
sed -ne "
|
||||
/^#/ !{
|
||||
q
|
||||
|
|
@ -44,9 +42,15 @@ extract_initial_comment_block() {
|
|||
}
|
||||
|
||||
collect_documentation() {
|
||||
# `tail` prevents "broken pipe" errors due to `head` closing the pipe without reading everything
|
||||
# https://superuser.com/questions/554855/how-can-i-fix-a-broken-pipe-error/642932#642932
|
||||
$(type -P gawk awk | tail -n +1 | head -n1) '
|
||||
local awk
|
||||
awk="$(type -P gawk)" || awk="$(type -P awk)" || true
|
||||
if [ -z "$awk" ]; then
|
||||
echo "rbenv: cannot find awk" >&2
|
||||
return 1
|
||||
fi
|
||||
|
||||
# shellcheck disable=SC2016
|
||||
"$awk" '
|
||||
/^Summary:/ {
|
||||
summary = substr($0, 10)
|
||||
next
|
||||
|
|
@ -123,7 +127,7 @@ print_help() {
|
|||
if [ -n "$usage" ]; then
|
||||
echo "$usage"
|
||||
else
|
||||
echo "Usage: pyenv ${command}"
|
||||
echo "Usage: rbenv ${command}"
|
||||
fi
|
||||
if [ -n "$help" ]; then
|
||||
echo
|
||||
|
|
@ -140,24 +144,62 @@ print_usage() {
|
|||
local command="$1"
|
||||
local summary usage help
|
||||
eval "$(documentation_for "$command")"
|
||||
[ -z "$usage" ] || echo "$usage"
|
||||
if [ -n "$usage" ]; then
|
||||
echo "$usage"
|
||||
else
|
||||
echo "Usage: rbenv ${command}"
|
||||
fi
|
||||
}
|
||||
|
||||
if [ "$1" = "--complete-commands" ]; then
|
||||
command_prefix="${2:-}"
|
||||
seen=()
|
||||
shopt -s nullglob
|
||||
PATH_remain="$PATH"
|
||||
# traverse PATH to find "rbenv-" prefixed commands
|
||||
while true; do
|
||||
path="${PATH_remain%%:*}"
|
||||
if [ -n "$path" ]; then
|
||||
for rbenv_command in "${path}/rbenv-"*; do
|
||||
command_name="${rbenv_command##*/}"
|
||||
command_name="${command_name#rbenv-}"
|
||||
command_name="${command_name#sh-}"
|
||||
[[ $command_name == "${command_prefix}"* ]] || continue
|
||||
[[ " ${seen[*]} " != *" ${command_name} "* ]] || continue
|
||||
seen+=("$command_name")
|
||||
summary=""
|
||||
eval "$(extract_initial_comment_block < "$rbenv_command" | collect_documentation)"
|
||||
[ -n "$summary" ] || continue
|
||||
printf "%s:%s\n" "$command_name" "$summary"
|
||||
done
|
||||
fi
|
||||
[[ $PATH_remain == *:* ]] || break
|
||||
PATH_remain="${PATH_remain#*:}"
|
||||
done
|
||||
exit 0
|
||||
fi
|
||||
|
||||
unset usage
|
||||
if [ "$1" = "--usage" ]; then
|
||||
usage="1"
|
||||
shift
|
||||
fi
|
||||
|
||||
if [ -z "$1" ] || [ "$1" == "pyenv" ]; then
|
||||
echo "Usage: pyenv <command> [<args>]"
|
||||
[ -z "$usage" ] || exit
|
||||
if [ -z "$1" ] || [ "$1" == "rbenv" ]; then
|
||||
if [ -z "$usage" ] && [ -t 1 ] && type -P man >/dev/null; then
|
||||
MANPATH="${BASH_SOURCE%/*}/../share/man:$MANPATH" exec man rbenv
|
||||
fi
|
||||
echo "Usage: rbenv <command> [<args>...]"
|
||||
[ -n "$usage" ] && exit
|
||||
echo
|
||||
echo "Some useful pyenv commands are:"
|
||||
print_summaries $(exec pyenv-commands | sort -u)
|
||||
echo "Commands to manage available Ruby versions:"
|
||||
print_summaries versions install uninstall rehash
|
||||
echo
|
||||
echo "See \`pyenv help <command>' for information on a specific command."
|
||||
echo "For full documentation, see: https://github.com/pyenv/pyenv#readme"
|
||||
echo "Commands to view or change the current Ruby version:"
|
||||
print_summaries version local global shell
|
||||
echo
|
||||
echo "See \`rbenv help <command>' for information on a specific command."
|
||||
echo "For full documentation, see: https://github.com/rbenv/rbenv#readme"
|
||||
else
|
||||
command="$1"
|
||||
if [ -n "$(command_path "$command")" ]; then
|
||||
|
|
@ -167,7 +209,7 @@ else
|
|||
print_help "$command"
|
||||
fi
|
||||
else
|
||||
echo "pyenv: no such command \`$command'" >&2
|
||||
echo "rbenv: no such command \`$command'" >&2
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
32
libexec/rbenv-hooks
Executable file
32
libexec/rbenv-hooks
Executable file
|
|
@ -0,0 +1,32 @@
|
|||
#!/usr/bin/env bash
|
||||
# Summary: List hook scripts for a given rbenv command
|
||||
# Usage: rbenv hooks <command>
|
||||
|
||||
set -e
|
||||
[ -n "$RBENV_DEBUG" ] && set -x
|
||||
|
||||
# Provide rbenv completions
|
||||
if [ "$1" = "--complete" ]; then
|
||||
echo exec
|
||||
echo rehash
|
||||
echo version-name
|
||||
echo version-origin
|
||||
echo which
|
||||
exit
|
||||
fi
|
||||
|
||||
RBENV_COMMAND="$1"
|
||||
if [ -z "$RBENV_COMMAND" ]; then
|
||||
rbenv-help --usage hooks >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
IFS=: read -r -a hook_paths <<<"$RBENV_HOOK_PATH"
|
||||
|
||||
shopt -s nullglob
|
||||
for path in "${hook_paths[@]}"; do
|
||||
for script in "$path/$RBENV_COMMAND"/*.bash; do
|
||||
echo "$script"
|
||||
done
|
||||
done
|
||||
shopt -u nullglob
|
||||
222
libexec/rbenv-init
Executable file
222
libexec/rbenv-init
Executable file
|
|
@ -0,0 +1,222 @@
|
|||
#!/usr/bin/env bash
|
||||
# Summary: Configure the shell environment for rbenv
|
||||
# Usage: rbenv init [<shells>...]
|
||||
# rbenv init - [--no-rehash] [<shell>]
|
||||
#
|
||||
# Modifies shell initialization files to bootstrap rbenv functionality.
|
||||
# Typically, this will add a line that eval's the output of `rbenv init -`.
|
||||
# If no shells are named by arguments, the current shell will be detected
|
||||
# by inspecting the parent process. If a shell is already configured for
|
||||
# rbenv, the init command does nothing and exits with zero status.
|
||||
#
|
||||
# In the `rbenv init -` mode, this outputs a script to be eval'd in the
|
||||
# current shell. Most importantly, that script prepends the rbenv shims
|
||||
# directory to the PATH environment variable. To aid interactive shells,
|
||||
# the script also installs the magic `rbenv()` shell function and loads
|
||||
# shell completions for rbenv commands.
|
||||
|
||||
set -e
|
||||
[ -n "$RBENV_DEBUG" ] && set -x
|
||||
|
||||
# Provide rbenv completions
|
||||
if [ "$1" = "--complete" ]; then
|
||||
echo -
|
||||
echo --no-rehash
|
||||
echo bash
|
||||
echo fish
|
||||
echo ksh
|
||||
echo zsh
|
||||
exit
|
||||
fi
|
||||
|
||||
print=""
|
||||
no_rehash=""
|
||||
shells=()
|
||||
while [ $# -gt 0 ]; do
|
||||
case "$1" in
|
||||
"-" )
|
||||
print=1
|
||||
;;
|
||||
"--no-rehash" )
|
||||
no_rehash=1
|
||||
;;
|
||||
* )
|
||||
shells+=("$1")
|
||||
;;
|
||||
esac
|
||||
shift
|
||||
done
|
||||
|
||||
if [ "${#shells[@]}" -eq 0 ]; then
|
||||
shell="$(ps -p "$PPID" -o 'args=' 2>/dev/null || true)"
|
||||
shell="${shell%% *}"
|
||||
shell="${shell##-}"
|
||||
shell="${shell:-$SHELL}"
|
||||
shell="${shell##*/}"
|
||||
shells=("${shell%%-*}")
|
||||
fi
|
||||
|
||||
root="${BASH_SOURCE:-$0}"
|
||||
root="${root%/*}"
|
||||
root="${root%/*}"
|
||||
|
||||
rbenv_in_path=true
|
||||
if [ -n "$RBENV_ORIG_PATH" ]; then
|
||||
PATH="$RBENV_ORIG_PATH" type -P rbenv >/dev/null || rbenv_in_path=""
|
||||
fi
|
||||
|
||||
if [ -z "$print" ]; then
|
||||
display_path() {
|
||||
if [ "${1/#$HOME\/}" != "$1" ]; then
|
||||
# shellcheck disable=SC2088
|
||||
printf '~/%s' "${1/#$HOME\/}"
|
||||
else
|
||||
printf '%s' "$1"
|
||||
fi
|
||||
}
|
||||
|
||||
rbenv_command=rbenv
|
||||
if [ -z "$rbenv_in_path" ]; then
|
||||
rbenv_command="$(display_path "$root/bin/rbenv")"
|
||||
fi
|
||||
|
||||
color_start=""
|
||||
color_end=""
|
||||
if [ -t 1 ]; then
|
||||
color_start=$'\e[33;1m'
|
||||
color_end=$'\e[m'
|
||||
fi
|
||||
|
||||
write_config() {
|
||||
if grep -q "rbenv init" "$1" 2>/dev/null; then
|
||||
printf 'skipping %s%s%s: already configured for rbenv.\n' "$color_start" "$(display_path "$1")" "$color_end"
|
||||
return 0
|
||||
fi
|
||||
mkdir -p "${1%/*}"
|
||||
# shellcheck disable=SC2016
|
||||
printf '\n# Added by `rbenv init` on %s\n%s\n' "$(date)" "$2" >> "$1"
|
||||
printf 'writing %s%s%s: now configured for rbenv.\n' "$color_start" "$(display_path "$1")" "$color_end"
|
||||
}
|
||||
|
||||
status=0
|
||||
for shell in "${shells[@]}"; do
|
||||
case "$shell" in
|
||||
bash )
|
||||
if [ -f ~/.bashrc ] && [ ! -f ~/.bash_profile ]; then
|
||||
profile="$HOME/.bashrc"
|
||||
else
|
||||
# shellcheck disable=SC2012
|
||||
profile="$(ls ~/.bash_profile ~/.bash_login ~/.profile 2>/dev/null | head -n1)"
|
||||
[ -n "$profile" ] || profile="$HOME/.bash_profile"
|
||||
fi
|
||||
write_config "$profile" \
|
||||
"eval \"\$($rbenv_command init - --no-rehash bash)\""
|
||||
;;
|
||||
zsh )
|
||||
# check zshrc for backward compatibility with older rbenv init
|
||||
if grep -q rbenv "${ZDOTDIR:-$HOME}/.zshrc" 2>/dev/null; then
|
||||
profile="${ZDOTDIR:-$HOME}/.zshrc"
|
||||
else
|
||||
profile="${ZDOTDIR:-$HOME}/.zprofile"
|
||||
fi
|
||||
write_config "$profile" \
|
||||
"eval \"\$($rbenv_command init - --no-rehash zsh)\""
|
||||
;;
|
||||
ksh | ksh93 | mksh )
|
||||
# There are two implementations of Korn shell: AT&T (ksh93) and Mir (mksh).
|
||||
# Systems may have them installed under those names, or as ksh, so those
|
||||
# are recognized here. The obsolete ksh88 (subsumed by ksh93) and pdksh
|
||||
# (subsumed by mksh) are not included, since they are unlikely to still
|
||||
# be in use as interactive shells anywhere.
|
||||
write_config "$HOME/.profile" \
|
||||
"eval \"\$($rbenv_command init - ksh)\""
|
||||
;;
|
||||
fish )
|
||||
write_config "${XDG_CONFIG_HOME:-$HOME/.config}/fish/config.fish" \
|
||||
"status --is-interactive; and $rbenv_command init - --no-rehash fish | source"
|
||||
;;
|
||||
* )
|
||||
printf 'unsupported shell: "%s"\n' "$shell" >&2
|
||||
status=1
|
||||
;;
|
||||
esac
|
||||
done
|
||||
exit $status
|
||||
fi
|
||||
|
||||
mkdir -p "${RBENV_ROOT}/"{shims,versions}
|
||||
|
||||
shell="${shells[0]}"
|
||||
case "$shell" in
|
||||
fish )
|
||||
[ -n "$rbenv_in_path" ] || printf "set -gx PATH '%s/bin' \$PATH\n" "$root"
|
||||
printf "set -gx PATH '%s/shims' \$PATH\n" "$RBENV_ROOT"
|
||||
printf 'set -gx RBENV_SHELL %s\n' "$shell"
|
||||
;;
|
||||
* )
|
||||
# shellcheck disable=SC2016
|
||||
[ -n "$rbenv_in_path" ] || printf 'export PATH="%s/bin:${PATH}"\n' "$root"
|
||||
# shellcheck disable=SC2016
|
||||
printf 'export PATH="%s/shims:${PATH}"\n' "$RBENV_ROOT"
|
||||
printf 'export RBENV_SHELL=%s\n' "$shell"
|
||||
|
||||
completion="${root}/completions/rbenv.${shell}"
|
||||
if [ -r "$completion" ]; then
|
||||
printf "source '%s'\n" "$completion"
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
|
||||
if [ -z "$no_rehash" ]; then
|
||||
echo 'command rbenv rehash 2>/dev/null'
|
||||
fi
|
||||
|
||||
IFS=$'\n' read -d '' -r -a commands <<<"$(rbenv-commands --sh)" || true
|
||||
|
||||
case "$shell" in
|
||||
fish )
|
||||
cat <<EOS
|
||||
function rbenv
|
||||
set command \$argv[1]
|
||||
set -e argv[1]
|
||||
|
||||
switch "\$command"
|
||||
case ${commands[*]}
|
||||
rbenv "sh-\$command" \$argv|source
|
||||
case '*'
|
||||
command rbenv "\$command" \$argv
|
||||
end
|
||||
end
|
||||
EOS
|
||||
;;
|
||||
ksh | ksh93 | mksh )
|
||||
cat <<EOS
|
||||
function rbenv {
|
||||
typeset command
|
||||
EOS
|
||||
;;
|
||||
* )
|
||||
cat <<EOS
|
||||
rbenv() {
|
||||
local command
|
||||
EOS
|
||||
;;
|
||||
esac
|
||||
|
||||
if [ "$shell" != "fish" ]; then
|
||||
IFS="|"
|
||||
cat <<EOS
|
||||
command="\${1:-}"
|
||||
if [ "\$#" -gt 0 ]; then
|
||||
shift
|
||||
fi
|
||||
|
||||
case "\$command" in
|
||||
${commands[*]})
|
||||
eval "\$(rbenv "sh-\$command" "\$@")";;
|
||||
*)
|
||||
command rbenv "\$command" "\$@";;
|
||||
esac
|
||||
}
|
||||
EOS
|
||||
fi
|
||||
45
libexec/rbenv-local
Executable file
45
libexec/rbenv-local
Executable file
|
|
@ -0,0 +1,45 @@
|
|||
#!/usr/bin/env bash
|
||||
#
|
||||
# Summary: Set or show the local application-specific Ruby version
|
||||
#
|
||||
# Usage: rbenv local <version>
|
||||
# rbenv local --unset
|
||||
#
|
||||
# Sets the local application-specific Ruby version by writing the
|
||||
# version name to a file named `.ruby-version'.
|
||||
#
|
||||
# When you run a Ruby command, rbenv will look for a `.ruby-version'
|
||||
# file in the current directory and each parent directory. If no such
|
||||
# file is found in the tree, rbenv will use the global Ruby version
|
||||
# specified with `rbenv global'. A version specified with the
|
||||
# `RBENV_VERSION' environment variable takes precedence over local
|
||||
# and global versions.
|
||||
#
|
||||
# <version> should be a string matching a Ruby version known to rbenv.
|
||||
# The special version string `system' will use your default system Ruby.
|
||||
# Run `rbenv versions' for a list of available Ruby versions.
|
||||
|
||||
set -e
|
||||
[ -n "$RBENV_DEBUG" ] && set -x
|
||||
|
||||
# Provide rbenv completions
|
||||
if [ "$1" = "--complete" ]; then
|
||||
echo --unset
|
||||
echo system
|
||||
exec rbenv-versions --bare
|
||||
fi
|
||||
|
||||
RBENV_VERSION="$1"
|
||||
|
||||
if [ "$RBENV_VERSION" = "--unset" ]; then
|
||||
rm -f .ruby-version
|
||||
elif [ -n "$RBENV_VERSION" ]; then
|
||||
rbenv-version-file-write .ruby-version "$RBENV_VERSION"
|
||||
else
|
||||
if version_file="$(rbenv-version-file "$PWD")"; then
|
||||
rbenv-version-file-read "$version_file"
|
||||
else
|
||||
echo "rbenv: no local version configured for this directory" >&2
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
42
libexec/rbenv-prefix
Executable file
42
libexec/rbenv-prefix
Executable file
|
|
@ -0,0 +1,42 @@
|
|||
#!/usr/bin/env bash
|
||||
# Summary: Display prefix for a Ruby version
|
||||
# Usage: rbenv prefix [<version>]
|
||||
#
|
||||
# Displays the directory where a Ruby version is installed. If no
|
||||
# version is given, `rbenv prefix' displays the location of the
|
||||
# currently selected version.
|
||||
|
||||
set -e
|
||||
[ -n "$RBENV_DEBUG" ] && set -x
|
||||
|
||||
# Provide rbenv completions
|
||||
if [ "$1" = "--complete" ]; then
|
||||
echo system
|
||||
exec rbenv-versions --bare
|
||||
fi
|
||||
|
||||
if [ -n "$1" ]; then
|
||||
export RBENV_VERSION="$1"
|
||||
elif [ -z "$RBENV_VERSION" ]; then
|
||||
RBENV_VERSION="$(rbenv-version-name)"
|
||||
fi
|
||||
|
||||
if [ "$RBENV_VERSION" = "system" ]; then
|
||||
if RUBY_PATH="$(rbenv-which ruby)"; then
|
||||
RUBY_PATH="${RUBY_PATH%/*}"
|
||||
RBENV_PREFIX_PATH="${RUBY_PATH%/bin}"
|
||||
echo "${RBENV_PREFIX_PATH:-/}"
|
||||
exit
|
||||
else
|
||||
echo "rbenv: system version not found in PATH" >&2
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
RBENV_PREFIX_PATH="${RBENV_ROOT}/versions/${RBENV_VERSION}"
|
||||
if [ ! -d "$RBENV_PREFIX_PATH" ]; then
|
||||
echo "rbenv: version \`${RBENV_VERSION}' not installed" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "$RBENV_PREFIX_PATH"
|
||||
180
libexec/rbenv-rehash
Executable file
180
libexec/rbenv-rehash
Executable file
|
|
@ -0,0 +1,180 @@
|
|||
#!/usr/bin/env bash
|
||||
# Summary: Regenerate rbenv shims
|
||||
#
|
||||
# Regenerate shims for every Ruby executable in `$RBENV_ROOT/versions/*/bin'
|
||||
# and write them to the `$RBENV_ROOT/shims' directory. A shell environment
|
||||
# properly set up for rbenv will have this shims directory in PATH, which is
|
||||
# the core mechanism for Ruby version switching.
|
||||
#
|
||||
# Running rbenv rehash should only be necessary after installing new Ruby
|
||||
# versions or gems. Note that this is sometimes done automatically: the
|
||||
# `rbenv install' command from the ruby-build plugin runs rehash after
|
||||
# every successful installation, and a RubyGems plugin that ships with
|
||||
# rbenv runs rehash after every `gem install' command.
|
||||
|
||||
set -e
|
||||
[ -n "$RBENV_DEBUG" ] && set -x
|
||||
|
||||
SHIM_PATH="${RBENV_ROOT}/shims"
|
||||
PROTOTYPE_SHIM_PATH="${SHIM_PATH}/.rbenv-shim"
|
||||
|
||||
# Create the shims directory if it doesn't already exist.
|
||||
mkdir -p "$SHIM_PATH"
|
||||
|
||||
# Ensure only one instance of rbenv-rehash is running at a time by
|
||||
# setting the shell's `noclobber` option and attempting to write to
|
||||
# the prototype shim file. If the file already exists, print a warning
|
||||
# to stderr and exit with a non-zero status.
|
||||
set -o noclobber
|
||||
{ echo > "$PROTOTYPE_SHIM_PATH"
|
||||
} 2>| /dev/null ||
|
||||
{ if [ -w "$SHIM_PATH" ]; then
|
||||
echo "rbenv: cannot rehash: $PROTOTYPE_SHIM_PATH exists"
|
||||
else
|
||||
echo "rbenv: cannot rehash: $SHIM_PATH isn't writable"
|
||||
fi
|
||||
exit 1
|
||||
} >&2
|
||||
set +o noclobber
|
||||
|
||||
# If we were able to obtain a lock, register a trap to clean up the
|
||||
# prototype shim when the process exits.
|
||||
trap remove_prototype_shim EXIT
|
||||
|
||||
remove_prototype_shim() {
|
||||
rm -f "$PROTOTYPE_SHIM_PATH"
|
||||
}
|
||||
|
||||
# Locates rbenv as found in the user's PATH. Otherwise, returns an
|
||||
# absolute path to the rbenv executable itself.
|
||||
rbenv_path() {
|
||||
local found
|
||||
found="$(PATH="$RBENV_ORIG_PATH" type -P rbenv)"
|
||||
if [[ $found == /* ]]; then
|
||||
echo "$found"
|
||||
elif [[ -n "$found" ]]; then
|
||||
echo "$PWD/${found#./}"
|
||||
else
|
||||
# Assume rbenv isn't in PATH.
|
||||
echo "${BASH_SOURCE%/*}/rbenv"
|
||||
fi
|
||||
}
|
||||
|
||||
# The prototype shim file is a script that re-execs itself, passing
|
||||
# its filename and any arguments to `rbenv exec`. This file is
|
||||
# hard-linked for every executable and then removed. The linking
|
||||
# technique is fast, uses less disk space than unique files, and also
|
||||
# serves as a locking mechanism.
|
||||
create_prototype_shim() {
|
||||
cat > "$PROTOTYPE_SHIM_PATH" <<SH
|
||||
#!/usr/bin/env bash
|
||||
set -e
|
||||
[ -n "\$RBENV_DEBUG" ] && set -x
|
||||
|
||||
program="\${0##*/}"
|
||||
if [ "\$program" = "ruby" ]; then
|
||||
for arg; do
|
||||
case "\$arg" in
|
||||
-e* | -- ) break ;;
|
||||
*/* )
|
||||
if [ -f "\$arg" ]; then
|
||||
export RBENV_DIR="\${arg%/*}"
|
||||
break
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
done
|
||||
fi
|
||||
|
||||
export RBENV_ROOT="$RBENV_ROOT"
|
||||
exec "$(rbenv_path)" exec "\$program" "\$@"
|
||||
SH
|
||||
chmod +x "$PROTOTYPE_SHIM_PATH"
|
||||
}
|
||||
|
||||
# If the contents of the prototype shim file differ from the contents
|
||||
# of the first shim in the shims directory, assume rbenv has been
|
||||
# upgraded and the existing shims need to be removed.
|
||||
remove_outdated_shims() {
|
||||
local shim
|
||||
for shim in "$SHIM_PATH"/*; do
|
||||
if ! diff "$PROTOTYPE_SHIM_PATH" "$shim" >/dev/null 2>&1; then
|
||||
rm -f "$SHIM_PATH"/*
|
||||
fi
|
||||
break
|
||||
done
|
||||
}
|
||||
|
||||
# List basenames of executables for every Ruby version
|
||||
list_executable_names() {
|
||||
local version file
|
||||
rbenv-versions --bare --skip-aliases | \
|
||||
while read -r version; do
|
||||
for file in "${RBENV_ROOT}/versions/${version}/bin/"*; do
|
||||
echo "${file##*/}"
|
||||
done
|
||||
done
|
||||
if [ -n "$GEM_HOME" ]; then
|
||||
for file in "$GEM_HOME"/bin/*; do
|
||||
echo "${file##*/}"
|
||||
done
|
||||
fi
|
||||
}
|
||||
|
||||
# The basename of each argument passed to `make_shims` will be
|
||||
# registered for installation as a shim. In this way, plugins may call
|
||||
# `make_shims` with a glob to register many shims at once.
|
||||
make_shims() {
|
||||
local file shim
|
||||
for file; do
|
||||
shim="${file##*/}"
|
||||
registered_shims+=("$shim")
|
||||
done
|
||||
}
|
||||
|
||||
# Registers the name of a shim to be generated.
|
||||
register_shim() {
|
||||
registered_shims+=("$1")
|
||||
}
|
||||
|
||||
# Install all the shims registered via `make_shims` or `register_shim` directly.
|
||||
install_registered_shims() {
|
||||
local shim file
|
||||
for shim in "${registered_shims[@]}"; do
|
||||
file="${SHIM_PATH}/${shim}"
|
||||
[ -e "$file" ] || cp "$PROTOTYPE_SHIM_PATH" "$file"
|
||||
done
|
||||
}
|
||||
|
||||
# Once the registered shims have been installed, we make a second pass
|
||||
# over the contents of the shims directory. Any file that is present
|
||||
# in the directory but has not been registered as a shim should be
|
||||
# removed.
|
||||
remove_stale_shims() {
|
||||
local shim
|
||||
local known_shims=" ${registered_shims[*]} "
|
||||
for shim in "$SHIM_PATH"/*; do
|
||||
if [[ "$known_shims" != *" ${shim##*/} "* ]]; then
|
||||
rm -f "$shim"
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
shopt -s nullglob
|
||||
|
||||
# Create the prototype shim, then register shims for all known
|
||||
# executables.
|
||||
create_prototype_shim
|
||||
remove_outdated_shims
|
||||
# shellcheck disable=SC2207
|
||||
registered_shims=( $(list_executable_names | sort -u) )
|
||||
|
||||
# Allow plugins to register shims.
|
||||
IFS=$'\n' read -d '' -r -a scripts <<<"$(rbenv-hooks rehash)" || true
|
||||
for script in "${scripts[@]}"; do
|
||||
# shellcheck disable=SC1090
|
||||
source "$script"
|
||||
done
|
||||
|
||||
install_registered_shims
|
||||
remove_stale_shims
|
||||
|
|
@ -1,3 +1,3 @@
|
|||
#!/usr/bin/env bash
|
||||
# Summary: Display the root directory where versions and shims are kept
|
||||
echo "$PYENV_ROOT"
|
||||
echo "$RBENV_ROOT"
|
||||
23
libexec/rbenv-sh-rehash
Executable file
23
libexec/rbenv-sh-rehash
Executable file
|
|
@ -0,0 +1,23 @@
|
|||
#!/usr/bin/env bash
|
||||
set -e
|
||||
[ -n "$RBENV_DEBUG" ] && set -x
|
||||
|
||||
# Provide rbenv completions
|
||||
if [ "$1" = "--complete" ]; then
|
||||
exec rbenv-rehash --complete
|
||||
fi
|
||||
|
||||
shell="$(basename "${RBENV_SHELL:-$SHELL}")"
|
||||
|
||||
# When rbenv shell integration is enabled, delegate to rbenv-rehash,
|
||||
# then tell the shell to empty its command lookup cache.
|
||||
rbenv-rehash
|
||||
|
||||
case "$shell" in
|
||||
fish )
|
||||
# no rehash support
|
||||
;;
|
||||
* )
|
||||
echo "hash -r 2>/dev/null || true"
|
||||
;;
|
||||
esac
|
||||
144
libexec/rbenv-sh-shell
Executable file
144
libexec/rbenv-sh-shell
Executable file
|
|
@ -0,0 +1,144 @@
|
|||
#!/usr/bin/env bash
|
||||
#
|
||||
# Summary: Set or show the shell-specific Ruby version
|
||||
#
|
||||
# Usage: rbenv shell <version>
|
||||
# rbenv shell -
|
||||
# rbenv shell --unset
|
||||
#
|
||||
# Sets a shell-specific Ruby version by setting the `RBENV_VERSION'
|
||||
# environment variable in your shell. This version overrides local
|
||||
# application-specific versions and the global version.
|
||||
#
|
||||
# <version> should be a string matching a Ruby version known to rbenv.
|
||||
# The special version string `system' will use your default system Ruby.
|
||||
# Run `rbenv versions' for a list of available Ruby versions.
|
||||
#
|
||||
# When `-` is passed instead of the version string, the previously set
|
||||
# version will be restored. With `--unset`, the `RBENV_VERSION`
|
||||
# environment variable gets unset, restoring the environment to the
|
||||
# state before the first `rbenv shell` call.
|
||||
|
||||
set -e
|
||||
[ -n "$RBENV_DEBUG" ] && set -x
|
||||
|
||||
# Provide rbenv completions
|
||||
if [ "$1" = "--complete" ]; then
|
||||
echo --unset
|
||||
echo system
|
||||
exec rbenv-versions --bare
|
||||
fi
|
||||
|
||||
version="$1"
|
||||
shell="$(basename "${RBENV_SHELL:-$SHELL}")"
|
||||
|
||||
if [ -z "$version" ]; then
|
||||
if [ -z "$RBENV_VERSION" ]; then
|
||||
echo "rbenv: no shell-specific version configured" >&2
|
||||
exit 1
|
||||
else
|
||||
echo 'echo "$RBENV_VERSION"'
|
||||
exit
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ "$version" = "--unset" ]; then
|
||||
case "$shell" in
|
||||
fish )
|
||||
echo 'set -gu RBENV_VERSION_OLD "$RBENV_VERSION"'
|
||||
echo "set -e RBENV_VERSION"
|
||||
;;
|
||||
zsh )
|
||||
echo "typeset -g RBENV_VERSION_OLD=\"\${RBENV_VERSION-}\""
|
||||
echo "unset RBENV_VERSION"
|
||||
;;
|
||||
* )
|
||||
echo 'RBENV_VERSION_OLD="${RBENV_VERSION-}"'
|
||||
echo "unset RBENV_VERSION"
|
||||
;;
|
||||
esac
|
||||
exit
|
||||
fi
|
||||
|
||||
if [ "$version" = "-" ]; then
|
||||
case "$shell" in
|
||||
fish )
|
||||
cat <<EOS
|
||||
if set -q RBENV_VERSION_OLD
|
||||
if [ -n "\$RBENV_VERSION_OLD" ]
|
||||
set RBENV_VERSION_OLD_ "\$RBENV_VERSION"
|
||||
set -gx RBENV_VERSION "\$RBENV_VERSION_OLD"
|
||||
set -gu RBENV_VERSION_OLD "\$RBENV_VERSION_OLD_"
|
||||
set -e RBENV_VERSION_OLD_
|
||||
else
|
||||
set -gu RBENV_VERSION_OLD "\$RBENV_VERSION"
|
||||
set -e RBENV_VERSION
|
||||
end
|
||||
else
|
||||
echo "rbenv: RBENV_VERSION_OLD is not set" >&2
|
||||
false
|
||||
end
|
||||
EOS
|
||||
;;
|
||||
zsh )
|
||||
cat <<EOS
|
||||
if [ -n "\${RBENV_VERSION_OLD+x}" ]; then
|
||||
if [ -n "\$RBENV_VERSION_OLD" ]; then
|
||||
local RBENV_VERSION_OLD_="\$RBENV_VERSION"
|
||||
export RBENV_VERSION="\$RBENV_VERSION_OLD"
|
||||
RBENV_VERSION_OLD="\$RBENV_VERSION_OLD_"
|
||||
unset RBENV_VERSION_OLD_
|
||||
else
|
||||
typeset -g RBENV_VERSION_OLD="\$RBENV_VERSION"
|
||||
unset RBENV_VERSION
|
||||
fi
|
||||
else
|
||||
echo "rbenv: RBENV_VERSION_OLD is not set" >&2
|
||||
false
|
||||
fi
|
||||
EOS
|
||||
;;
|
||||
* )
|
||||
cat <<EOS
|
||||
if [ -n "\${RBENV_VERSION_OLD+x}" ]; then
|
||||
if [ -n "\$RBENV_VERSION_OLD" ]; then
|
||||
RBENV_VERSION_OLD_="\$RBENV_VERSION"
|
||||
export RBENV_VERSION="\$RBENV_VERSION_OLD"
|
||||
RBENV_VERSION_OLD="\$RBENV_VERSION_OLD_"
|
||||
unset RBENV_VERSION_OLD_
|
||||
else
|
||||
RBENV_VERSION_OLD="\$RBENV_VERSION"
|
||||
unset RBENV_VERSION
|
||||
fi
|
||||
else
|
||||
echo "rbenv: RBENV_VERSION_OLD is not set" >&2
|
||||
false
|
||||
fi
|
||||
EOS
|
||||
;;
|
||||
esac
|
||||
exit
|
||||
fi
|
||||
|
||||
# Make sure the specified version is installed.
|
||||
if rbenv-prefix "$version" >/dev/null; then
|
||||
if [ "$version" != "$RBENV_VERSION" ]; then
|
||||
case "$shell" in
|
||||
fish )
|
||||
echo 'set -gu RBENV_VERSION_OLD "$RBENV_VERSION"'
|
||||
echo "set -gx RBENV_VERSION \"$version\""
|
||||
;;
|
||||
zsh )
|
||||
echo "typeset -g RBENV_VERSION_OLD=\"\${RBENV_VERSION-}\""
|
||||
echo "export RBENV_VERSION=\"$version\""
|
||||
;;
|
||||
* )
|
||||
echo 'RBENV_VERSION_OLD="${RBENV_VERSION-}"'
|
||||
echo "export RBENV_VERSION=\"$version\""
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
else
|
||||
echo "false"
|
||||
exit 1
|
||||
fi
|
||||
|
|
@ -1,11 +1,11 @@
|
|||
#!/usr/bin/env bash
|
||||
# Summary: List existing pyenv shims
|
||||
# Usage: pyenv shims [--short]
|
||||
# Summary: List existing rbenv shims
|
||||
# Usage: rbenv shims [--short]
|
||||
|
||||
set -e
|
||||
[ -n "$PYENV_DEBUG" ] && set -x
|
||||
[ -n "$RBENV_DEBUG" ] && set -x
|
||||
|
||||
# Provide pyenv completions
|
||||
# Provide rbenv completions
|
||||
if [ "$1" = "--complete" ]; then
|
||||
echo --short
|
||||
exit
|
||||
|
|
@ -13,7 +13,7 @@ fi
|
|||
|
||||
shopt -s nullglob
|
||||
|
||||
for command in "${PYENV_ROOT}/shims/"*; do
|
||||
for command in "${RBENV_ROOT}/shims/"*; do
|
||||
if [ "$1" = "--short" ]; then
|
||||
echo "${command##*/}"
|
||||
else
|
||||
18
libexec/rbenv-version
Executable file
18
libexec/rbenv-version
Executable file
|
|
@ -0,0 +1,18 @@
|
|||
#!/usr/bin/env bash
|
||||
# Summary: Show the current Ruby version and its origin
|
||||
#
|
||||
# Shows the currently selected Ruby version and how it was
|
||||
# selected. To obtain only the version string, use `rbenv
|
||||
# version-name'.
|
||||
|
||||
set -e
|
||||
[ -n "$RBENV_DEBUG" ] && set -x
|
||||
|
||||
version_name="$(rbenv-version-name)"
|
||||
version_origin="$(rbenv-version-origin)"
|
||||
|
||||
if [ "$version_origin" = "${RBENV_ROOT}/version" ] && [ ! -e "$version_origin" ]; then
|
||||
echo "$version_name"
|
||||
else
|
||||
echo "$version_name (set by $version_origin)"
|
||||
fi
|
||||
34
libexec/rbenv-version-file
Executable file
34
libexec/rbenv-version-file
Executable file
|
|
@ -0,0 +1,34 @@
|
|||
#!/usr/bin/env bash
|
||||
# Usage: rbenv version-file [<dir>]
|
||||
# Summary: Detect the file that sets the current rbenv version
|
||||
#
|
||||
# Detects and prints the location of a `.ruby-version` file that sets the
|
||||
# version for the current working directory. If no file found, this prints
|
||||
# the location of the global version file, even if that file does
|
||||
# not exist.
|
||||
|
||||
set -e
|
||||
[ -n "$RBENV_DEBUG" ] && set -x
|
||||
|
||||
target_dir="$1"
|
||||
|
||||
find_local_version_file() {
|
||||
local root="$1"
|
||||
while ! [[ "$root" =~ ^//[^/]*$ ]]; do
|
||||
if [ -s "${root}/.ruby-version" ]; then
|
||||
echo "${root}/.ruby-version"
|
||||
return 0
|
||||
fi
|
||||
[ -n "$root" ] || break
|
||||
root="${root%/*}"
|
||||
done
|
||||
return 1
|
||||
}
|
||||
|
||||
if [ -n "$target_dir" ]; then
|
||||
find_local_version_file "$target_dir"
|
||||
else
|
||||
find_local_version_file "$RBENV_DIR" || {
|
||||
[ "$RBENV_DIR" != "$PWD" ] && find_local_version_file "$PWD"
|
||||
} || echo "${RBENV_ROOT}/version"
|
||||
fi
|
||||
21
libexec/rbenv-version-file-read
Executable file
21
libexec/rbenv-version-file-read
Executable file
|
|
@ -0,0 +1,21 @@
|
|||
#!/usr/bin/env bash
|
||||
# Usage: rbenv version-file-read <file>
|
||||
set -e
|
||||
[ -n "$RBENV_DEBUG" ] && set -x
|
||||
|
||||
VERSION_FILE="$1"
|
||||
|
||||
if [ -s "$VERSION_FILE" ]; then
|
||||
# Read the first word from the specified version file. Avoid reading it whole.
|
||||
IFS="${IFS}"$'\r'
|
||||
read -n 1024 -d "" -r version _ <"$VERSION_FILE" || :
|
||||
|
||||
if [ "$version" = ".." ] || [[ $version == */* ]]; then
|
||||
echo "rbenv: invalid version in \`$VERSION_FILE'" >&2
|
||||
elif [ -n "$version" ]; then
|
||||
echo "$version"
|
||||
exit
|
||||
fi
|
||||
fi
|
||||
|
||||
exit 1
|
||||
19
libexec/rbenv-version-file-write
Executable file
19
libexec/rbenv-version-file-write
Executable file
|
|
@ -0,0 +1,19 @@
|
|||
#!/usr/bin/env bash
|
||||
# Usage: rbenv version-file-write <file> <version>
|
||||
|
||||
set -e
|
||||
[ -n "$RBENV_DEBUG" ] && set -x
|
||||
|
||||
RBENV_VERSION_FILE="$1"
|
||||
RBENV_VERSION="$2"
|
||||
|
||||
if [ -z "$RBENV_VERSION" ] || [ -z "$RBENV_VERSION_FILE" ]; then
|
||||
rbenv-help --usage version-file-write >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Make sure the specified version is installed.
|
||||
rbenv-prefix "$RBENV_VERSION" >/dev/null
|
||||
|
||||
# Write the version out to disk.
|
||||
echo "$RBENV_VERSION" > "$RBENV_VERSION_FILE"
|
||||
34
libexec/rbenv-version-name
Executable file
34
libexec/rbenv-version-name
Executable file
|
|
@ -0,0 +1,34 @@
|
|||
#!/usr/bin/env bash
|
||||
# Summary: Show the current Ruby version
|
||||
set -e
|
||||
[ -n "$RBENV_DEBUG" ] && set -x
|
||||
|
||||
if [ -z "$RBENV_VERSION" ]; then
|
||||
RBENV_VERSION_FILE="$(rbenv-version-file)"
|
||||
RBENV_VERSION="$(rbenv-version-file-read "$RBENV_VERSION_FILE" || true)"
|
||||
fi
|
||||
|
||||
IFS=$'\n' read -d '' -r -a scripts <<<"$(rbenv-hooks version-name)" || true
|
||||
for script in "${scripts[@]}"; do
|
||||
# shellcheck disable=SC1090
|
||||
source "$script"
|
||||
done
|
||||
|
||||
if [ -z "$RBENV_VERSION" ] || [ "$RBENV_VERSION" = "system" ]; then
|
||||
echo "system"
|
||||
exit
|
||||
fi
|
||||
|
||||
version_exists() {
|
||||
local version="$1"
|
||||
[ -d "${RBENV_ROOT}/versions/${version}" ]
|
||||
}
|
||||
|
||||
if version_exists "$RBENV_VERSION"; then
|
||||
echo "$RBENV_VERSION"
|
||||
elif version_exists "${RBENV_VERSION#ruby-}"; then
|
||||
echo "${RBENV_VERSION#ruby-}"
|
||||
else
|
||||
echo "rbenv: version \`$RBENV_VERSION' is not installed (set by $(rbenv-version-origin))" >&2
|
||||
exit 1
|
||||
fi
|
||||
20
libexec/rbenv-version-origin
Executable file
20
libexec/rbenv-version-origin
Executable file
|
|
@ -0,0 +1,20 @@
|
|||
#!/usr/bin/env bash
|
||||
# Summary: Explain how the current Ruby version is set
|
||||
set -e
|
||||
[ -n "$RBENV_DEBUG" ] && set -x
|
||||
|
||||
unset RBENV_VERSION_ORIGIN
|
||||
|
||||
IFS=$'\n' read -d '' -r -a scripts <<<"$(rbenv-hooks version-origin)" || true
|
||||
for script in "${scripts[@]}"; do
|
||||
# shellcheck disable=SC1090
|
||||
source "$script"
|
||||
done
|
||||
|
||||
if [ -n "$RBENV_VERSION_ORIGIN" ]; then
|
||||
echo "$RBENV_VERSION_ORIGIN"
|
||||
elif [ -n "$RBENV_VERSION" ]; then
|
||||
echo "RBENV_VERSION environment variable"
|
||||
else
|
||||
rbenv-version-file
|
||||
fi
|
||||
83
libexec/rbenv-versions
Executable file
83
libexec/rbenv-versions
Executable file
|
|
@ -0,0 +1,83 @@
|
|||
#!/usr/bin/env bash
|
||||
# Summary: List installed Ruby versions
|
||||
# Usage: rbenv versions [--bare] [--skip-aliases]
|
||||
#
|
||||
# Lists all Ruby versions found in `$RBENV_ROOT/versions/*'.
|
||||
|
||||
set -e
|
||||
[ -n "$RBENV_DEBUG" ] && set -x
|
||||
|
||||
unset bare
|
||||
unset skip_aliases
|
||||
# Provide rbenv completions
|
||||
for arg; do
|
||||
case "$arg" in
|
||||
--complete )
|
||||
echo --bare
|
||||
echo --skip-aliases
|
||||
exit ;;
|
||||
--bare ) bare=1 ;;
|
||||
--skip-aliases ) skip_aliases=1 ;;
|
||||
* )
|
||||
rbenv-help --usage versions >&2
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
canonicalize_dir() {
|
||||
{ cd "$1" && pwd -P
|
||||
} 2>/dev/null || echo "$1"
|
||||
}
|
||||
|
||||
versions_dir="${RBENV_ROOT}/versions"
|
||||
if [ -n "$skip_aliases" ]; then
|
||||
versions_dir="$(canonicalize_dir "$versions_dir")"
|
||||
fi
|
||||
|
||||
list_versions() {
|
||||
local path
|
||||
local target
|
||||
shopt -s nullglob
|
||||
for path in "$versions_dir"/*; do
|
||||
if [ -d "$path" ]; then
|
||||
if [ -n "$skip_aliases" ] && [ -L "$path" ]; then
|
||||
target="$(canonicalize_dir "$path")"
|
||||
[ "${target%/*}" != "$versions_dir" ] || continue
|
||||
fi
|
||||
echo "${path##*/}"
|
||||
fi
|
||||
done
|
||||
shopt -u nullglob
|
||||
}
|
||||
|
||||
if [ -n "$bare" ]; then
|
||||
list_versions
|
||||
exit 0
|
||||
fi
|
||||
|
||||
sort_versions() {
|
||||
sed 'h; s/[+-]/./g; s/.p\([[:digit:]]\)/.z.\1/; s/$/.z/; G; s/\n/ /' | \
|
||||
LC_ALL=C sort -t. -k 1,1 -k 2,2n -k 3,3n -k 4,4n -k 5,5n | awk '{print $2}'
|
||||
}
|
||||
|
||||
versions="$(
|
||||
if RBENV_VERSION=system rbenv-which ruby >/dev/null 2>&1; then
|
||||
echo system
|
||||
fi
|
||||
list_versions | sort_versions
|
||||
)"
|
||||
|
||||
if [ -z "$versions" ]; then
|
||||
echo "Warning: no Ruby detected on the system" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
current_version="$(rbenv-version-name || true)"
|
||||
while read -r version; do
|
||||
if [ "$version" == "$current_version" ]; then
|
||||
echo "* $(rbenv-version 2>/dev/null)"
|
||||
else
|
||||
echo " $version"
|
||||
fi
|
||||
done <<<"$versions"
|
||||
38
libexec/rbenv-whence
Executable file
38
libexec/rbenv-whence
Executable file
|
|
@ -0,0 +1,38 @@
|
|||
#!/usr/bin/env bash
|
||||
# Summary: List all Ruby versions that contain the given executable
|
||||
# Usage: rbenv whence [--path] <command>
|
||||
|
||||
set -e
|
||||
[ -n "$RBENV_DEBUG" ] && set -x
|
||||
|
||||
# Provide rbenv completions
|
||||
if [ "$1" = "--complete" ]; then
|
||||
echo --path
|
||||
exec rbenv-shims --short
|
||||
fi
|
||||
|
||||
if [ "$1" = "--path" ]; then
|
||||
print_paths="1"
|
||||
shift
|
||||
else
|
||||
print_paths=""
|
||||
fi
|
||||
|
||||
whence() {
|
||||
local command="$1"
|
||||
rbenv-versions --bare | while read -r version; do
|
||||
path="$(rbenv-prefix "$version")/bin/${command}"
|
||||
if [ -x "$path" ]; then
|
||||
[ "$print_paths" ] && echo "$path" || echo "$version"
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
RBENV_COMMAND="$1"
|
||||
if [ -z "$RBENV_COMMAND" ]; then
|
||||
rbenv-help --usage whence >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
result="$(whence "$RBENV_COMMAND")"
|
||||
[ -n "$result" ] && echo "$result"
|
||||
74
libexec/rbenv-which
Executable file
74
libexec/rbenv-which
Executable file
|
|
@ -0,0 +1,74 @@
|
|||
#!/usr/bin/env bash
|
||||
#
|
||||
# Summary: Display the full path to an executable
|
||||
#
|
||||
# Usage: rbenv which <command>
|
||||
#
|
||||
# Displays the full path to the executable that rbenv will invoke when
|
||||
# you run the given command.
|
||||
|
||||
set -e
|
||||
[ -n "$RBENV_DEBUG" ] && set -x
|
||||
|
||||
# Provide rbenv completions
|
||||
if [ "$1" = "--complete" ]; then
|
||||
exec rbenv-shims --short
|
||||
fi
|
||||
|
||||
remove_from_path() {
|
||||
local path_to_remove="$1"
|
||||
local path_before
|
||||
local result=":${PATH//\~/$HOME}:"
|
||||
while [ "$path_before" != "$result" ]; do
|
||||
path_before="$result"
|
||||
result="${result//:$path_to_remove:/:}"
|
||||
done
|
||||
result="${result%:}"
|
||||
echo "${result#:}"
|
||||
}
|
||||
|
||||
RBENV_COMMAND="$1"
|
||||
|
||||
if [ -z "$RBENV_COMMAND" ]; then
|
||||
rbenv-help --usage which >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
RBENV_VERSION="${RBENV_VERSION:-$(rbenv-version-name)}"
|
||||
|
||||
if [ "$RBENV_VERSION" = "system" ]; then
|
||||
PATH="$(remove_from_path "${RBENV_ROOT}/shims")" \
|
||||
RBENV_COMMAND_PATH="$(command -v "$RBENV_COMMAND" || true)"
|
||||
else
|
||||
RBENV_COMMAND_PATH="${RBENV_ROOT}/versions/${RBENV_VERSION}/bin/${RBENV_COMMAND}"
|
||||
fi
|
||||
|
||||
if [[ ! -x "$RBENV_COMMAND_PATH" && -n "$GEM_HOME" && -x "${GEM_HOME}/bin/${RBENV_COMMAND}" ]]; then
|
||||
RBENV_COMMAND_PATH="${GEM_HOME}/bin/${RBENV_COMMAND}"
|
||||
fi
|
||||
|
||||
IFS=$'\n' read -d '' -r -a scripts <<<"$(rbenv-hooks which)" || true
|
||||
for script in "${scripts[@]}"; do
|
||||
# shellcheck disable=SC1090
|
||||
source "$script"
|
||||
done
|
||||
|
||||
if [ -x "$RBENV_COMMAND_PATH" ]; then
|
||||
echo "$RBENV_COMMAND_PATH"
|
||||
elif [ "$RBENV_VERSION" != "system" ] && [ ! -d "${RBENV_ROOT}/versions/${RBENV_VERSION}" ]; then
|
||||
echo "rbenv: version \`$RBENV_VERSION' is not installed (set by $(rbenv-version-origin))" >&2
|
||||
exit 1
|
||||
else
|
||||
echo "rbenv: $RBENV_COMMAND: command not found" >&2
|
||||
|
||||
versions="$(rbenv-whence "$RBENV_COMMAND" || true)"
|
||||
if [ -n "$versions" ]; then
|
||||
{ echo
|
||||
echo "The \`$1' command exists in these Ruby versions:"
|
||||
echo "$versions" | sed 's/^/ /g'
|
||||
echo
|
||||
} >&2
|
||||
fi
|
||||
|
||||
exit 127
|
||||
fi
|
||||
550
man/man1/pyenv.1
550
man/man1/pyenv.1
|
|
@ -1,550 +0,0 @@
|
|||
.TH PYENV 1 "24 Apr 2023" "PYENV"
|
||||
.SH NAME
|
||||
pyenv \- Simple Python version management
|
||||
.SH SYNOPSIS
|
||||
.B pyenv
|
||||
\fI\,<command> \/\fR[\fI\,<args>\/\fR]
|
||||
.SH DESCRIPTION
|
||||
pyenv lets you easily switch between multiple versions of Python\. It's simple, unobtrusive, and follows the UNIX tradition of single\-purpose tools that do one thing well\.
|
||||
.P
|
||||
To start using pyenv
|
||||
.IP "1." 3
|
||||
\fBAppend\fR the following to \fB$HOME/.bashrc\fR
|
||||
.P
|
||||
.RS 15
|
||||
.nf
|
||||
if command -v pyenv 1>/dev/null 2>&1; then\n
|
||||
eval "$(pyenv init - bash)" \n
|
||||
fi
|
||||
.fi
|
||||
.RE
|
||||
.RS 3
|
||||
.P
|
||||
.nh
|
||||
Appending this line enables shims. Please make sure this line is placed toward the end of the shell configuration file since it manipulates \fBPATH\fR during the initialization\.
|
||||
.hy
|
||||
.TP 13
|
||||
.B Debian note:
|
||||
Modify only your \fB~/\.bashrc\fR file instead of creating
|
||||
.br
|
||||
\fB~/\.bash_profile\fR
|
||||
.P
|
||||
.RS 0
|
||||
\fBZsh note\fR: Modify your \fB~/\.zshrc\fR file instead of \fB~/\.bashrc\fR
|
||||
.P
|
||||
\fBWarning\fR: If you configured your system so that \fBBASH_ENV\fR variable points to \fB\.bashrc\fR\. You should almost certainly put the above mentioned line into \fB\.bash_profile\fR, and \fBnot\fR into \fB\.bashrc\fR. Otherwise you may observe strange behaviour, such as \fBpyenv\fR getting into an infinite loop. See #264
|
||||
.UR https://github\.com/pyenv/pyenv/issues/264
|
||||
.UE
|
||||
for details.
|
||||
.RE
|
||||
.RE
|
||||
.IP "2." 3
|
||||
\fBRestart your shell so the path changes take effect\.\fR You can now begin using pyenv\.
|
||||
.P
|
||||
.RS 15
|
||||
exec "$SHELL"\fR
|
||||
.RE
|
||||
.IP "3." 3
|
||||
\fBInstall Python versions into \fB$(pyenv root)/versions\fR\.\fR For example, to download and install Python 3\.6\.12, run:
|
||||
.P
|
||||
.RS 15
|
||||
.B pyenv install 3.6.12\fR
|
||||
.RE
|
||||
.P
|
||||
\fBNOTE:\fR If you need to pass configure option to build, please use \fBCONFIGURE_OPTS\fR environment variable. If you are having trouble installing a python version, please visit the wiki page about Common Build Problems
|
||||
.UR https://github\.com/pyenv/pyenv/wiki/Common\-build\-problems
|
||||
.UE
|
||||
.P
|
||||
\fBProxy note\fR: If you use a proxy, export \fBHTTP_PROXY\fR and \fBHTTPS_PROXY\fR environment variables.
|
||||
.P
|
||||
.SS "Stop using pyenv"
|
||||
The simplicity of pyenv makes it easy to temporarily disable it, or uninstall from the system\.
|
||||
To \fBdisable\fR pyenv managing your Python versions, simply remove the \fBpyenv init\fR line from your shell startup configuration\. This will remove pyenv shims directory from PATH, and future invocations like \fBpython\fR will execute the system Python version, as before pyenv\.
|
||||
.IP "" 0
|
||||
.P
|
||||
\fBpyenv\fR will still be accessible on the command line, but your Python apps won't be affected by version switching\.
|
||||
.IP "" 0
|
||||
.SH COMMAND LINE OPTIONS
|
||||
Like \fBgit\fR, the \fBpyenv\fR command delegates to subcommands based on its first argument\.
|
||||
.SS "Some useful pyenv commands are:"
|
||||
.TP 5
|
||||
.B commands
|
||||
List all available pyenv commands
|
||||
.TP
|
||||
.B exec
|
||||
Run an executable with the selected Python version
|
||||
.TP
|
||||
.B global
|
||||
Set or show the global Python version(s)
|
||||
.TP
|
||||
.B help
|
||||
Display help for a command
|
||||
.TP
|
||||
.B hooks
|
||||
List hook scripts for a given pyenv command
|
||||
.TP
|
||||
.B init
|
||||
Configure the shell environment for pyenv
|
||||
.TP
|
||||
.B install
|
||||
Install a Python version using python\-build
|
||||
.TP
|
||||
.B local
|
||||
Set or show the local application\-specific Python version(s)
|
||||
.TP
|
||||
.B prefix
|
||||
Display prefix for a Python version
|
||||
.TP
|
||||
.B rehash
|
||||
Rehash pyenv shims (run this after installing executables)
|
||||
.TP
|
||||
.B root
|
||||
Display the root directory where versions and shims are kept
|
||||
.TP
|
||||
.B shell
|
||||
Set or show the shell\-specific Python version
|
||||
.TP
|
||||
.B shims
|
||||
List existing pyenv shims
|
||||
.TP
|
||||
.B uninstall
|
||||
Uninstall Python versions
|
||||
.TP
|
||||
.B version
|
||||
Show the current Python version(s) and its origin
|
||||
.TP
|
||||
.B version\-file
|
||||
Detect the file that sets the current pyenv version
|
||||
.TP
|
||||
.B version\-name
|
||||
Show the current Python version
|
||||
.TP
|
||||
.B version\-origin
|
||||
Explain how the current Python version is set
|
||||
.TP
|
||||
.B versions
|
||||
List all Python versions available to pyenv
|
||||
.TP
|
||||
.B whence
|
||||
List all Python versions that contain the given executable
|
||||
.TP
|
||||
.B which
|
||||
Display the full path to an executable
|
||||
.PP
|
||||
See `pyenv help <command>' for information on a specific command.
|
||||
For full documentation, see \fBCOMMAND REFERENCE\fR section
|
||||
.SH OPTIONS
|
||||
.TP
|
||||
.B \-h, \-\-help
|
||||
Show summary of options.
|
||||
.TP
|
||||
.B \-v, \-\-version
|
||||
Show version of program.
|
||||
.SH COMPARISON
|
||||
.P
|
||||
.B "pyenv does\|\.\|\.\|\.
|
||||
.P
|
||||
.IP \(bu 4
|
||||
Let you \fBchange the global Python version\fR on a per\-user basis\.
|
||||
.IP \(bu 4
|
||||
Provide support for \fBper\-project Python versions\fR\.
|
||||
.IP \(bu 4
|
||||
Allow you to \fBoverride the Python version\fR with an environment variable\.
|
||||
.IP \(bu 4
|
||||
Search commands from \fBmultiple versions of Python at a time\fR\. This may be helpful to test across Python versions with tox
|
||||
.IP "" 0
|
||||
.P
|
||||
.B "In contrast with pythonbrew and pythonz, pyenv does not\|\.\|\.\|\."
|
||||
.IP \(bu 4
|
||||
\fBDepend on Python itself\.\fR pyenv was made from pure shell scripts\. There is no bootstrap problem of Python\.
|
||||
.IP \(bu 4
|
||||
\fBNeed to be loaded into your shell\.\fR Instead, pyenv's shim approach works by adding a directory to your \fB$PATH\fR\.
|
||||
.IP \(bu 4
|
||||
\fBManage virtualenv\.\fR Of course, you can create virtualenv yourself, or pyenv\-virtualenv to automate the process\.
|
||||
.SH "How It Works"
|
||||
At a high level, pyenv intercepts Python commands using shim executables injected into your \fBPATH\fR, determines which Python version has been specified by your application, and passes your commands along to the correct Python installation\.
|
||||
.SS "Understanding PATH"
|
||||
When you run a command like \fBpython\fR or \fBpip\fR, your operating system searches through a list of directories to find an executable file with that name\. This list of directories lives in an environment variable called \fBPATH\fR, with each directory in the list separated by a colon:
|
||||
.IP "" 4
|
||||
.nf
|
||||
/usr/local/bin:/usr/bin:/bin
|
||||
.fi
|
||||
.IP "" 0
|
||||
.P
|
||||
Directories in \fBPATH\fR are searched from left to right, so a matching executable in a directory at the beginning of the list takes precedence over another one at the end\. In this example, the \fB/usr/local/bin\fR directory will be searched first, then \fB/usr/bin\fR, then \fB/bin\fR\.
|
||||
.SS "Understanding Shims"
|
||||
pyenv works by inserting a directory of \fIshims\fR at the front of your \fBPATH\fR:
|
||||
.IP "" 4
|
||||
.nf
|
||||
$(pyenv root)/shims:/usr/local/bin:/usr/bin:/bin
|
||||
.fi
|
||||
.IP "" 0
|
||||
.P
|
||||
Through a process called \fIrehashing\fR, pyenv maintains shims in that directory to match every Python command (\fBpython\fR,\fBpip\fR,etc...) across every installed version of Python
|
||||
.P
|
||||
Shims are lightweight executables that simply pass your command along to pyenv\. So with pyenv installed, when you run, say, \fBpip\fR, your operating system will do the following:
|
||||
.IP \(bu 4
|
||||
Search your \fBPATH\fR for an executable file named \fBpip\fR
|
||||
.IP \(bu 4
|
||||
Find the pyenv shim named \fBpip\fR at the beginning of your \fBPATH\fR
|
||||
.IP \(bu 4
|
||||
Run the shim named \fBpip\fR, which in turn passes the command along to pyenv
|
||||
.IP "" 0
|
||||
.SS "Choosing the Python Version"
|
||||
When you execute a shim, pyenv determines which Python version to use by reading it from the following sources, in this order:
|
||||
.IP "1." 4
|
||||
The \fBPYENV_VERSION\fR environment variable (if specified)\. You can use the \fBpyenv shell\fR command to set this environment variable in your current shell session\.
|
||||
.IP "2." 4
|
||||
The application\-specific \fB\.python\-version\fR file in the current directory (if present)\. You can modify the current directory's \fB\.python\-version\fR file with the \fBpyenv local\fR command\.
|
||||
.IP "3." 4
|
||||
The first \fB\.python\-version\fR file found (if any) by searching each parent directory, until reaching the root of your filesystem\.
|
||||
.IP "4." 4
|
||||
The global \fB$(pyenv root)/version\fR file\. You can modify this file using the \fBpyenv global\fR command\. If the global version file is not present, pyenv assumes you want to use the "system" Python\. (In other words, whatever version would run if pyenv weren't in your \fBPATH\fR\.)
|
||||
.IP "" 0
|
||||
.P
|
||||
.nh
|
||||
\fBNOTE:\fR You can activate multiple versions at the same time, including multiple versions of Python2 or Python3 simultaneously\. This allows for parallel usage of Python2 and Python3, and is required with tools like \fBtox\fR\. For example, to set your path to first use your \fBsystem\fR Python and Python3 (set to 2\.7\.9 and 3\.4\.2 in this example), but also have Python 3\.3\.6, 3\.2, and 2\.5 available on your \fBPATH\fR, one would first \fBpyenv install\fR the missing versions, then set \fBpyenv global system 3\.3\.6 3\.2 2\.5\fR\. At this point, one should be able to find the full executable path to each of these using \fBpyenv which\fR, e\.g\. \fBpyenv which python2\.5\fR (should display \fB$(pyenv root)/versions/2\.5/bin/python2\.5\fR), or \fBpyenv which python3\.4\fR (should display path to system Python3)\. You can also specify multiple versions in a \fB\.python\-version\fR file, separated by newlines or any whitespace\.
|
||||
hy
|
||||
.SS "Locating the Python Installation"
|
||||
Once pyenv has determined which version of Python your application has specified, it passes the command along to the corresponding Python installation\.
|
||||
.P
|
||||
Each Python version is installed into its own directory under
|
||||
.nf
|
||||
\fB$(pyenv root)/versions\fR\.
|
||||
.fi
|
||||
.P
|
||||
For example, you might have these versions installed:
|
||||
.IP \(bu 4
|
||||
\fB$(pyenv root)/versions/2\.7\.8/\fR
|
||||
.IP \(bu 4
|
||||
\fB$(pyenv root)/versions/3\.4\.2/\fR
|
||||
.IP \(bu 4
|
||||
\fB$(pyenv root)/versions/pypy\-2\.4\.0/\fR
|
||||
.IP "" 0
|
||||
.P
|
||||
As far as pyenv is concerned, version names are simply the directories in \fB$(pyenv root)/versions\fR\.
|
||||
.SS "Managing Virtual Environments"
|
||||
There is a pyenv plugin named pyenv\-virtualenv which comes with various features to help pyenv users to manage virtual environments created by virtualenv or Anaconda\. Because the \fBactivate\fR script of those virtual environments are relying on mutating \fB$PATH\fR variable of user's interactive shell, it will intercept pyenv's shim style command execution hooks\. We'd recommend to install pyenv\-virtualenv as well if you have some plan to play with those virtual environments\.
|
||||
|
||||
.SH "Advanced Configuration"
|
||||
Skip this section unless you must know what every line in your shell profile is doing\.
|
||||
.P
|
||||
\fBpyenv init\fR is the only command that crosses the line of loading extra commands into your shell\. Coming from rvm, some of you might be opposed to this idea\. Here's what \fBpyenv init\fR actually does:
|
||||
.IP "1." 4
|
||||
\fBSets up your shims path\.\fR This is the only requirement for pyenv to function properly\. You can do this by hand by prepending \fB$(pyenv root)/shims\fR to your \fB$PATH\fR\.
|
||||
.IP "2." 4
|
||||
\fBRehashes shims\.\fR From time to time you'll need to rebuild your shim files\. Doing this on init makes sure everything is up to date\. You can always run \fBpyenv rehash\fR manually\.
|
||||
You can disable this functionality by adding \fB--no-rehash\fR to the end of your \fBpyenv init\fR command line.
|
||||
.IP "3." 4
|
||||
\fBInstalls the sh dispatcher\.\fR This bit is also optional, but allows pyenv and plugins to change variables in your current shell, making commands like \fBpyenv shell\fR possible\. The sh dispatcher doesn't do anything crazy like override \fBcd\fR or hack your shell prompt, but if for some reason you need \fBpyenv\fR to be a real script rather than a shell function, you can safely skip it\.
|
||||
.IP "" 0
|
||||
.P
|
||||
To see exactly what happens under the hood for yourself, run \fB"pyenv init \-"\fR\.
|
||||
.SH "Uninstalling Python Versions"
|
||||
As time goes on, you will accumulate Python versions in your \fB$(pyenv root)/versions\fR directory\.
|
||||
.P
|
||||
To remove old Python versions, \fBpyenv uninstall\fR command to automate the removal process\.
|
||||
.P
|
||||
Alternatively, simply \fBrm \-rf\fR the directory of the version you want to remove\. You can find the directory of a particular Python version with the \fBpyenv prefix\fR command,
|
||||
.P
|
||||
e\.g\. \fBpyenv prefix 2\.6\.8\fR\.
|
||||
.SH "Command Reference"
|
||||
.P
|
||||
The most common subcommands are:
|
||||
.SS "pyenv commands"
|
||||
Lists all available pyenv commands\.
|
||||
.SS "pyenv local"
|
||||
Sets a local application\-specific Python version by writing the version name to a \fB\.python\-version\fR file in the current directory\. This version overrides the global version, and can be overridden itself by setting the \fBPYENV_VERSION\fR environment variable or with the \fBpyenv shell\fR command\.
|
||||
.IP "" 4
|
||||
.nf
|
||||
$ pyenv local 2\.7\.6
|
||||
.fi
|
||||
.IP "" 0
|
||||
.P
|
||||
When run without a version number, \fBpyenv local\fR reports the currently configured local version\. You can also unset the local version:
|
||||
.IP "" 4
|
||||
.nf
|
||||
$ pyenv local \-\-unset
|
||||
.fi
|
||||
.IP "" 0
|
||||
.P
|
||||
Previous versions of pyenv stored local version specifications in a file named \fB\.pyenv\-version\fR\. For backwards compatibility, pyenv will read a local version specified in an \fB\.pyenv\-version\fR file, but a \fB\.python\-version\fR file in the same directory will take precedence\.
|
||||
.P
|
||||
You can specify multiple versions as local Python at once\.
|
||||
.P
|
||||
Let's say if you have two versions of 2\.7\.6 and 3\.3\.3\. If you prefer 2\.7\.6 over 3\.3\.3,
|
||||
.IP "" 4
|
||||
.nf
|
||||
$ pyenv local 2\.7\.6 3\.3\.3
|
||||
$ pyenv versions
|
||||
system
|
||||
* 2\.7\.6 (set by /Users/yyuu/path/to/project/\.python\-version)
|
||||
* 3\.3\.3 (set by /Users/yyuu/path/to/project/\.python\-version)
|
||||
$ python \-\-version
|
||||
Python 2\.7\.6
|
||||
$ python2\.7 \-\-version
|
||||
Python 2\.7\.6
|
||||
$ python3\.3 \-\-version
|
||||
Python 3\.3\.3
|
||||
.fi
|
||||
.IP "" 0
|
||||
.P
|
||||
or, if you prefer 3\.3\.3 over 2\.7\.6,
|
||||
.IP "" 4
|
||||
.nf
|
||||
$ pyenv local 3\.3\.3 2\.7\.6
|
||||
$ pyenv versions
|
||||
system
|
||||
* 2\.7\.6 (set by /Users/yyuu/path/to/project/\.python\-version)
|
||||
* 3\.3\.3 (set by /Users/yyuu/path/to/project/\.python\-version)
|
||||
venv27
|
||||
$ python \-\-version
|
||||
Python 3\.3\.3
|
||||
$ python2\.7 \-\-version
|
||||
Python 2\.7\.6
|
||||
$ python3\.3 \-\-version
|
||||
Python 3\.3\.3
|
||||
.fi
|
||||
.IP "" 0
|
||||
.SS "pyenv global"
|
||||
Sets the global version of Python to be used in all shells by writing the version name to the \fB~/\.pyenv/version\fR file\. This version can be overridden by an application\-specific \fB\.python\-version\fR file, or by setting the \fBPYENV_VERSION\fR environment variable\.
|
||||
.IP "" 4
|
||||
.nf
|
||||
$ pyenv global 2\.7\.6
|
||||
.fi
|
||||
.IP "" 0
|
||||
.P
|
||||
The special version name \fBsystem\fR tells pyenv to use the system Python (detected by searching your \fB$PATH\fR)\.
|
||||
.P
|
||||
When run without a version number, \fBpyenv global\fR reports the currently configured global version\.
|
||||
.P
|
||||
You can specify multiple versions as global Python at once\.
|
||||
.P
|
||||
Let's say if you have two versions of 2\.7\.6 and 3\.3\.3\. If you prefer 2\.7\.6 over 3\.3\.3,
|
||||
.IP "" 4
|
||||
.nf
|
||||
$ pyenv global 2\.7\.6 3\.3\.3
|
||||
$ pyenv versions
|
||||
system
|
||||
* 2\.7\.6 (set by /Users/yyuu/\.pyenv/version)
|
||||
* 3\.3\.3 (set by /Users/yyuu/\.pyenv/version)
|
||||
$ python \-\-version
|
||||
Python 2\.7\.6
|
||||
$ python2\.7 \-\-version
|
||||
Python 2\.7\.6
|
||||
$ python3\.3 \-\-version
|
||||
Python 3\.3\.3
|
||||
.fi
|
||||
.IP "" 0
|
||||
.P
|
||||
or, if you prefer 3\.3\.3 over 2\.7\.6,
|
||||
.IP "" 4
|
||||
.nf
|
||||
$ pyenv global 3\.3\.3 2\.7\.6
|
||||
$ pyenv versions
|
||||
system
|
||||
* 2\.7\.6 (set by /Users/yyuu/\.pyenv/version)
|
||||
* 3\.3\.3 (set by /Users/yyuu/\.pyenv/version)
|
||||
venv27
|
||||
$ python \-\-version
|
||||
Python 3\.3\.3
|
||||
$ python2\.7 \-\-version
|
||||
Python 2\.7\.6
|
||||
$ python3\.3 \-\-version
|
||||
Python 3\.3\.3
|
||||
.fi
|
||||
.IP "" 0
|
||||
.SS "pyenv shell"
|
||||
Sets a shell\-specific Python version by setting the \fBPYENV_VERSION\fR environment variable in your shell\. This version overrides application\-specific versions and the global version\.
|
||||
.IP "" 4
|
||||
.nf
|
||||
$ pyenv shell pypy\-2\.2\.1
|
||||
.fi
|
||||
.IP "" 0
|
||||
.P
|
||||
When run without a version number, \fBpyenv shell\fR reports the current value of \fBPYENV_VERSION\fR\. You can also unset the shell version:
|
||||
.IP "" 4
|
||||
.nf
|
||||
$ pyenv shell \-\-unset
|
||||
.fi
|
||||
.IP "" 0
|
||||
.P
|
||||
Note that you'll need pyenv's shell integration enabled (step 3 of the installation instructions) in order to use this command\. If you prefer not to use shell integration, you may simply set the \fBPYENV_VERSION\fR variable yourself:
|
||||
.IP "" 4
|
||||
.nf
|
||||
$ export PYENV_VERSION=pypy\-2\.2\.1
|
||||
.fi
|
||||
.IP "" 0
|
||||
.P
|
||||
You can specify multiple versions via \fBPYENV_VERSION\fR at once\.
|
||||
.P
|
||||
Let's say if you have two versions of 2\.7\.6 and 3\.3\.3\. If you prefer 2\.7\.6 over 3\.3\.3,
|
||||
.IP "" 4
|
||||
.nf
|
||||
$ pyenv shell 2\.7\.6 3\.3\.3
|
||||
$ pyenv versions
|
||||
system
|
||||
* 2\.7\.6 (set by PYENV_VERSION environment variable)
|
||||
* 3\.3\.3 (set by PYENV_VERSION environment variable)
|
||||
$ python \-\-version
|
||||
Python 2\.7\.6
|
||||
$ python2\.7 \-\-version
|
||||
Python 2\.7\.6
|
||||
$ python3\.3 \-\-version
|
||||
Python 3\.3\.3
|
||||
.fi
|
||||
.IP "" 0
|
||||
.P
|
||||
or, if you prefer 3\.3\.3 over 2\.7\.6,
|
||||
.IP "" 4
|
||||
.nf
|
||||
$ pyenv shell 3\.3\.3 2\.7\.6
|
||||
$ pyenv versions
|
||||
system
|
||||
* 2\.7\.6 (set by PYENV_VERSION environment variable)
|
||||
* 3\.3\.3 (set by PYENV_VERSION environment variable)
|
||||
venv27
|
||||
$ python \-\-version
|
||||
Python 3\.3\.3
|
||||
$ python2\.7 \-\-version
|
||||
Python 2\.7\.6
|
||||
$ python3\.3 \-\-version
|
||||
Python 3\.3\.3
|
||||
.fi
|
||||
.IP "" 0
|
||||
.SS "pyenv install"
|
||||
Install a Python version
|
||||
.IP "" 4
|
||||
.nf
|
||||
Usage: pyenv install [\-f] [\-kvp] <version>
|
||||
pyenv install [\-f] [\-kvp] <definition\-file>
|
||||
pyenv install \-l|\-\-list
|
||||
|
||||
\-l, \-\-list List all available versions
|
||||
\-f, \-\-force Install even if the version appears to be installed
|
||||
already
|
||||
\-s, \-\-skip\-existing Skip the installation if the version appears to be
|
||||
installed already
|
||||
|
||||
python\-build options:
|
||||
|
||||
\-k, \-\-keep Keep source tree in $PYENV_BUILD_ROOT after installation
|
||||
(defaults to $PYENV_ROOT/sources)
|
||||
\-v, \-\-verbose Verbose mode: print compilation status to stdout
|
||||
\-p, \-\-patch Apply a patch from stdin before building
|
||||
\-g, \-\-debug Build a debug version
|
||||
.fi
|
||||
.IP "" 0
|
||||
.P
|
||||
To list the all available versions of Python, including Anaconda, Jython, pypy, and stackless, use:
|
||||
.IP "" 4
|
||||
.nf
|
||||
$ pyenv install \-\-list
|
||||
.fi
|
||||
.IP "" 0
|
||||
.P
|
||||
Then install the desired versions:
|
||||
.IP "" 4
|
||||
.nf
|
||||
$ pyenv install 2\.7\.6
|
||||
$ pyenv install 2\.6\.8
|
||||
$ pyenv versions
|
||||
system
|
||||
2\.6\.8
|
||||
* 2\.7\.6 (set by /home/yyuu/\.pyenv/version)
|
||||
.fi
|
||||
.IP "" 0
|
||||
.SS "pyenv uninstall"
|
||||
Uninstall Python versions\.
|
||||
.IP "" 4
|
||||
.nf
|
||||
Usage: pyenv uninstall [\-f|\-\-force] <version> ...
|
||||
|
||||
\-f Attempt to remove the specified version without prompting
|
||||
for confirmation\. If the version does not exist, do not
|
||||
display an error message\.
|
||||
.fi
|
||||
.IP "" 0
|
||||
.SS "pyenv rehash"
|
||||
Installs shims for all Python binaries known to pyenv (i\.e\., \fB~/\.pyenv/versions/*/bin/*\fR)\. Run this command after you install a new version of Python, or install a package that provides binaries\.
|
||||
.IP "" 4
|
||||
.nf
|
||||
$ pyenv rehash
|
||||
.fi
|
||||
.IP "" 0
|
||||
.SS "pyenv version"
|
||||
Displays the currently active Python version, along with information on how it was set\.
|
||||
.IP "" 4
|
||||
.nf
|
||||
$ pyenv version
|
||||
2\.7\.6 (set by /home/yyuu/\.pyenv/version)
|
||||
.fi
|
||||
.IP "" 0
|
||||
.SS "pyenv versions"
|
||||
Lists all Python versions known to pyenv, and shows an asterisk next to the currently active version\.
|
||||
.IP "" 4
|
||||
.nf
|
||||
$ pyenv versions
|
||||
2\.5\.6
|
||||
2\.6\.8
|
||||
* 2\.7\.6 (set by /home/yyuu/\.pyenv/version)
|
||||
3\.3\.3
|
||||
jython\-2\.5\.3
|
||||
pypy\-2\.2\.1
|
||||
.fi
|
||||
.IP "" 0
|
||||
.SS "pyenv which"
|
||||
Displays the full path to the executable that pyenv will invoke when you run the given command\.
|
||||
.IP "" 4
|
||||
.nf
|
||||
$ pyenv which python3\.3
|
||||
/home/yyuu/\.pyenv/versions/3\.3\.3/bin/python3\.3
|
||||
.fi
|
||||
.IP "" 0
|
||||
.SS "pyenv whence"
|
||||
Lists all Python versions with the given command installed\.
|
||||
.IP "" 4
|
||||
.nf
|
||||
$ pyenv whence 2to3
|
||||
2\.6\.8
|
||||
2\.7\.6
|
||||
3\.3\.3
|
||||
.fi
|
||||
.IP "" 0
|
||||
.SH "Environment variables"
|
||||
You can affect how pyenv operates with the following settings:
|
||||
.TP 28
|
||||
.B name (default)
|
||||
.B description
|
||||
.TP 28
|
||||
.B PYENV_VERSION
|
||||
Specifies the Python version to be used. Also see \fBpyenv shell\fR
|
||||
.TP
|
||||
.B PYENV_ROOT (\fB~/.pyenv\fR)
|
||||
Defines the directory under which Python versions and shims reside. Also see \fBpyenv root\fR
|
||||
.TP
|
||||
.B PYENV_DEBUG
|
||||
Outputs debug information.
|
||||
.br
|
||||
Also as: \fBpyenv --debug <subcommand>\fR
|
||||
.TP
|
||||
.B PYENV_HOOK_PATH
|
||||
Colon\-separated list of paths searched for pyenv hooks\.
|
||||
.TP
|
||||
.B PYENV_DIR (\fB$PWD\fR)
|
||||
Directory to start searching for \fB\.python\-version\fR files\.
|
||||
.TP
|
||||
.B HTTP_PROXY,HTTPS_PROXY
|
||||
Proxy Variables
|
||||
.TP
|
||||
.B CONFIGURE_OPTS
|
||||
Pass configure options to build.
|
||||
.TP
|
||||
.B PYTHON_BUILD_ARIA2_OPTS
|
||||
Used to pass additional parameters to \fBaria2\fR
|
||||
.UR https://aria2\.github\.io/
|
||||
.UE
|
||||
If the \fBaria2c\fR binary is available on PATH, pyenv uses \fBaria2c\fR instead of \fBcurl\fR or \fBwget\fR to download the Python Source code\. If you have an unstable internet connection, you can use this variable to instruct \fBaria2\fR to accelerate the download\.
|
||||
In most cases, you will only need to use \fB\-x 10 \-k 1M\fR as value to \fBPYTHON_BUILD_ARIA2_OPTS\fR environment variable
|
||||
.SH "License"
|
||||
The \fBMIT\fR License
|
||||
7
plugins/.gitignore
vendored
7
plugins/.gitignore
vendored
|
|
@ -1,7 +0,0 @@
|
|||
/*
|
||||
!/.gitignore
|
||||
!/version-ext-compat
|
||||
!/python-build
|
||||
!/pyenv-binary
|
||||
!/pyenv-link
|
||||
/python-build/test/build
|
||||
|
|
@ -1,94 +0,0 @@
|
|||
# pyenv-binary (experimental)
|
||||
|
||||
Package an installed Python version into a relocatable archive that can be
|
||||
installed on another machine.
|
||||
|
||||
This is experimental and intentionally decoupled: it does not change
|
||||
`pyenv install` or any other command. You drive it explicitly through
|
||||
`pyenv binary`. Run `pyenv binary <command> --help` for details on a command.
|
||||
|
||||
## Portability
|
||||
|
||||
An archive is portable across machines that share its build platform (OS,
|
||||
architecture and a compatible libc) and have the recorded system libraries. It
|
||||
is not portable across, say, glibc and musl, or to an older glibc; the platform
|
||||
and dependency metadata exist to catch that.
|
||||
|
||||
## Commands
|
||||
|
||||
### `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)
|
||||
and writes `<version>-<platform>.meta` describing the build platform (OS, arch,
|
||||
distro and libc version) and the system libraries the build links against. Use
|
||||
`--name` to set a different base name for both files.
|
||||
|
||||
```sh
|
||||
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.
|
||||
|
|
@ -1,65 +0,0 @@
|
|||
#!/usr/bin/env bash
|
||||
#
|
||||
# Summary: Package an installed Python version as a relocatable binary (experimental)
|
||||
#
|
||||
# Usage: pyenv binary <command> [<args>]
|
||||
#
|
||||
# `pyenv binary` packages an already-installed Python version into a relocatable
|
||||
# archive that can be installed on another machine. It is experimental and does
|
||||
# not touch `pyenv install' or any other command.
|
||||
#
|
||||
# Run `pyenv binary' to list its commands, or `pyenv binary <command> --help'
|
||||
# for command-specific help.
|
||||
#
|
||||
set -e
|
||||
[ -n "$PYENV_DEBUG" ] && set -x
|
||||
|
||||
libexec="${BASH_SOURCE%/*}/../libexec"
|
||||
|
||||
# The pyenv launcher only puts a plugin's bin on PATH, but `pyenv-help' looks a
|
||||
# command up there. Add our libexec so the subcommands, and the help text they
|
||||
# print, can be found.
|
||||
export PATH="${libexec}:${PATH}"
|
||||
|
||||
list_commands() {
|
||||
local path
|
||||
for path in "$libexec"/pyenv-binary-*; do
|
||||
[ -e "$path" ] && echo "${path##*/pyenv-binary-}"
|
||||
done
|
||||
}
|
||||
|
||||
# Provide pyenv completions
|
||||
if [ "$1" = "--complete" ]; then
|
||||
shift
|
||||
if [ -z "$1" ]; then
|
||||
list_commands
|
||||
else
|
||||
command_path="${libexec}/pyenv-binary-$1"
|
||||
shift
|
||||
[ -x "$command_path" ] && exec "$command_path" --complete "$@"
|
||||
fi
|
||||
exit
|
||||
fi
|
||||
|
||||
subcommand="$1"
|
||||
if [ -z "$subcommand" ]; then
|
||||
{ pyenv-help binary
|
||||
echo
|
||||
echo "Commands:"
|
||||
list_commands | sed 's/^/ /'
|
||||
} >&2
|
||||
exit 1
|
||||
fi
|
||||
shift
|
||||
|
||||
command_path="${libexec}/pyenv-binary-${subcommand}"
|
||||
if [ ! -x "$command_path" ]; then
|
||||
echo "pyenv-binary: no such command \`${subcommand}'" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
|
||||
exec pyenv-help "binary-${subcommand}"
|
||||
fi
|
||||
|
||||
exec "$command_path" "$@"
|
||||
|
|
@ -1,224 +0,0 @@
|
|||
#!/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
|
||||
|
|
@ -1,83 +0,0 @@
|
|||
#!/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"
|
||||
|
|
@ -1,73 +0,0 @@
|
|||
#!/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"
|
||||
|
|
@ -1,137 +0,0 @@
|
|||
#!/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')
|
||||
|
|
@ -1,157 +0,0 @@
|
|||
#!/usr/bin/env bash
|
||||
#
|
||||
# Summary: Save an installed Python version as a relocatable archive
|
||||
#
|
||||
# Usage: pyenv binary save <version> [<output-dir>] [--name <name>]
|
||||
#
|
||||
# Packs an installed version into a relocatable .tar.gz (relative paths) and
|
||||
# writes a metadata file listing the build platform and the system libraries
|
||||
# it links against, so an installer can check compatibility before unpacking.
|
||||
#
|
||||
# <version> An installed version, as listed by `pyenv versions --bare'.
|
||||
# <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
|
||||
[ -n "$PYENV_DEBUG" ] && set -x
|
||||
|
||||
# Provide pyenv completions
|
||||
if [ "$1" = "--complete" ]; then
|
||||
echo --name
|
||||
exec pyenv-versions --bare
|
||||
fi
|
||||
|
||||
version=""
|
||||
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
|
||||
echo "Usage: pyenv binary save <version> [<output-dir>] [--name <name>]" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# A version is a single directory name under versions/. With no slash allowed,
|
||||
# the only remaining names that could point elsewhere are `.' and `..'.
|
||||
case "$version" in
|
||||
*/* | .. | . )
|
||||
echo "pyenv-binary: invalid version name \`${version}'" >&2
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
||||
case "$package_name" in
|
||||
*/* | .. | . | *[[:cntrl:]]* )
|
||||
echo "pyenv-binary: invalid package name \`${package_name}'" >&2
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
||||
prefix="${PYENV_ROOT}/versions/${version}"
|
||||
if [ ! -d "${prefix}/bin" ]; then
|
||||
echo "pyenv-binary: version \`${version}' is not installed" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
os="$(uname -s)"
|
||||
arch="$(uname -m)"
|
||||
platform="$(printf '%s' "$os" | tr '[:upper:]' '[:lower:]')-${arch}"
|
||||
|
||||
# Record the distro and libc version. Platform and arch alone are too coarse to
|
||||
# judge compatibility: a build is only portable to a matching libc (e.g. a
|
||||
# glibc 2.36 build will not load on an older glibc, nor on musl at all).
|
||||
distro=""
|
||||
libc=""
|
||||
if [ -r /etc/os-release ]; then
|
||||
distro="$( . /etc/os-release && printf '%s %s' "${ID:-}" "${VERSION_ID:-}" )"
|
||||
elif [ "$os" = "Darwin" ]; then
|
||||
distro="macos $(sw_vers -productVersion 2>/dev/null)"
|
||||
fi
|
||||
if [ "$os" = "Linux" ]; then
|
||||
libc="$(getconf GNU_LIBC_VERSION 2>/dev/null || true)"
|
||||
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
|
||||
# resolve outside its own prefix, so they must already exist on the target.
|
||||
# The interpreter plus every bundled shared object are inspected.
|
||||
system_deps() {
|
||||
local f needed
|
||||
{
|
||||
for f in "${prefix}"/bin/python*; do
|
||||
[ -e "$f" ] && printf '%s\n' "$f"
|
||||
done
|
||||
# CPython ships its extension modules as *.so (and *.dylib on macOS). A
|
||||
# bare *.so.* is unusual for CPython itself, but the odd build carries a
|
||||
# versioned copy alongside, so match it too rather than miss a dependency.
|
||||
find "${prefix}" -type f \( -name '*.so' -o -name '*.so.*' -o -name '*.dylib' \)
|
||||
} | sort -u | while IFS= read -r f; do
|
||||
if [ "$os" = "Darwin" ]; then
|
||||
otool -L "$f" 2>/dev/null | tail -n +2 | awk -v pfx="${prefix}/" \
|
||||
'$1 !~ /^@/ && substr($1, 1, length(pfx)) != pfx { print $1 }'
|
||||
else
|
||||
# GNU binutils 2.44 writes "(NEEDED) ... [name]"; FreeBSD 15.1 writes
|
||||
# "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
|
||||
done | sort -u
|
||||
}
|
||||
|
||||
mkdir -p "$output_dir"
|
||||
package_name="${package_name:-${version}-${platform}}"
|
||||
archive="${package_name}.tar.gz"
|
||||
metadata="${package_name}.meta"
|
||||
|
||||
tar -C "$(dirname "$prefix")" -czf "${output_dir}/${archive}" "$(basename "$prefix")"
|
||||
|
||||
{
|
||||
echo "# pyenv-binary metadata"
|
||||
echo "version=${version}"
|
||||
echo "os=${os}"
|
||||
echo "arch=${arch}"
|
||||
echo "platform=${platform}"
|
||||
[ -n "$distro" ] && echo "distro=${distro}"
|
||||
[ -n "$libc" ] && echo "libc=${libc}"
|
||||
echo "build_prefix=${prefix}"
|
||||
echo "archive=${archive}"
|
||||
system_deps | while IFS= read -r dep; do
|
||||
[ -n "$dep" ] && echo "dep=${dep}"
|
||||
done
|
||||
} > "${output_dir}/${metadata}"
|
||||
|
||||
echo "Saved ${archive} and ${metadata} to ${output_dir}"
|
||||
|
|
@ -1,212 +0,0 @@
|
|||
#!/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" ]
|
||||
}
|
||||
|
|
@ -1,59 +0,0 @@
|
|||
#!/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'"
|
||||
}
|
||||
|
|
@ -1,131 +0,0 @@
|
|||
#!/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"
|
||||
}
|
||||
|
|
@ -1,221 +0,0 @@
|
|||
#!/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 ""
|
||||
}
|
||||
|
|
@ -1,155 +0,0 @@
|
|||
#!/usr/bin/env bats
|
||||
|
||||
load test_helper
|
||||
|
||||
create_version() {
|
||||
mkdir -p "${PYENV_ROOT}/versions/$1/bin"
|
||||
}
|
||||
|
||||
platform() {
|
||||
echo "$(uname -s | tr '[:upper:]' '[:lower:]')-$(uname -m)"
|
||||
}
|
||||
|
||||
@test "fails with no version given" {
|
||||
run pyenv-binary-save
|
||||
assert_failure "Usage: pyenv binary save <version> [<output-dir>] [--name <name>]"
|
||||
}
|
||||
|
||||
@test "fails for a version that is not installed" {
|
||||
run pyenv-binary-save 9.9.9
|
||||
assert_failure "pyenv-binary: version \`9.9.9' is not installed"
|
||||
}
|
||||
|
||||
@test "rejects a version name containing a slash" {
|
||||
run pyenv-binary-save "foo/bar"
|
||||
assert_failure "pyenv-binary: invalid version name \`foo/bar'"
|
||||
}
|
||||
|
||||
@test "rejects the parent directory reference" {
|
||||
run pyenv-binary-save ".."
|
||||
assert_failure "pyenv-binary: invalid version name \`..'"
|
||||
}
|
||||
|
||||
@test "packages an installed version" {
|
||||
create_version "3.12.7"
|
||||
local out="${BATS_TEST_TMPDIR}/dist"
|
||||
local archive="${out}/3.12.7-$(platform).tar.gz"
|
||||
|
||||
run pyenv-binary-save "3.12.7" "$out"
|
||||
assert_success "Saved 3.12.7-$(platform).tar.gz and 3.12.7-$(platform).meta to $out"
|
||||
assert [ -f "$archive" ]
|
||||
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" {
|
||||
create_version "3.12.7"
|
||||
local out="${BATS_TEST_TMPDIR}/dist"
|
||||
pyenv-binary-save "3.12.7" "$out" >/dev/null
|
||||
|
||||
run cat "${out}/3.12.7-$(platform).meta"
|
||||
assert_success
|
||||
assert_line "version=3.12.7"
|
||||
assert_line "platform=$(platform)"
|
||||
assert_line "archive=3.12.7-$(platform).tar.gz"
|
||||
}
|
||||
|
||||
@test "records the original installation prefix" {
|
||||
create_version "3.12.7"
|
||||
local out="${BATS_TEST_TMPDIR}/dist"
|
||||
pyenv-binary-save "3.12.7" "$out" >/dev/null
|
||||
|
||||
run grep '^build_prefix=' "${out}/3.12.7-$(platform).meta"
|
||||
assert_success "build_prefix=${PYENV_ROOT}/versions/3.12.7"
|
||||
}
|
||||
|
||||
@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"
|
||||
touch "${PYENV_ROOT}/versions/3.12.7/bin/python3.12"
|
||||
create_path_executable uname <<'STUB'
|
||||
case "$1" in
|
||||
-s) echo Linux ;;
|
||||
-m) echo x86_64 ;;
|
||||
esac
|
||||
STUB
|
||||
create_path_executable ldd <<'STUB'
|
||||
prefix="${PYENV_ROOT}/versions/3.12.7"
|
||||
cat <<EOF
|
||||
linux-vdso.so.1 (0x00007ffd1adfe000)
|
||||
libpython3.12.so.1.0 => ${prefix}/lib/libpython3.12.so.1.0 (0x00007f4a3c000000)
|
||||
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f4a3bc00000)
|
||||
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f4a3b800000)
|
||||
/lib64/ld-linux-x86-64.so.2 (0x00007f4a3c200000)
|
||||
EOF
|
||||
STUB
|
||||
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
|
||||
|
||||
run pyenv-binary-save "3.12.7" "${BATS_TEST_TMPDIR}/dist"
|
||||
assert_success
|
||||
run grep '^dep=' "${BATS_TEST_TMPDIR}/dist/"*.meta
|
||||
assert_output "dep=libm.so.6"
|
||||
}
|
||||
|
||||
@test "records only the libraries otool resolves outside the prefix" {
|
||||
create_version "3.12.7"
|
||||
touch "${PYENV_ROOT}/versions/3.12.7/bin/python3.12"
|
||||
create_path_executable uname <<'STUB'
|
||||
case "$1" in
|
||||
-s) echo Darwin ;;
|
||||
-m) echo arm64 ;;
|
||||
esac
|
||||
STUB
|
||||
create_path_executable otool <<'STUB'
|
||||
prefix="${PYENV_ROOT}/versions/3.12.7"
|
||||
cat <<EOF
|
||||
${2}:
|
||||
@rpath/libpython3.12.dylib (compatibility version 3.12.0, current version 3.12.0)
|
||||
${prefix}/lib/libcrypto.3.dylib (compatibility version 3.0.0, current version 3.0.0)
|
||||
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1345.0.0)
|
||||
EOF
|
||||
STUB
|
||||
|
||||
run pyenv-binary-save "3.12.7" "${BATS_TEST_TMPDIR}/dist"
|
||||
assert_success
|
||||
run grep '^dep=' "${BATS_TEST_TMPDIR}/dist/"*.meta
|
||||
assert_output "dep=/usr/lib/libSystem.B.dylib"
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue