Compare commits

..

3 Commits
main ... main

Author SHA1 Message Date
Zach D. LAMAZIERE
5036332666 auto bump compile-pythons 2023-12-12 09:00:03 +01:00
Zach D. LAMAZIERE
2810b5740f add patch version to bin 2023-12-12 09:00:03 +01:00
Zach D. LAMAZIERE
aa6cb4359c try with patch version if not
cf https://discuss.afpy.org/t/venv-direnv-prompt-bash-et-emacs-et-lsp/1845/4
2023-12-12 09:00:03 +01:00

View File

@ -1,108 +1,64 @@
#!/bin/bash
# Needs:
#
# sudo apt-get update; sudo apt-get install make build-essential libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm libncursesw5-dev xz-utils tk-dev libxml2-dev libxmlsec1-dev libffi-dev liblzma-dev
# Remerciements
###############
# This whole script was inspired from the great https://gitlab.com/python-devs/ci-images/, so Thanks Barry Warsaw.
# The automatic poking of last version is greatly inspired by z4c, thanks!
get-python-version()
_get_last_tag()
{
# Lists the /ftp/python/ directory searching for the most recent
# Python version directory matching a given pattern.
# Exemples:
#
# $ get-python-versions 3
# 3.13.0
# $ get-python-versions 3.10
# 3.10.14
# Such that /ftp/python/$(get-python-version 3.12) exists.
local URL="https://www.python.org/ftp/python/"
local PY_VERSION="$1"
wget -qO- "$URL" |
grep -o ">[0-9.]\+/<" |
sed "s/^>//;s|/<$||" |
sort --sort=version |
grep "^$PY_VERSION\." |
tail -n 1
[[ $1 =~ ^[23.]\.[0-9]+\.[0-9]+$ ]] && echo $1 || \
curl -s https://www.python.org/ftp/python/ \
| grep -o ">[0-9.]\+/<" \
| sed "s/^>//;s|/<$||" \
| grep ^$1 \
| sort --version-sort \
| tail -n 1
}
get-python-version-suffix()
_get_last_instable()
{
# Given a directory from /ftp/python/ like `3.12.0` gets the most
# recent version suffix for it.
# Examples:
#
# $ get-python-version-suffix 3.10.3
# # prints nothing, there's no pre-release for it.
#
# $ get-python-version-suffix 3.12.0
# # prints nothing, the last 3.12.0 IS 3.12.0
#
# $ get-python-version-suffix 3.13.0
# a5
local VERSION="$1"
versions="$(wget -qO- "https://www.python.org/ftp/python/$VERSION/" |
grep -o '>Python-[0-9]\.[0-9]\+\.[a-z0-9]\+.tgz<' |
sed "s/^>Python-//;s|.tgz<$||" |
sort --sort=version)"
if ! printf "%s" "$versions" | grep --quiet "^$VERSION$"
then
printf "%s" "$versions" | tail -n 1 | sed "s/^$VERSION//"
fi
[[ $1 =~ ^[23.]\.[0-9]+\.0$ ]] && \
curl -s https://www.python.org/ftp/python/$1/ \
| grep -o "Python-[0-9]\.[0-9]\+\.0[a-z0-9]\+" \
| sort \
| uniq \
| sed "s/Python-[0-9.]*//;" \
| sort --version-sort \
| tail -n 1
}
compile-python()
{
# Compile the given Python version. Accepts a "version pattern" as a filter, like:
# Inspired from the great https://gitlab.com/python-devs/ci-images/
# Thanks Barry Warsaw.
# compile-python 3 # The most recent Python 3 available
# # Beware it may pick an alpha version!
# Needs:
# sudo apt-get update; sudo apt-get install make build-essential libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm libncursesw5-dev xz-utils tk-dev libxml2-dev libxmlsec1-dev libffi-dev liblzma-dev
# compile-python 3.12 # Will compile the most recent 3.12 available
# # Can pick alpha/beta/rc versions if 3.12 is not released yet.
# compile-python 3.12.2 # Will compile the given version.
local PY_VERSION
local SUFFIX
local PY_VERSION=`_get_last_tag $1`
local BETA=${2:-`_get_last_instable $PY_VERSION`}
local URL="https://www.python.org/ftp/python"
PY_VERSION="$(get-python-version "$1")"
SUFFIX="$(get-python-version-suffix "$PY_VERSION")"
(
cd /tmp || return 1
wget -qO- "$URL/$PY_VERSION/Python-$PY_VERSION$SUFFIX.tgz" | tar -xzf - || (
[ -f $HOME/.local/bin/python${PY_VERSION}${BETA} ] || return 2
wget -qO- "$URL/$PY_VERSION/Python-$PY_VERSION$BETA.tgz" | tar -xzf - || (
echo "Version not found, check on $URL."
)
[ -d "Python-$PY_VERSION$SUFFIX" ] && (cd "Python-$PY_VERSION$SUFFIX"; ./configure --prefix="$HOME/.local/" && make -j "$(nproc)" && make altinstall) &&
rm -r "Python-$PY_VERSION$SUFFIX"
[ -d "Python-$PY_VERSION$BETA" ] && (cd "Python-$PY_VERSION$BETA"; ./configure --prefix="$HOME/.local/" && make -j "$(nproc)" && make altinstall) &&
rm -r "Python-$PY_VERSION$BETA" &&
cp $HOME/.local/bin/python${PY_VERSION%.*} $HOME/.local/bin/python${PY_VERSION}${BETA}
)
}
compile-pythons()
{
# Compiles a usefull set of Python versions.
compile-python 3.7 &
compile-python 3.8 &
compile-python 3.9 &
compile-python 3.10 &
compile-python 3.11 &
compile-python 3.12 &
compile-python 3.13 &
compile-python 3.7.17 &
compile-python 3.8.18 &
compile-python 3.9.18 &
compile-python 3.10.13 &
compile-python 3.11.5 &
compile-python 3.12.0 &
compile-python 3.13.0 a2 &
wait
}