-
Notifications
You must be signed in to change notification settings - Fork 344
Add python-as-wrapper package and use it in asciidoc build. #36891
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
smoser
wants to merge
1
commit into
wolfi-dev:main
Choose a base branch
from
smoser:feat/python-as-wrapper
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
package: | ||
name: python-as-wrapper | ||
version: 0.1.0 | ||
epoch: 0 | ||
description: Shell script wrapper to exec python3.XX | ||
copyright: | ||
- license: Apache-2.0 | ||
|
||
# In a "normal" installation of python, 'python3' is a symlink | ||
# to 'pythonX.Y' where X.Y is Major.Minor (3.13). In that scenario, | ||
# if caller invokes 'python3', then when python reads its sys.executable, | ||
# the executable is 'python3'. | ||
# | ||
# That value of sys.executable is "sticky" and finds its way into shbangs that | ||
# are installed with 'pip install' or other places. | ||
# | ||
# In the vast majority of places, we do not want shebang with | ||
# /usr/bin/python3 because at runtime: | ||
# * python3 might be a symlink to another python version | ||
# * python3 may not exist at all - with only python3.XX installed. | ||
# | ||
# This wrapper will cause the scripts generated by 'python3 -m pip install pkg' | ||
# to be generated with a shbang of /usr/bin/python3.Y instead of /usr/bin/python3. | ||
# | ||
# Note: None of these packages are intended for production use. | ||
# They are intended to be used to accomodate package build systems | ||
# That invoke 'python3' or 'python'. | ||
data: | ||
- name: py-versions | ||
items: | ||
3.10: '310' | ||
3.11: '311' | ||
3.12: '312' | ||
3.13: '313' | ||
- name: python-as-names | ||
items: | ||
python: PYTHON_AS | ||
python3: PYTHON3_AS | ||
|
||
environment: | ||
contents: | ||
packages: | ||
- busybox | ||
|
||
pipeline: | ||
- runs: | | ||
chmod 755 write-strict write-env | ||
chmod 755 test-python3-as-env test-python3-as-wrapper | ||
|
||
subpackages: | ||
- range: py-versions | ||
name: python3-as-${{range.key}} | ||
description: provides /usr/bin/python3 that execs python${{range.key}} | ||
dependencies: | ||
runtime: | ||
- python-${{range.key}}-base | ||
pipeline: | ||
- runs: | | ||
./write-strict "python${{range.key}}" ${{targets.contextdir}}/usr/bin/python3 | ||
test: | ||
environment: | ||
contents: | ||
packages: | ||
- python3-as-test | ||
pipeline: | ||
- name: validate wrapper 'python3' for ${{range.key}} | ||
runs: | | ||
python3 /usr/bin/test-python3-as-wrapper \ | ||
python3 test-python3-as-wrapper ${{range.key}} | ||
|
||
- range: py-versions | ||
name: python-as-${{range.key}} | ||
description: provides /usr/bin/python that execs python${{range.key}} | ||
dependencies: | ||
runtime: | ||
- python-${{range.key}}-base | ||
pipeline: | ||
- runs: | | ||
./write-strict "python${{range.key}}" ${{targets.contextdir}}/usr/bin/python | ||
test: | ||
environment: | ||
contents: | ||
packages: | ||
- python3-as-test | ||
pipeline: | ||
- name: validate wrapper 'python' for ${{range.key}} | ||
runs: | | ||
python /usr/bin/test-python3-as-wrapper \ | ||
python test-python3-as-wrapper ${{range.key}} | ||
|
||
- range: python-as-names | ||
name: ${{range.key}}-as-env | ||
description: provides /usr/bin/${{range.key}} that execs env var ${{range.value}} | ||
pipeline: | ||
- runs: | | ||
./write-env "${{range.value}}" ${{targets.contextdir}}/usr/bin/${{range.key}} | ||
test: | ||
environment: | ||
contents: | ||
packages: | ||
- python3-as-test | ||
pipeline: | ||
- name: validate wrapper '${{range.key}}' | ||
runs: | | ||
test-python3-as-env /usr/bin/${{range.key}} ${{range.value}} ${{range.key}} | ||
|
||
- name: python3-as-test | ||
description: provides the tests for this package | ||
pipeline: | ||
- runs: | | ||
install -D -m755 "-t${{targets.contextdir}}/usr/bin" test-* | ||
|
||
update: | ||
enabled: false | ||
exclude-reason: No source to watch for the new versions - this is the source. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#!/bin/sh | ||
fail() { echo "FATAL:" "$0" "$@"; exit 9; } | ||
[ -n "${ENV_NAME}" ] || fail "invoked without ENV_NAME set" | ||
[ "$ENV_NAME" -ef "$0" ] && fail "invoked with ENV_NAME = $0" | ||
[ "${ENV_NAME}" != "${0##*/}" ] || fail "invoked with ENV_NAME = basename($0)" | ||
command -v "$ENV_NAME" >/dev/null || | ||
fail "invoked with ENV_NAME=$ENV_NAME, but $ENV_NAME not found in PATH" | ||
exec "${ENV_NAME}" "$@" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#!/bin/sh | ||
fail() { echo "FAIL:" "$@"; exit 1; } | ||
|
||
wrapper="$1" | ||
varname="$2" | ||
wrapped="$3" | ||
[ -x "$wrapper" ] || fail "$wrapper is not executable file" | ||
echo "PASS: $wrapper is executable" | ||
|
||
if env "$varname=true" "$wrapper"; then | ||
echo "PASS: $varname=true exited 0" | ||
else | ||
fail "$wrapper exited $? with $varname=true" | ||
fi | ||
|
||
if env "${varname}=false" "$wrapper"; then | ||
fail "$wrapper exited 0 with ${varname}=false" | ||
else | ||
echo "PASS: ${varname}=false exited $?" | ||
fi | ||
|
||
# test that bad values are caught by the wrapper | ||
# 'wrapped' here is 'python' or 'python3'. We want | ||
# to check that potential recursion is blocked. | ||
for val in bogus-prog-name $wrapped /usr/bin/$wrapped; do | ||
out=$(env "$varname=$val" "$wrapper" 2>&1) | ||
rc=$? | ||
case "$rc" in | ||
9) echo "PASS: $wrapper exited $rc with ${varname}=$val";; | ||
*) echo "output: $out"; | ||
fail "$wrapper exited $rc with ${varname}=$val";; | ||
esac | ||
done | ||
|
||
exit 0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#!/usr/bin/python3 | ||
import os, sys | ||
wrapper = sys.argv[1] | ||
fname = sys.argv[2] | ||
majmin = sys.argv[3] | ||
|
||
assert f"/usr/bin/python{majmin}" == sys.executable | ||
assert majmin == "%s.%s" % (sys.version_info.major, sys.version_info.minor) | ||
assert os.path.basename(sys.argv[0]) == os.path.basename(fname) | ||
assert len(sys.argv) == 4, f"expected 4 args found {sys.argv}" | ||
|
||
print(f"PASS: {wrapper} wrapped {sys.executable} successfully") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#!/bin/sh -e | ||
input="$1" | ||
outf="$2" | ||
d=$(dirname "$0") | ||
tmpl="$d/env-script.tmpl" | ||
|
||
[ -f "$tmpl" ] || | ||
{ echo "no 'wrapper-env.tmpl' in dir '$d/'"; exit 1; } | ||
|
||
mkdir -p "${outf%/*}" | ||
sed "s,ENV_NAME,$input,g" "$tmpl" > "$outf" | ||
|
||
chmod 755 "$outf" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#!/bin/sh -e | ||
input="$1" | ||
outf="$2" | ||
mkdir -p "${outf%/*}" | ||
|
||
cat >"$outf" <<END | ||
#!/bin/sh | ||
exec "$input" "\$@" | ||
END | ||
|
||
chmod 755 "$outf" |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.