Skip to content

Commit 421d7ac

Browse files
keukoyoctozepto
authored andcommitted
Support editable installation in all cases
An editable installation allows changes to be made to the source code directly, and have those changes applied immediately without having to reinstall. pip install -e /path/to/kolla-ansible Above is currently working only in virtualenv, but there is no reason to not allow in all cases. This is usefull for example when user is building his own docker container with editable kolla-ansible installed from git without virtualenv. Change-Id: I185f7c09c3f026fd6926a26001393f066ff1860d (cherry picked from commit 22a6765)
1 parent 6387e43 commit 421d7ac

File tree

1 file changed

+23
-5
lines changed

1 file changed

+23
-5
lines changed

tools/kolla-ansible

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ function check_environment_coherence {
2222
local ansible_python_cmdline
2323
# NOTE(yoctozepto): may have multiple parts
2424
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]))')
2526

2627
if ! $ansible_python_cmdline --version &>/dev/null; then
2728
echo "ERROR: Ansible Python is not functional." >&2
@@ -66,21 +67,38 @@ function check_environment_coherence {
6667

6768
function find_base_dir {
6869
local dir_name
70+
local python_dir
6971
dir_name=$(dirname "$0")
7072
# NOTE(yoctozepto): Fix the case where dir_name is a symlink and VIRTUAL_ENV might not be. This
7173
# happens with pyenv-virtualenv, see https://bugs.launchpad.net/kolla-ansible/+bug/1903887
7274
dir_name=$(readlink -e "$dir_name")
75+
python_dir="python${ansible_python_version}"
7376
if [ -z "$SNAP" ]; then
7477
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
7684
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
7891
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
8098
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
82100
# 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)"
84102
else
85103
BASEDIR="${VIRTUAL_ENV}/share/kolla-ansible"
86104
fi

0 commit comments

Comments
 (0)