@@ -22,6 +22,7 @@ function check_environment_coherence {
22
22
local ansible_python_cmdline
23
23
# NOTE(yoctozepto): may have multiple parts
24
24
ansible_python_cmdline=${ansible_shebang_line# \#\! }
25
+ ansible_python_version=$( $ansible_python_cmdline -c ' import sys; print(str(sys.version_info[0])+"."+str(sys.version_info[1]))' )
25
26
26
27
if ! $ansible_python_cmdline --version & > /dev/null; then
27
28
echo " ERROR: Ansible Python is not functional." >&2
@@ -66,21 +67,38 @@ function check_environment_coherence {
66
67
67
68
function find_base_dir {
68
69
local dir_name
70
+ local python_dir
69
71
dir_name=$( dirname " $0 " )
70
72
# NOTE(yoctozepto): Fix the case where dir_name is a symlink and VIRTUAL_ENV might not be. This
71
73
# happens with pyenv-virtualenv, see https://bugs.launchpad.net/kolla-ansible/+bug/1903887
72
74
dir_name=$( readlink -e " $dir_name " )
75
+ python_dir=" python${ansible_python_version} "
73
76
if [ -z " $SNAP " ]; then
74
77
if [[ ${dir_name} == " /usr/bin" ]]; then
75
- BASEDIR=/usr/share/kolla-ansible
78
+ if test -f /usr/lib/${python_dir} /* -packages/kolla-ansible.egg-link; then
79
+ # Editable install.
80
+ BASEDIR=" $( head -n1 /usr/lib/${python_dir} /* -packages/kolla-ansible.egg-link) "
81
+ else
82
+ BASEDIR=/usr/share/kolla-ansible
83
+ fi
76
84
elif [[ ${dir_name} == " /usr/local/bin" ]]; then
77
- BASEDIR=/usr/local/share/kolla-ansible
85
+ if test -f /usr/local/lib/${python_dir} /* -packages/kolla-ansible.egg-link; then
86
+ # Editable install.
87
+ BASEDIR=" $( head -n1 /usr/local/lib/${python_dir} /* -packages/kolla-ansible.egg-link) "
88
+ else
89
+ BASEDIR=/usr/local/share/kolla-ansible
90
+ fi
78
91
elif [[ ${dir_name} == ~ /.local/bin ]]; then
79
- BASEDIR=~ /.local/share/kolla-ansible
92
+ if test -f ~ /.local/lib/${python_dir} /* -packages/kolla-ansible.egg-link; then
93
+ # Editable install.
94
+ BASEDIR=" $( head -n1 ~ /.local/lib/${python_dir} /* -packages/kolla-ansible.egg-link) "
95
+ else
96
+ BASEDIR=~ /.local/share/kolla-ansible
97
+ fi
80
98
elif [[ -n ${VIRTUAL_ENV} ]] && [[ ${dir_name} == " $( readlink -e " ${VIRTUAL_ENV} /bin" ) " ]]; then
81
- if test -f ${VIRTUAL_ENV} /lib/python * /site-packages/kolla-ansible.egg-link; then
99
+ if test -f ${VIRTUAL_ENV} /lib/${python_dir} /site-packages/kolla-ansible.egg-link; then
82
100
# Editable install.
83
- BASEDIR=" $( head -n1 ${VIRTUAL_ENV} /lib/python * /site -packages/kolla-ansible.egg-link) "
101
+ BASEDIR=" $( head -n1 ${VIRTUAL_ENV} /lib/${python_dir} / * -packages/kolla-ansible.egg-link) "
84
102
else
85
103
BASEDIR=" ${VIRTUAL_ENV} /share/kolla-ansible"
86
104
fi
0 commit comments