try with patch version if not #1

Closed
z4c wants to merge 3 commits from z4c/compile-python:main into main
First-time contributor
cf https://discuss.afpy.org/t/venv-direnv-prompt-bash-et-emacs-et-lsp/1845/4
z4c force-pushed main from 2ec4c849a7 to 278ed6cb13 2023-12-10 19:32:44 +00:00 Compare
mdk reviewed 2023-12-10 19:39:43 +00:00
@ -16,2 +22,3 @@
wget -qO- "$URL/$PY_VERSION/Python-$PY_VERSION$BETA.tgz" | tar -xzf - || (
echo "Version not found, check on $URL."
echo "Version '$PY_VERSION' not found, check on $URL."
echo "Ttrying something else." && compile-python `_get_last_patch $PY_VERSION`
Owner

Is this line to "autocorrect" from 3.12 to 3.12.0? (Or from 3.11 to 3.11.7?
(Beware of the double t)

Is this line to "autocorrect" from `3.12` to `3.12.0`? (Or from `3.11` to `3.11.7`? (Beware of the double t)
Author
First-time contributor

yep. that's it.

_get_last_patch 3.12
=> 3.12.1
yep. that's it. ``` _get_last_patch 3.12 => 3.12.1 ```
mdk reviewed 2023-12-10 19:42:42 +00:00
@ -2,1 +2,4 @@
_get_last_patch()
{
curl -s https://www.python.org/ftp/python/ | grep -o ">[0-9.]\+/<" | sed "s/^>//;s|/<$||"| grep ^$1 | sort --version-sort | tail -n 1
Owner

I'm a bit sad it does not work with alpha releases.

compile-python 3.13 may try compile-python 3.13.0 but it does not exists, only the alphas exists.

Oh does it make this implem run in an infinite loop? :D

I'm a bit sad it does not work with alpha releases. `compile-python 3.13` may try `compile-python 3.13.0` but it does not exists, only the alphas exists. Oh does it make this implem run in an infinite loop? :D
Owner

I dislike adding complexity.

But to be honest, if your "get last patch" function could grab betas versions, it would greatly simplify compile-pythons, at least its maintenance, as it would "auto-bump", which is a nice feature...

I dislike adding complexity. But to be honest, if your "get last patch" function could grab betas versions, it would greatly simplify `compile-pythons`, at least its maintenance, as it would "auto-bump", which is a nice feature...
Author
First-time contributor

I dislike adding complexity.

But to be honest, if your "get last patch" function could grab betas versions, it would greatly simplify compile-pythons, at least its maintenance, as it would "auto-bump", which is a nice feature...

You right @mdk
Done.

> I dislike adding complexity. > > But to be honest, if your "get last patch" function could grab betas versions, it would greatly simplify `compile-pythons`, at least its maintenance, as it would "auto-bump", which is a nice feature... You right @mdk Done.
z4c force-pushed main from 9ce740cf73 to 7bfcdc9a0a 2023-12-11 11:41:35 +00:00 Compare
z4c force-pushed main from 7bfcdc9a0a to 5036332666 2023-12-12 08:00:11 +00:00 Compare
Owner

Hum, there's un problème, compile-python 3.11.0 will compile 3.11.0rc2 instead of 3.11.0.

I can propose:

_get_last_instable()
{
    local VERSIONS

    if [[ $1 =~ ^[23.]\.[0-9]+\.0$ ]]
    then
        VERSIONS="$(
            curl -s https://www.python.org/ftp/python/$1/ |
            sed -n 's/.*"Python-[0-9.]\+\.0\([^"]*\).tgz".*/\1/p' |
            sort --version-sort
        )"
        if ! grep -q "^$" <<< "$VERSIONS"
        then
            printf "%s\n" "$VERSIONS" |
                sort --version-sort |
                tail -n 1
        fi
    fi
}

Also please simplify compile-pythons to:

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 &
    wait
}

as compile-python correctly chooses the right version.

Did you know you can avoid backslashes at end of line by putting the | instead? It's unambiguous to bash, if the line ends with a | it's not the end of it.

Hum, there's un problème, `compile-python 3.11.0` will compile `3.11.0rc2` instead of `3.11.0`. I can propose: ```bash _get_last_instable() { local VERSIONS if [[ $1 =~ ^[23.]\.[0-9]+\.0$ ]] then VERSIONS="$( curl -s https://www.python.org/ftp/python/$1/ | sed -n 's/.*"Python-[0-9.]\+\.0\([^"]*\).tgz".*/\1/p' | sort --version-sort )" if ! grep -q "^$" <<< "$VERSIONS" then printf "%s\n" "$VERSIONS" | sort --version-sort | tail -n 1 fi fi } ``` Also please simplify `compile-pythons` to: ```bash 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 & wait } ``` as `compile-python` correctly chooses the right version. Did you know you can avoid backslashes at end of line by putting the `|` instead? It's unambiguous to bash, if the line ends with a `|` it's not the end of it.
Owner

A bit of sed-fu for the fun, for the _get_last_tag function, feel free to use it or not:

    [[ $1 =~ ^[23.]\.[0-9]+\.[0-9]+$ ]] && echo $1 || \
            curl -s https://www.python.org/ftp/python/ |
                sed -n "s|.*\">\($1\.[0-9.]\+\)/<.*|\1|p" |
                sort --version-sort |
                tail -n 1
A bit of sed-fu for the fun, for the `_get_last_tag` function, feel free to use it or not: ```bash [[ $1 =~ ^[23.]\.[0-9]+\.[0-9]+$ ]] && echo $1 || \ curl -s https://www.python.org/ftp/python/ | sed -n "s|.*\">\($1\.[0-9.]\+\)/<.*|\1|p" | sort --version-sort | tail -n 1 ```
Owner

J'ai encore joué avec ta PR, j'ai fini par faire quelque chose qui me convient, j'ai fini aussi les changements dans compile-pythons pour ne plus avoir à maintenir ça à la main, et j'ai tenté de documenter un poil.

Merci beaucoup pour la PR :)

J'ai encore joué avec ta PR, j'ai fini par faire quelque chose qui me convient, j'ai fini aussi les changements dans `compile-pythons` pour ne plus avoir à maintenir ça à la main, et j'ai tenté de documenter un poil. Merci beaucoup pour la PR :)
mdk closed this pull request 2024-04-02 16:30:57 +00:00

Pull request closed

Sign in to join this conversation.
No reviewers
No Label
No Milestone
No project
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: mdk/compile-python#1
No description provided.