Convert to safe name in lib_installed_from_git

The 'pip list' command prints the "safe name" which converts _'s to
-'s amongst other things; e.g. glance_store becomes

  "glance-store             0.21.1.dev22      /opt/stack/glance_store"

Because people may use these more familiar "file system" names in
LIBS_FROM_GIT automatically convert names when checking if libraries
are installed.

Change-Id: I30524f80a341f38dfa794a8f629d859e85a4a448
This commit is contained in:
DamonLi 2017-11-23 10:05:46 +08:00 committed by Ian Wienand
parent b5fb7fd627
commit 007f588f27

View File

@ -406,6 +406,9 @@ function use_library_from_git {
# determine if a package was installed from git # determine if a package was installed from git
function lib_installed_from_git { function lib_installed_from_git {
local name=$1 local name=$1
local safe_name
safe_name=$(python -c "from pkg_resources import safe_name; \
print(safe_name('${name}'))")
# Note "pip freeze" doesn't always work here, because it tries to # Note "pip freeze" doesn't always work here, because it tries to
# be smart about finding the remote of the git repo the package # be smart about finding the remote of the git repo the package
# was installed from. This doesn't work with zuul which clones # was installed from. This doesn't work with zuul which clones
@ -419,7 +422,7 @@ function lib_installed_from_git {
# bashate 0.5.2.dev19 /tmp/env/src/bashate # bashate 0.5.2.dev19 /tmp/env/src/bashate
# Thus we check the third column to see if we're installed from # Thus we check the third column to see if we're installed from
# some local place. # some local place.
[[ -n $(pip list --format=columns 2>/dev/null | awk "/^$name/ {print \$3}") ]] [[ -n $(pip list --format=columns 2>/dev/null | awk "/^$safe_name/ {print \$3}") ]]
} }
# check that everything that's in LIBS_FROM_GIT was actually installed # check that everything that's in LIBS_FROM_GIT was actually installed