strokirk / pyenv-autoenv

pyenv-autoenv is a pyenv plugin that will automatically create and upgrade your project's virtualenv.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

stackless-3.7.5 picked when specifying no version

EmilStenstrom opened this issue · comments

When running pyenv autoenv with no parameters stackless-3.7.5 is installed. Should it be the latest python version?

(boktraven) 2021-04-08 23:21:05 ~/Projects/boktraven $ python --version
Python 3.9.1

(boktraven) 2021-04-08 23:17:55 ~/Projects/boktraven $ ls
Procfile               download_database.sh  runtime.txt       urls.py
README.md              manage.py             settings.py       util
__init__.py            requirements-dev.in   settings_dev.py   views.py
__pycache__            requirements-dev.txt  setup.cfg         wsgi.py
data.xml.zip           requirements.in       static
books                  requirements.txt      templates
context_processors.py  run.py                test_settings.py

(boktraven) 2021-04-08 23:16:03 ~/Projects/boktraven $ pyenv autoenv
Picking 'boktraven' for virtualenv name
Using Python version stackless-3.7.5
Downloading v3.7.5-slp.tar.gz...
^C

Interesting, I couldn't reproduce it locally when I tried.

What is the output of pyenv --version and pyenv --debug autoenv?

Oh, I didn't know about the --debug flag, thanks. Here's the full log:

+(/home/emilstenstrom/.pyenv/bin/pyenv:118): '[' -z /home/emilstenstrom/.pyenv/plugins/pyenv-autoenv/bin/pyenv-autoenv ']'
+(/home/emilstenstrom/.pyenv/bin/pyenv:126): shift 1
+(/home/emilstenstrom/.pyenv/bin/pyenv:127): '[' '' = --help ']'
+(/home/emilstenstrom/.pyenv/bin/pyenv:134): exec /home/emilstenstrom/.pyenv/plugins/pyenv-autoenv/bin/pyenv-autoenv
+(/home/emilstenstrom/.pyenv/plugins/pyenv-autoenv/bin/pyenv-autoenv:18): '[' '' = --complete ']'
+(/home/emilstenstrom/.pyenv/plugins/pyenv-autoenv/bin/pyenv-autoenv:54): parse_options
+(/home/emilstenstrom/.pyenv/plugins/pyenv-autoenv/bin/pyenv-autoenv:32): parse_options(): OPTIONS=()
+(/home/emilstenstrom/.pyenv/plugins/pyenv-autoenv/bin/pyenv-autoenv:33): parse_options(): ARGUMENTS=()
+(/home/emilstenstrom/.pyenv/plugins/pyenv-autoenv/bin/pyenv-autoenv:34): parse_options(): local arg option index
+(/home/emilstenstrom/.pyenv/plugins/pyenv-autoenv/bin/pyenv-autoenv:80): '[' -z '' ']'
+++(/home/emilstenstrom/.pyenv/plugins/pyenv-autoenv/bin/pyenv-autoenv:81): pwd
++(/home/emilstenstrom/.pyenv/plugins/pyenv-autoenv/bin/pyenv-autoenv:81): basename /home/emilstenstrom/Projects/boktraven
+(/home/emilstenstrom/.pyenv/plugins/pyenv-autoenv/bin/pyenv-autoenv:81): VENV_NAME=boktraven
+(/home/emilstenstrom/.pyenv/plugins/pyenv-autoenv/bin/pyenv-autoenv:82): echo 'Picking '\''boktraven'\'' for virtualenv name'
Picking 'boktraven' for virtualenv name
+(/home/emilstenstrom/.pyenv/plugins/pyenv-autoenv/bin/pyenv-autoenv:85): '[' -z '' ']'
++(/home/emilstenstrom/.pyenv/plugins/pyenv-autoenv/bin/pyenv-autoenv:86): python-build --definitions
++(/home/emilstenstrom/.pyenv/plugins/pyenv-autoenv/bin/pyenv-autoenv:86): grep '^\d'
++(/home/emilstenstrom/.pyenv/plugins/pyenv-autoenv/bin/pyenv-autoenv:86): grep -v -- -dev
++(/home/emilstenstrom/.pyenv/plugins/pyenv-autoenv/bin/pyenv-autoenv:86): tail -1
+(/home/emilstenstrom/.pyenv/plugins/python-build/bin/python-build:24): exec
+(/home/emilstenstrom/.pyenv/plugins/python-build/bin/python-build:57): lib --definitions
+(/home/emilstenstrom/.pyenv/plugins/python-build/bin/python-build:51): lib(): '[' --definitions == --lib ']'
+(/home/emilstenstrom/.pyenv/plugins/python-build/bin/python-build:1838): unset VERBOSE
+(/home/emilstenstrom/.pyenv/plugins/python-build/bin/python-build:1839): unset KEEP_BUILD_PATH
+(/home/emilstenstrom/.pyenv/plugins/python-build/bin/python-build:1840): unset HAS_PATCH
+(/home/emilstenstrom/.pyenv/plugins/python-build/bin/python-build:1841): unset DEBUG
+(/home/emilstenstrom/.pyenv/plugins/python-build/bin/python-build:1842): unset IPV4
+(/home/emilstenstrom/.pyenv/plugins/python-build/bin/python-build:1843): unset IPV6
++(/home/emilstenstrom/.pyenv/plugins/python-build/bin/python-build:1845): abs_dirname /home/emilstenstrom/.pyenv/plugins/python-build/bin/python-build
++(/home/emilstenstrom/.pyenv/plugins/python-build/bin/python-build:65): abs_dirname(): local path=/home/emilstenstrom/.pyenv/plugins/python-build/bin/python-build
++(/home/emilstenstrom/.pyenv/plugins/python-build/bin/python-build:69): abs_dirname(): '[' -n /home/emilstenstrom/.pyenv/plugins/python-build/bin/python-build ']'
++(/home/emilstenstrom/.pyenv/plugins/python-build/bin/python-build:70): abs_dirname(): cd_path=/home/emilstenstrom/.pyenv/plugins/python-build/bin
++(/home/emilstenstrom/.pyenv/plugins/python-build/bin/python-build:71): abs_dirname(): [[ /home/emilstenstrom/.pyenv/plugins/python-build/bin != \/\h\o\m\e\/\e\m\i\l\s\t\e\n\s\t\r\o\m\/\.\p\y\e\n\v\/\p\l\u\g\i\n\s\/\p\y\t\h\o\n\-\b\u\i\l\d\/\b\i\n\/\p\y\t\h\o\n\-\b\u\i\l\d ]]
++(/home/emilstenstrom/.pyenv/plugins/python-build/bin/python-build:72): abs_dirname(): cd /home/emilstenstrom/.pyenv/plugins/python-build/bin
++(/home/emilstenstrom/.pyenv/plugins/python-build/bin/python-build:74): abs_dirname(): name=python-build
+++(/home/emilstenstrom/.pyenv/plugins/python-build/bin/python-build:75): abs_dirname(): resolve_link python-build
++++(/home/emilstenstrom/.pyenv/plugins/python-build/bin/python-build:61): resolve_link(): type -p greadlink readlink
++++(/home/emilstenstrom/.pyenv/plugins/python-build/bin/python-build:61): resolve_link(): head -1
+++(/home/emilstenstrom/.pyenv/plugins/python-build/bin/python-build:61): resolve_link(): /usr/bin/readlink python-build
+++(/home/emilstenstrom/.pyenv/plugins/python-build/bin/python-build:75): abs_dirname(): true
++(/home/emilstenstrom/.pyenv/plugins/python-build/bin/python-build:75): abs_dirname(): path=
++(/home/emilstenstrom/.pyenv/plugins/python-build/bin/python-build:69): abs_dirname(): '[' -n '' ']'
++(/home/emilstenstrom/.pyenv/plugins/python-build/bin/python-build:78): abs_dirname(): echo /home/emilstenstrom/.pyenv/plugins/python-build/bin
+(/home/emilstenstrom/.pyenv/plugins/python-build/bin/python-build:1845): PYTHON_BUILD_INSTALL_PREFIX=/home/emilstenstrom/.pyenv/plugins/python-build/bin/..
+(/home/emilstenstrom/.pyenv/plugins/python-build/bin/python-build:1847): IFS=:
+(/home/emilstenstrom/.pyenv/plugins/python-build/bin/python-build:1847): PYTHON_BUILD_DEFINITIONS=($PYTHON_BUILD_DEFINITIONS ${PYTHON_BUILD_ROOT:-$PYTHON_BUILD_INSTALL_PREFIX}/share/python-build)
+(/home/emilstenstrom/.pyenv/plugins/python-build/bin/python-build:1848): IFS='
'
+(/home/emilstenstrom/.pyenv/plugins/python-build/bin/python-build:1850): parse_options --definitions
+(/home/emilstenstrom/.pyenv/plugins/python-build/bin/python-build:29): parse_options(): OPTIONS=()
+(/home/emilstenstrom/.pyenv/plugins/python-build/bin/python-build:30): parse_options(): ARGUMENTS=()
+(/home/emilstenstrom/.pyenv/plugins/python-build/bin/python-build:31): parse_options(): local arg option index
+(/home/emilstenstrom/.pyenv/plugins/python-build/bin/python-build:33): parse_options(): for arg in "$@"
+(/home/emilstenstrom/.pyenv/plugins/python-build/bin/python-build:34): parse_options(): '[' - = - ']'
+(/home/emilstenstrom/.pyenv/plugins/python-build/bin/python-build:35): parse_options(): '[' - = - ']'
+(/home/emilstenstrom/.pyenv/plugins/python-build/bin/python-build:36): parse_options(): OPTIONS[${#OPTIONS[*]}]=definitions
+(/home/emilstenstrom/.pyenv/plugins/python-build/bin/python-build:1852): for option in "${OPTIONS[@]}"
+(/home/emilstenstrom/.pyenv/plugins/python-build/bin/python-build:1853): case "$option" in
+(/home/emilstenstrom/.pyenv/plugins/python-build/bin/python-build:1860): list_definitions
+(/home/emilstenstrom/.pyenv/plugins/python-build/bin/python-build:1826): list_definitions(): for DEFINITION_DIR in "${PYTHON_BUILD_DEFINITIONS[@]}"
+(/home/emilstenstrom/.pyenv/plugins/python-build/bin/python-build:1827): list_definitions(): '[' -d /home/emilstenstrom/.pyenv/plugins/python-build/bin/../share/python-build ']'
+(/home/emilstenstrom/.pyenv/plugins/python-build/bin/python-build:1829): list_definitions(): sort_versions
+(/home/emilstenstrom/.pyenv/plugins/python-build/bin/python-build:1829): list_definitions(): uniq
+(/home/emilstenstrom/.pyenv/plugins/python-build/bin/python-build:1827): list_definitions(): ls /home/emilstenstrom/.pyenv/plugins/python-build/bin/../share/python-build
+(/home/emilstenstrom/.pyenv/plugins/python-build/bin/python-build:1833): sort_versions(): sed 'h; s/[+-]/./g; s/.p\([[:digit:]]\)/.z.\1/; s/$/.z/; G; s/\n/ /'
+(/home/emilstenstrom/.pyenv/plugins/python-build/bin/python-build:1827): list_definitions(): grep -xv patches
+(/home/emilstenstrom/.pyenv/plugins/python-build/bin/python-build:1834): sort_versions(): LC_ALL=C
+(/home/emilstenstrom/.pyenv/plugins/python-build/bin/python-build:1834): sort_versions(): sort -t. -k 1,1 -k 2,2n -k 3,3n -k 4,4n -k 5,5n
+(/home/emilstenstrom/.pyenv/plugins/python-build/bin/python-build:1834): sort_versions(): awk '{print $2}'
+(/home/emilstenstrom/.pyenv/plugins/python-build/bin/python-build:1861): exit 0
+(/home/emilstenstrom/.pyenv/plugins/pyenv-autoenv/bin/pyenv-autoenv:86): DESIRED_VENV_VERSION=
++(/home/emilstenstrom/.pyenv/plugins/pyenv-autoenv/bin/pyenv-autoenv:88): python-build --definitions
++(/home/emilstenstrom/.pyenv/plugins/pyenv-autoenv/bin/pyenv-autoenv:88): grep '^'
++(/home/emilstenstrom/.pyenv/plugins/pyenv-autoenv/bin/pyenv-autoenv:88): tail -1
+(/home/emilstenstrom/.pyenv/plugins/python-build/bin/python-build:24): exec
+(/home/emilstenstrom/.pyenv/plugins/python-build/bin/python-build:57): lib --definitions
+(/home/emilstenstrom/.pyenv/plugins/python-build/bin/python-build:51): lib(): '[' --definitions == --lib ']'
+(/home/emilstenstrom/.pyenv/plugins/python-build/bin/python-build:1838): unset VERBOSE
+(/home/emilstenstrom/.pyenv/plugins/python-build/bin/python-build:1839): unset KEEP_BUILD_PATH
+(/home/emilstenstrom/.pyenv/plugins/python-build/bin/python-build:1840): unset HAS_PATCH
+(/home/emilstenstrom/.pyenv/plugins/python-build/bin/python-build:1841): unset DEBUG
+(/home/emilstenstrom/.pyenv/plugins/python-build/bin/python-build:1842): unset IPV4
+(/home/emilstenstrom/.pyenv/plugins/python-build/bin/python-build:1843): unset IPV6
++(/home/emilstenstrom/.pyenv/plugins/python-build/bin/python-build:1845): abs_dirname /home/emilstenstrom/.pyenv/plugins/python-build/bin/python-build
++(/home/emilstenstrom/.pyenv/plugins/python-build/bin/python-build:65): abs_dirname(): local path=/home/emilstenstrom/.pyenv/plugins/python-build/bin/python-build
++(/home/emilstenstrom/.pyenv/plugins/python-build/bin/python-build:69): abs_dirname(): '[' -n /home/emilstenstrom/.pyenv/plugins/python-build/bin/python-build ']'
++(/home/emilstenstrom/.pyenv/plugins/python-build/bin/python-build:70): abs_dirname(): cd_path=/home/emilstenstrom/.pyenv/plugins/python-build/bin
++(/home/emilstenstrom/.pyenv/plugins/python-build/bin/python-build:71): abs_dirname(): [[ /home/emilstenstrom/.pyenv/plugins/python-build/bin != \/\h\o\m\e\/\e\m\i\l\s\t\e\n\s\t\r\o\m\/\.\p\y\e\n\v\/\p\l\u\g\i\n\s\/\p\y\t\h\o\n\-\b\u\i\l\d\/\b\i\n\/\p\y\t\h\o\n\-\b\u\i\l\d ]]
++(/home/emilstenstrom/.pyenv/plugins/python-build/bin/python-build:72): abs_dirname(): cd /home/emilstenstrom/.pyenv/plugins/python-build/bin
++(/home/emilstenstrom/.pyenv/plugins/python-build/bin/python-build:74): abs_dirname(): name=python-build
+++(/home/emilstenstrom/.pyenv/plugins/python-build/bin/python-build:75): abs_dirname(): resolve_link python-build
++++(/home/emilstenstrom/.pyenv/plugins/python-build/bin/python-build:61): resolve_link(): type -p greadlink readlink
++++(/home/emilstenstrom/.pyenv/plugins/python-build/bin/python-build:61): resolve_link(): head -1
+++(/home/emilstenstrom/.pyenv/plugins/python-build/bin/python-build:61): resolve_link(): /usr/bin/readlink python-build
+++(/home/emilstenstrom/.pyenv/plugins/python-build/bin/python-build:75): abs_dirname(): true
++(/home/emilstenstrom/.pyenv/plugins/python-build/bin/python-build:75): abs_dirname(): path=
++(/home/emilstenstrom/.pyenv/plugins/python-build/bin/python-build:69): abs_dirname(): '[' -n '' ']'
++(/home/emilstenstrom/.pyenv/plugins/python-build/bin/python-build:78): abs_dirname(): echo /home/emilstenstrom/.pyenv/plugins/python-build/bin
+(/home/emilstenstrom/.pyenv/plugins/python-build/bin/python-build:1845): PYTHON_BUILD_INSTALL_PREFIX=/home/emilstenstrom/.pyenv/plugins/python-build/bin/..
+(/home/emilstenstrom/.pyenv/plugins/python-build/bin/python-build:1847): IFS=:
+(/home/emilstenstrom/.pyenv/plugins/python-build/bin/python-build:1847): PYTHON_BUILD_DEFINITIONS=($PYTHON_BUILD_DEFINITIONS ${PYTHON_BUILD_ROOT:-$PYTHON_BUILD_INSTALL_PREFIX}/share/python-build)
+(/home/emilstenstrom/.pyenv/plugins/python-build/bin/python-build:1848): IFS='
'
+(/home/emilstenstrom/.pyenv/plugins/python-build/bin/python-build:1850): parse_options --definitions
+(/home/emilstenstrom/.pyenv/plugins/python-build/bin/python-build:29): parse_options(): OPTIONS=()
+(/home/emilstenstrom/.pyenv/plugins/python-build/bin/python-build:30): parse_options(): ARGUMENTS=()
+(/home/emilstenstrom/.pyenv/plugins/python-build/bin/python-build:31): parse_options(): local arg option index
+(/home/emilstenstrom/.pyenv/plugins/python-build/bin/python-build:33): parse_options(): for arg in "$@"
+(/home/emilstenstrom/.pyenv/plugins/python-build/bin/python-build:34): parse_options(): '[' - = - ']'
+(/home/emilstenstrom/.pyenv/plugins/python-build/bin/python-build:35): parse_options(): '[' - = - ']'
+(/home/emilstenstrom/.pyenv/plugins/python-build/bin/python-build:36): parse_options(): OPTIONS[${#OPTIONS[*]}]=definitions
+(/home/emilstenstrom/.pyenv/plugins/python-build/bin/python-build:1852): for option in "${OPTIONS[@]}"
+(/home/emilstenstrom/.pyenv/plugins/python-build/bin/python-build:1853): case "$option" in
+(/home/emilstenstrom/.pyenv/plugins/python-build/bin/python-build:1860): list_definitions
+(/home/emilstenstrom/.pyenv/plugins/python-build/bin/python-build:1826): list_definitions(): for DEFINITION_DIR in "${PYTHON_BUILD_DEFINITIONS[@]}"
+(/home/emilstenstrom/.pyenv/plugins/python-build/bin/python-build:1827): list_definitions(): '[' -d /home/emilstenstrom/.pyenv/plugins/python-build/bin/../share/python-build ']'
+(/home/emilstenstrom/.pyenv/plugins/python-build/bin/python-build:1829): list_definitions(): sort_versions
+(/home/emilstenstrom/.pyenv/plugins/python-build/bin/python-build:1829): list_definitions(): uniq
+(/home/emilstenstrom/.pyenv/plugins/python-build/bin/python-build:1833): sort_versions(): sed 'h; s/[+-]/./g; s/.p\([[:digit:]]\)/.z.\1/; s/$/.z/; G; s/\n/ /'
+(/home/emilstenstrom/.pyenv/plugins/python-build/bin/python-build:1834): sort_versions(): LC_ALL=C
+(/home/emilstenstrom/.pyenv/plugins/python-build/bin/python-build:1834): sort_versions(): sort -t. -k 1,1 -k 2,2n -k 3,3n -k 4,4n -k 5,5n
+(/home/emilstenstrom/.pyenv/plugins/python-build/bin/python-build:1827): list_definitions(): ls /home/emilstenstrom/.pyenv/plugins/python-build/bin/../share/python-build
+(/home/emilstenstrom/.pyenv/plugins/python-build/bin/python-build:1827): list_definitions(): grep -xv patches
+(/home/emilstenstrom/.pyenv/plugins/python-build/bin/python-build:1834): sort_versions(): awk '{print $2}'
+(/home/emilstenstrom/.pyenv/plugins/python-build/bin/python-build:1861): exit 0
+(/home/emilstenstrom/.pyenv/plugins/pyenv-autoenv/bin/pyenv-autoenv:88): VENV_VERSION=stackless-3.7.5
+(/home/emilstenstrom/.pyenv/plugins/pyenv-autoenv/bin/pyenv-autoenv:89): '[' -z stackless-3.7.5 ']'
+(/home/emilstenstrom/.pyenv/plugins/pyenv-autoenv/bin/pyenv-autoenv:94): echo 'Using Python version stackless-3.7.5'
Using Python version stackless-3.7.5

Ah, it's the last python in the list of definitions:


$ /home/emilstenstrom/.pyenv/plugins/python-build/bin/python-build --definitions
2.1.3
2.2.3
2.3.7
2.4.0
2.4.1
2.4.2
2.4.3
2.4.4
2.4.5
2.4.6
2.5.0
2.5.1
2.5.2
2.5.3
2.5.4
2.5.5
2.5.6
2.6.6
2.6.7
2.6.8
2.6.9
2.7.0

[snip]

pyston-0.6.1
stackless-dev
stackless-2.7-dev
stackless-2.7.2
stackless-2.7.3
stackless-2.7.4
stackless-2.7.5
stackless-2.7.6
stackless-2.7.7
stackless-2.7.8
stackless-2.7.9
stackless-2.7.10
stackless-2.7.11
stackless-2.7.12
stackless-2.7.14
stackless-3.2.2
stackless-3.2.5
stackless-3.3.5
stackless-3.3.7
stackless-3.4-dev
stackless-3.4.2
stackless-3.4.7
stackless-3.5.4
stackless-3.7.5

Another try at a minimally reproducable testcase:

$ printf "3.9.4\nstackless-3.7.5" | sed 'h; s/[+-]/./g; s/.p\([[:di
git:]]\)/.z.\1/; s/$/.z/; G; s/\n/ /' | sort -t. -k 1,1 -k 2,2n -k 3,3n -k 4,4n -k 5,5n
3.9.4.z 3.9.4
stackless.3.7.5.z stackless-3.7.5

The sed and sort commands are taken from the output --debug above.

I find this line interesting:

+(/home/emilstenstrom/.pyenv/plugins/pyenv-autoenv/bin/pyenv-autoenv:86): DESIRED_VENV_VERSION=

It seems that the regex doesn't capture the "number-only" python versions.

Could you check the output of this command?

VENV_OPTIONS=$(python-build --definitions)
DESIRED_VENV_PYTHON=$(printf "%s\n" "${VENV_OPTIONS[@]}" | grep "^\d\.\d\.\d$" | grep -v -- "-dev" | tail -1)
echo $DESIRED_VENV_PYTHON

DESIRED_VENV_PYTHON is empty after that line. After some debugging it's because grep doesn't do regex by default. "\d" matches the letter "d", not digits. Adding -P (perl regex) fixes this for me.

$ DESIRED_VENV_PYTHON=$(printf "%s\n" "${VENV_OPTIONS[@]}" | grep -P "^\d\.\d\.\d$" | grep -v -- "
-dev" | tail -1)
$ echo $DESIRED_VENV_PYTHON
3.9.4
$ grep --version
grep (GNU grep) 3.4
Copyright (C) 2020 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Written by Mike Haertel and others; see
<https://git.sv.gnu.org/cgit/grep.git/tree/AUTHORS>.

Thanks! That explains the mystery.

I'll probably fix this by implementing the Python-version-picking in Python - more comfortable and consistent than using bash.

Works great! :) Thank you!