Files
bf81732b129675d667d2285859f32db16ef5e2f5
devstack /inc /python

286 lines
8.0 KiB
Plaintext
Raw Normal View History

#
# **inc/python** - Python-related functions
#
# Support for pip/setuptools interfaces and virtual environments
#
# External functions used:
# - GetOSVersion
# - is_fedora
# - is_suse
# - safe_chown
# Save trace setting
INC_PY_TRACE=$(set +o | grep xtrace)
set +o xtrace
# PROJECT_VENV contains the name of the virtual enviromnet for each
# project. A null value installs to the system Python directories.
declare -A PROJECT_VENV
# ================
# Get the path to the pip command.
# get_pip_command
function get_pip_command {
which pip || which pip-python
if [ $? -ne 0 ]; then
die $LINENO "Unable to find pip; cannot continue"
fi
}
# Get the path to the direcotry where python executables are installed.
# get_python_exec_prefix
function get_python_exec_prefix {
xtrace=$(set +o | grep xtrace)
if [[ -z "$os_PACKAGE" ]]; then
GetOSVersion
fi
$xtrace
echo "/usr/bin"
else
echo "/usr/local/bin"
fi
}
# from the global-requirements specification.
#
# Uses globals ``REQUIREMENTS_DIR``
#
# pip_install_gr packagename
function pip_install_gr {
local name=1ドル
clean_name=$(get_from_global_requirements $name)
}
function pip_install {
xtrace=$(set +o | grep xtrace)
if [[ "$offline" == "True" || -z "$@" ]]; then
$xtrace
return
fi
time_start "pip_install"
if [[ "$PIP_UPGRADE" = "True" ]] ; then
upgrade="--upgrade"
fi
GetOSVersion
fi
if [[ $TRACK_DEPENDS = True && ! "$@" =~ virtualenv ]]; then
# TRACK_DEPENDS=True installation creates a circular dependency when
# we attempt to install virtualenv into a virualenv, so we must global
# that installation.
source $DEST/.venv/bin/activate
local cmd_pip=$DEST/.venv/bin/pip
local sudo_pip="env"
else
local cmd_pip=$PIP_VIRTUAL_ENV/bin/pip
local sudo_pip="env"
else
cmd_pip=$(get_pip_command)
fi
cmd_pip="$cmd_pip -c $REQUIREMENTS_DIR/upper-constraints.txt"
pip_version=$(python -c "import pip; \
if (( pip_version<6 )); then
die $LINENO "Currently installed pip version ${pip_version} does not" \
"meet minimum requirements (>=6)."
fi
$xtrace
$sudo_pip \
https_proxy="${https_proxy:-}" \
no_proxy="${no_proxy:-}" \
echo "Installing test-requirements for $test_req"
$sudo_pip \
http_proxy=${http_proxy:-} \
https_proxy=${https_proxy:-} \
no_proxy=${no_proxy:-} \
PIP_FIND_LINKS=$PIP_FIND_LINKS \
time_stop "pip_install"
# get_from_global_requirements <package>
function get_from_global_requirements {
local package=1ドル
required_pkg=$(grep -i -h ^${package} $REQUIREMENTS_DIR/global-requirements.txt | cut -d\# -f1)
die $LINENO "Can't find package $package in requirements"
fi
echo $required_pkg
}
# get pulled in via pip dependencies.
function use_library_from_git {
local name=1ドル
local enabled=1
[[ ,${LIBS_FROM_GIT}, =~ ,${name}, ]] && enabled=0
return $enabled
}
function lib_installed_from_git {
local name=1ドル
pip freeze 2>/dev/null | grep -- "$name" | grep -q -- '-e git'
}
# check that everything that's in LIBS_FROM_GIT was actually installed
# correctly, this helps double check issues with library fat fingering.
function check_libs_from_git {
local lib=""
local not_installed=""
for lib in $(echo ${LIBS_FROM_GIT} | tr "," " "); do
if ! lib_installed_from_git "$lib"; then
not_installed+=" $lib"
fi
done
# if anything is not installed, say what it is.
if [[ -n "$not_installed" ]]; then
die $LINENO "The following LIBS_FROM_GIT were not installed correct: $not_installed"
fi
}
# git, we'll do a git based install, otherwise we'll punt and the
# library should be installed by a requirements pull from another
# project.
function setup_lib {
local name=1ドル
local dir=${GITDIR[$name]}
setup_install $dir
}
# setup a library by name in editiable mode. If we are trying to use
# the library from git, we'll do a git based install, otherwise we'll
# punt and the library should be installed by a requirements pull from
# another project.
#
# use this for non namespaced libraries
function setup_dev_lib {
local name=1ドル
local dir=${GITDIR[$name]}
setup_develop $dir
}
# this should be used if you want to install globally, all libraries should
# use this, especially *oslo* ones
function setup_install {
local project_dir=1ドル
# this should be used for projects which run services, like all services
function setup_develop {
local project_dir=1ドル
# determine if a project as specified by directory is in
# projects.txt. This will not be an exact match because we throw away
# the namespacing when we clone, but it should be good enough in all
# practical ways.
function is_in_projects_txt {
local project_dir=1ドル
project_name=$(basename $project_dir)
# ``pip install -e`` the package, which processes the dependencies
# using pip before running `setup.py develop`
#
# future installed state of this package. This ensures when we
# install this package we get the from source version.
local flags=2ドル
# Constrain this package to this project directory from here on out.
name=$(awk '/^name.*=/ {print 3ドル}' $project_dir/setup.cfg)
$REQUIREMENTS_DIR/upper-constraints.txt -- $name \
"$flags file://$project_dir#egg=$name"
}
# ``pip install -e`` the package, which processes the dependencies
# using pip before running `setup.py develop`
# Uses globals ``STACK_USER``
# setup_develop_no_requirements_update directory
function setup_package {
local project_dir=1ドル
local flags=2ドル
pip_install $flags $project_dir
# ensure that further actions can do things like setup.py sdist
if [[ "$flags" == "-e" ]]; then
safe_chown -R $STACK_USER 1ドル/*.egg-info
fi
}
# Restore xtrace
$INC_PY_TRACE
# Local variables:
# mode: shell-script
# End: