blob: a24f4e910aaece4dfffdb77c790f55ad160e00b6 [file] [log] [blame]
Dean Troyer490430d2015-01-30 14:38:35 -06001#!/bin/bash
2#
3# **inc/python** - Python-related functions
4#
5# Support for pip/setuptools interfaces and virtual environments
6#
7# External functions used:
8# - GetOSVersion
9# - is_fedora
Dean Troyer490430d2015-01-30 14:38:35 -060010# - safe_chown
11
12# Save trace setting
13INC_PY_TRACE=$(set +o | grep xtrace)
14set +o xtrace
15
16
Dean Troyer8c2ce6e2015-02-18 14:47:54 -060017# Global Config Variables
18
Atsushi SAKAI5509ed52015-11-30 20:20:21 +090019# PROJECT_VENV contains the name of the virtual environment for each
Dean Troyer8c2ce6e2015-02-18 14:47:54 -060020# project. A null value installs to the system Python directories.
Sean Dagueafef8bf2017-03-06 14:07:23 -050021declare -A -g PROJECT_VENV
Dean Troyer8c2ce6e2015-02-18 14:47:54 -060022
Radosław Piliszekbe263062020-03-30 09:56:53 +020023# Utility Functions
24# =================
25
26# Joins bash array of extras with commas as expected by other functions
27function join_extras {
28 local IFS=","
29 echo "$*"
30}
Dean Troyer8c2ce6e2015-02-18 14:47:54 -060031
Dean Troyer490430d2015-01-30 14:38:35 -060032# Python Functions
33# ================
34
35# Get the path to the pip command.
36# get_pip_command
37function get_pip_command {
Doug Hellmannddc38392015-05-07 21:06:24 +000038 local version="$1"
Tom Barron4db9d562019-01-09 08:43:52 -050039 if [ -z "$version" ]; then
40 die $LINENO "pip python version is not set."
41 fi
42
Doug Hellmannddc38392015-05-07 21:06:24 +000043 # NOTE(dhellmann): I don't know if we actually get a pip3.4-python
44 # under any circumstances.
45 which pip${version} || which pip${version}-python
Dean Troyer490430d2015-01-30 14:38:35 -060046
47 if [ $? -ne 0 ]; then
Doug Hellmannddc38392015-05-07 21:06:24 +000048 die $LINENO "Unable to find pip${version}; cannot continue"
Dean Troyer490430d2015-01-30 14:38:35 -060049 fi
50}
51
Atsushi SAKAI5509ed52015-11-30 20:20:21 +090052# Get the path to the directory where python executables are installed.
Dean Troyer490430d2015-01-30 14:38:35 -060053# get_python_exec_prefix
54function get_python_exec_prefix {
Ian Wienand433a9b12015-10-07 13:29:31 +110055 local xtrace
56 xtrace=$(set +o | grep xtrace)
Dean Troyer2b564762015-02-11 17:01:02 -060057 set +o xtrace
58 if [[ -z "$os_PACKAGE" ]]; then
59 GetOSVersion
60 fi
61 $xtrace
62
Lenny Verkhovskya30dd1c2019-03-14 13:19:36 +020063 local PYTHON_PATH=/usr/local/bin
Lenny Verkhovskya30dd1c2019-03-14 13:19:36 +020064 echo $PYTHON_PATH
Dean Troyer490430d2015-01-30 14:38:35 -060065}
66
Sean Dague60996b12015-04-08 09:06:49 -040067# Wrapper for ``pip install`` that only installs versions of libraries
68# from the global-requirements specification.
69#
70# Uses globals ``REQUIREMENTS_DIR``
71#
72# pip_install_gr packagename
73function pip_install_gr {
74 local name=$1
Ian Wienandada886d2015-10-07 14:06:26 +110075 local clean_name
76 clean_name=$(get_from_global_requirements $name)
Sean Dague60996b12015-04-08 09:06:49 -040077 pip_install $clean_name
78}
79
Mehdi Abaakouk52b10742016-12-01 16:11:17 +010080# Wrapper for ``pip install`` that only installs versions of libraries
81# from the global-requirements specification with extras.
82#
83# Uses globals ``REQUIREMENTS_DIR``
84#
85# pip_install_gr_extras packagename extra1,extra2,...
86function pip_install_gr_extras {
87 local name=$1
88 local extras=$2
Radosław Piliszekbe263062020-03-30 09:56:53 +020089 local version_constraints
90 version_constraints=$(get_version_constraints_from_global_requirements $name)
91 pip_install $name[$extras]$version_constraints
Mehdi Abaakouk52b10742016-12-01 16:11:17 +010092}
93
Doug Hellmann36377f62018-12-04 11:33:03 -050094# enable_python3_package() -- no-op for backwards compatibility
Doug Hellmann94129c72017-01-09 21:24:24 +000095#
Doug Hellmann94129c72017-01-09 21:24:24 +000096# enable_python3_package dir [dir ...]
97function enable_python3_package {
98 local xtrace
99 xtrace=$(set +o | grep xtrace)
100 set +o xtrace
101
Doug Hellmann36377f62018-12-04 11:33:03 -0500102 echo "It is no longer necessary to call enable_python3_package()."
Doug Hellmann94129c72017-01-09 21:24:24 +0000103
104 $xtrace
105}
106
Stephen Finucane6b6bdc72019-10-09 16:13:20 +0100107# disable_python3_package() -- no-op for backwards compatibility
Doug Hellmann94129c72017-01-09 21:24:24 +0000108#
Doug Hellmann94129c72017-01-09 21:24:24 +0000109# disable_python3_package dir [dir ...]
110function disable_python3_package {
111 local xtrace
112 xtrace=$(set +o | grep xtrace)
113 set +o xtrace
114
Stephen Finucane6b6bdc72019-10-09 16:13:20 +0100115 echo "It is no longer possible to call disable_python3_package()."
Doug Hellmann94129c72017-01-09 21:24:24 +0000116
117 $xtrace
118}
119
Dean Troyer490430d2015-01-30 14:38:35 -0600120# Wrapper for ``pip install`` to set cache and proxy environment variables
Dean Troyer41d6f852015-03-25 22:42:46 -0500121# Uses globals ``OFFLINE``, ``PIP_VIRTUAL_ENV``,
Ian Wienandbcb2c302020-01-13 16:31:20 +1100122# ``PIP_UPGRADE``, ``*_proxy``,
Zane Bitter9e7ead92017-10-05 16:51:09 -0400123# Usage:
124# pip_install pip_arguments
Dean Troyer490430d2015-01-30 14:38:35 -0600125function pip_install {
Federico Ressie208d062015-11-21 11:15:39 +0000126 local xtrace result
Ian Wienand433a9b12015-10-07 13:29:31 +1100127 xtrace=$(set +o | grep xtrace)
Dean Troyer490430d2015-01-30 14:38:35 -0600128 set +o xtrace
Chris Dentebdd9ac2015-03-04 12:35:14 +0000129 local upgrade=""
Dean Troyer490430d2015-01-30 14:38:35 -0600130 local offline=${OFFLINE:-False}
131 if [[ "$offline" == "True" || -z "$@" ]]; then
132 $xtrace
133 return
134 fi
135
Sean Daguecb658fa2015-10-08 17:12:03 -0400136 time_start "pip_install"
137
Chris Dentebdd9ac2015-03-04 12:35:14 +0000138 PIP_UPGRADE=$(trueorfalse False PIP_UPGRADE)
139 if [[ "$PIP_UPGRADE" = "True" ]] ; then
140 upgrade="--upgrade"
141 fi
142
Dean Troyer490430d2015-01-30 14:38:35 -0600143 if [[ -z "$os_PACKAGE" ]]; then
144 GetOSVersion
145 fi
Zane Bitter9e7ead92017-10-05 16:51:09 -0400146
147 # Try to extract the path of the package we are installing into
148 # package_dir. We need this to check for test-requirements.txt,
149 # at least.
150 #
151 # ${!#} expands to the last positional argument to this function.
152 # With "extras" syntax included, our arguments might be something
153 # like:
154 # -e /path/to/fooproject[extra]
155 # Thus this magic line grabs just the path without extras
156 #
157 # Note that this makes no sense if this is a pypi (rather than
158 # local path) install; ergo you must check this path exists before
159 # use. Also, if we had multiple or mixed installs, we would also
160 # likely break. But for historical reasons, it's basically only
161 # the other wrapper functions in here calling this to install
162 # local packages, and they do so with single call per install. So
163 # this works (for now...)
164 local package_dir=${!#%\[*\]}
165
Ian Wienandbcb2c302020-01-13 16:31:20 +1100166 if [[ -n ${PIP_VIRTUAL_ENV:=} && -d ${PIP_VIRTUAL_ENV} ]]; then
167 local cmd_pip=$PIP_VIRTUAL_ENV/bin/pip
Dean Troyer490430d2015-01-30 14:38:35 -0600168 local sudo_pip="env"
169 else
Jens Harbottd7a82f42020-06-23 10:21:09 +0200170 local cmd_pip="python$PYTHON3_VERSION -m pip"
Ian Wienand18b42512020-08-31 16:22:57 +1000171 # See
172 # https://github.com/pypa/setuptools/issues/2232
173 # http://lists.openstack.org/pipermail/openstack-discuss/2020-August/016905.html
174 # this makes setuptools >=50 use the platform distutils.
175 # We only want to do this on global pip installs, not if
176 # installing in a virtualenv
177 local sudo_pip="sudo -H LC_ALL=en_US.UTF-8 SETUPTOOLS_USE_DISTUTILS=stdlib "
Jens Harbottd7a82f42020-06-23 10:21:09 +0200178 echo "Using python $PYTHON3_VERSION to install $package_dir"
Dean Troyer490430d2015-01-30 14:38:35 -0600179 fi
180
Robert Collins635a5ba2015-06-10 08:48:06 +1200181 cmd_pip="$cmd_pip install"
Clark Boylan05aa3842015-08-03 11:14:13 -0700182 # Always apply constraints
183 cmd_pip="$cmd_pip -c $REQUIREMENTS_DIR/upper-constraints.txt"
Robert Collins635a5ba2015-06-10 08:48:06 +1200184
Dean Troyer490430d2015-01-30 14:38:35 -0600185 $xtrace
Clark Boylanf266a2d2017-06-12 14:57:59 -0700186
Dean Troyer490430d2015-01-30 14:38:35 -0600187 $sudo_pip \
Eli Qiao6a83c422015-03-17 16:54:16 +0800188 http_proxy="${http_proxy:-}" \
189 https_proxy="${https_proxy:-}" \
190 no_proxy="${no_proxy:-}" \
Joe Gordoncd8824a2015-03-04 16:40:19 -0800191 PIP_FIND_LINKS=$PIP_FIND_LINKS \
Monty Taylor09b5b052020-03-27 11:22:39 -0500192 $cmd_pip $upgrade \
Dean Troyer490430d2015-01-30 14:38:35 -0600193 $@
Federico Ressie208d062015-11-21 11:15:39 +0000194 result=$?
Dean Troyer490430d2015-01-30 14:38:35 -0600195
Sean Daguecb658fa2015-10-08 17:12:03 -0400196 time_stop "pip_install"
Federico Ressie208d062015-11-21 11:15:39 +0000197 return $result
Dean Troyer490430d2015-01-30 14:38:35 -0600198}
199
Sean Daguef28e7ef2017-05-07 22:02:10 -0400200function pip_uninstall {
Sampath Priyankara87d23962017-08-03 16:12:40 +0900201 # Skip uninstall if offline
202 [[ "${OFFLINE}" = "True" ]] && return
203
Sean Daguef28e7ef2017-05-07 22:02:10 -0400204 local name=$1
205 if [[ -n ${PIP_VIRTUAL_ENV:=} && -d ${PIP_VIRTUAL_ENV} ]]; then
206 local cmd_pip=$PIP_VIRTUAL_ENV/bin/pip
207 local sudo_pip="env"
208 else
Jens Harbottd7a82f42020-06-23 10:21:09 +0200209 local cmd_pip="python$PYTHON3_VERSION -m pip"
210 local sudo_pip="sudo -H LC_ALL=en_US.UTF-8"
Sean Daguef28e7ef2017-05-07 22:02:10 -0400211 fi
212 # don't error if we can't uninstall, it might not be there
Brian Haley954fd1b2017-05-16 12:24:45 -0400213 $sudo_pip $cmd_pip uninstall -y $name || /bin/true
Sean Daguef28e7ef2017-05-07 22:02:10 -0400214}
215
Joe Gordond5ac7852015-02-06 19:29:23 -0800216# get version of a package from global requirements file
217# get_from_global_requirements <package>
218function get_from_global_requirements {
219 local package=$1
Ian Wienandada886d2015-10-07 14:06:26 +1100220 local required_pkg
221 required_pkg=$(grep -i -h ^${package} $REQUIREMENTS_DIR/global-requirements.txt | cut -d\# -f1)
Joe Gordond5ac7852015-02-06 19:29:23 -0800222 if [[ $required_pkg == "" ]]; then
223 die $LINENO "Can't find package $package in requirements"
224 fi
225 echo $required_pkg
226}
227
Radosław Piliszekbe263062020-03-30 09:56:53 +0200228# get only version constraints of a package from global requirements file
229# get_version_constraints_from_global_requirements <package>
230function get_version_constraints_from_global_requirements {
231 local package=$1
232 local required_pkg_version_constraint
233 # drop the package name from output (\K)
234 required_pkg_version_constraint=$(grep -i -h -o -P "^${package}\K.*" $REQUIREMENTS_DIR/global-requirements.txt | cut -d\# -f1)
235 if [[ $required_pkg_version_constraint == "" ]]; then
236 die $LINENO "Can't find package $package in requirements"
237 fi
238 echo $required_pkg_version_constraint
239}
240
Dean Troyer490430d2015-01-30 14:38:35 -0600241# should we use this library from their git repo, or should we let it
242# get pulled in via pip dependencies.
243function use_library_from_git {
244 local name=$1
245 local enabled=1
Marc Koderer46f8cb72016-05-13 09:08:16 +0200246 [[ ${LIBS_FROM_GIT} = 'ALL' ]] || [[ ,${LIBS_FROM_GIT}, =~ ,${name}, ]] && enabled=0
Dean Troyer490430d2015-01-30 14:38:35 -0600247 return $enabled
248}
249
Sean Daguec71973e2015-09-08 07:12:48 -0400250# determine if a package was installed from git
251function lib_installed_from_git {
252 local name=$1
DamonLi007f5882017-11-23 10:05:46 +0800253 local safe_name
254 safe_name=$(python -c "from pkg_resources import safe_name; \
255 print(safe_name('${name}'))")
Ian Wienandae9c6ab2017-09-29 10:16:47 +1000256 # Note "pip freeze" doesn't always work here, because it tries to
257 # be smart about finding the remote of the git repo the package
258 # was installed from. This doesn't work with zuul which clones
259 # repos with no remote.
260 #
261 # The best option seems to be to use "pip list" which will tell
262 # you the path an editable install was installed from; for example
263 # in response to something like
Matt Riedemann9b6d2f22019-06-18 10:43:16 -0400264 # pip install -e 'git+https://opendev.org/openstack/bashate#egg=bashate'
Monty Taylorf0cd9a82017-10-06 13:11:48 -0500265 # pip list --format columns shows
266 # bashate 0.5.2.dev19 /tmp/env/src/bashate
267 # Thus we check the third column to see if we're installed from
268 # some local place.
DamonLi007f5882017-11-23 10:05:46 +0800269 [[ -n $(pip list --format=columns 2>/dev/null | awk "/^$safe_name/ {print \$3}") ]]
Sean Daguec71973e2015-09-08 07:12:48 -0400270}
271
Dean Troyer490430d2015-01-30 14:38:35 -0600272# setup a library by name. If we are trying to use the library from
273# git, we'll do a git based install, otherwise we'll punt and the
274# library should be installed by a requirements pull from another
275# project.
276function setup_lib {
277 local name=$1
278 local dir=${GITDIR[$name]}
279 setup_install $dir
280}
281
Atsushi SAKAI5509ed52015-11-30 20:20:21 +0900282# setup a library by name in editable mode. If we are trying to use
Dean Troyer490430d2015-01-30 14:38:35 -0600283# the library from git, we'll do a git based install, otherwise we'll
284# punt and the library should be installed by a requirements pull from
285# another project.
286#
287# use this for non namespaced libraries
Ian Wienand58243f62018-12-13 14:05:53 +1100288#
Radosław Piliszekbe263062020-03-30 09:56:53 +0200289# setup_dev_lib [-bindep] <name> [<extras>]
Dean Troyer490430d2015-01-30 14:38:35 -0600290function setup_dev_lib {
Ian Wienand58243f62018-12-13 14:05:53 +1100291 local bindep
292 if [[ $1 == -bindep* ]]; then
293 bindep="${1}"
294 shift
295 fi
Dean Troyer490430d2015-01-30 14:38:35 -0600296 local name=$1
297 local dir=${GITDIR[$name]}
Radosław Piliszekbe263062020-03-30 09:56:53 +0200298 local extras=$2
299 setup_develop $bindep $dir $extras
Dean Troyer490430d2015-01-30 14:38:35 -0600300}
301
302# this should be used if you want to install globally, all libraries should
303# use this, especially *oslo* ones
Brant Knudson0842b812015-08-03 13:31:25 -0500304#
305# setup_install project_dir [extras]
306# project_dir: directory of project repo (e.g., /opt/stack/keystone)
307# extras: comma-separated list of optional dependencies to install
308# (e.g., ldap,memcache).
Takashi NATSUMEfa007772017-07-22 08:59:43 +0900309# See https://docs.openstack.org/pbr/latest/user/using.html#extra-requirements
Ian Wienand58243f62018-12-13 14:05:53 +1100310# bindep: Set "-bindep" as first argument to install bindep.txt packages
Brant Knudson0842b812015-08-03 13:31:25 -0500311# The command is like "pip install <project_dir>[<extras>]"
Dean Troyer490430d2015-01-30 14:38:35 -0600312function setup_install {
Ian Wienand58243f62018-12-13 14:05:53 +1100313 local bindep
314 if [[ $1 == -bindep* ]]; then
315 bindep="${1}"
316 shift
317 fi
Dean Troyer490430d2015-01-30 14:38:35 -0600318 local project_dir=$1
Brant Knudson0842b812015-08-03 13:31:25 -0500319 local extras=$2
Ian Wienand58243f62018-12-13 14:05:53 +1100320 _setup_package_with_constraints_edit $bindep $project_dir "" $extras
Dean Troyer490430d2015-01-30 14:38:35 -0600321}
322
323# this should be used for projects which run services, like all services
Brant Knudson0842b812015-08-03 13:31:25 -0500324#
325# setup_develop project_dir [extras]
326# project_dir: directory of project repo (e.g., /opt/stack/keystone)
327# extras: comma-separated list of optional dependencies to install
328# (e.g., ldap,memcache).
Takashi NATSUMEfa007772017-07-22 08:59:43 +0900329# See https://docs.openstack.org/pbr/latest/user/using.html#extra-requirements
Brant Knudson0842b812015-08-03 13:31:25 -0500330# The command is like "pip install -e <project_dir>[<extras>]"
Dean Troyer490430d2015-01-30 14:38:35 -0600331function setup_develop {
Ian Wienand58243f62018-12-13 14:05:53 +1100332 local bindep
333 if [[ $1 == -bindep* ]]; then
334 bindep="${1}"
335 shift
336 fi
Dean Troyer490430d2015-01-30 14:38:35 -0600337 local project_dir=$1
Brant Knudson0842b812015-08-03 13:31:25 -0500338 local extras=$2
Ian Wienand58243f62018-12-13 14:05:53 +1100339 _setup_package_with_constraints_edit $bindep $project_dir -e $extras
Dean Troyer490430d2015-01-30 14:38:35 -0600340}
341
Dean Troyer490430d2015-01-30 14:38:35 -0600342# ``pip install -e`` the package, which processes the dependencies
343# using pip before running `setup.py develop`
344#
Clark Boylan05aa3842015-08-03 11:14:13 -0700345# Updates the constraints from REQUIREMENTS_DIR to reflect the
346# future installed state of this package. This ensures when we
347# install this package we get the from source version.
Dean Troyer490430d2015-01-30 14:38:35 -0600348#
Clark Boylan05aa3842015-08-03 11:14:13 -0700349# Uses globals ``REQUIREMENTS_DIR``
Brant Knudson0842b812015-08-03 13:31:25 -0500350# _setup_package_with_constraints_edit project_dir flags [extras]
351# project_dir: directory of project repo (e.g., /opt/stack/keystone)
352# flags: pip CLI options/flags
353# extras: comma-separated list of optional dependencies to install
354# (e.g., ldap,memcache).
Takashi NATSUMEfa007772017-07-22 08:59:43 +0900355# See https://docs.openstack.org/pbr/latest/user/using.html#extra-requirements
Brant Knudson0842b812015-08-03 13:31:25 -0500356# The command is like "pip install <flags> <project_dir>[<extras>]"
357function _setup_package_with_constraints_edit {
Ian Wienand58243f62018-12-13 14:05:53 +1100358 local bindep
359 if [[ $1 == -bindep* ]]; then
360 bindep="${1}"
361 shift
362 fi
Dean Troyer490430d2015-01-30 14:38:35 -0600363 local project_dir=$1
364 local flags=$2
Brant Knudson0842b812015-08-03 13:31:25 -0500365 local extras=$3
Dean Troyer490430d2015-01-30 14:38:35 -0600366
YAMAMOTO Takashic8c1c612016-03-22 14:29:47 +0900367 # Normalize the directory name to avoid
368 # "installation from path or url cannot be constrained to a version"
369 # error.
370 # REVISIT(yamamoto): Remove this when fixed in pip.
371 # https://github.com/pypa/pip/pull/3582
372 project_dir=$(cd $project_dir && pwd)
373
Robert Collins635a5ba2015-06-10 08:48:06 +1200374 if [ -n "$REQUIREMENTS_DIR" ]; then
Ian Wienand6b9a5642021-07-28 11:19:57 +1000375 # Remove this package from constraints before we install it.
376 # That way, later installs won't "downgrade" the install from
377 # source we are about to do.
Ian Wienandada886d2015-10-07 14:06:26 +1100378 local name
379 name=$(awk '/^name.*=/ {print $3}' $project_dir/setup.cfg)
Robert Collins7c838612015-07-03 13:28:09 +1200380 $REQUIREMENTS_DIR/.venv/bin/edit-constraints \
Ian Wienand6b9a5642021-07-28 11:19:57 +1000381 $REQUIREMENTS_DIR/upper-constraints.txt -- $name
Robert Collins635a5ba2015-06-10 08:48:06 +1200382 fi
383
Ian Wienand58243f62018-12-13 14:05:53 +1100384 setup_package $bindep $project_dir "$flags" $extras
Dean Troyer490430d2015-01-30 14:38:35 -0600385
James E. Blaire1edde32018-03-02 15:05:14 +0000386 # If this project is in LIBS_FROM_GIT, verify it was actually installed
387 # correctly. This helps catch errors caused by constraints mismatches.
388 if use_library_from_git "$project_dir"; then
389 if ! lib_installed_from_git "$project_dir"; then
390 die $LINENO "The following LIBS_FROM_GIT was not installed correctly: $project_dir"
391 fi
392 fi
Dean Troyer490430d2015-01-30 14:38:35 -0600393}
394
395# ``pip install -e`` the package, which processes the dependencies
Ian Wienand58243f62018-12-13 14:05:53 +1100396# using pip before running `setup.py develop`. The command is like
397# "pip install <flags> <project_dir>[<extras>]"
Brant Knudson0842b812015-08-03 13:31:25 -0500398#
Dean Troyer490430d2015-01-30 14:38:35 -0600399# Uses globals ``STACK_USER``
Ian Wienand58243f62018-12-13 14:05:53 +1100400#
401# Usage:
402# setup_package [-bindep[=profile,profile]] <project_dir> <flags> [extras]
403#
404# -bindep : Use bindep to install dependencies; select extra profiles
405# as comma separated arguments after "="
406# project_dir : directory of project repo (e.g., /opt/stack/keystone)
407# flags : pip CLI options/flags
408# extras : comma-separated list of optional dependencies to install
409# (e.g., ldap,memcache).
410# See https://docs.openstack.org/pbr/latest/user/using.html#extra-requirements
Dean Troyer490430d2015-01-30 14:38:35 -0600411function setup_package {
Ian Wienand58243f62018-12-13 14:05:53 +1100412 local bindep=0
413 local bindep_flag=""
414 local bindep_profiles=""
415 if [[ $1 == -bindep* ]]; then
416 bindep=1
417 IFS="=" read bindep_flag bindep_profiles <<< ${1}
418 shift
419 fi
Dean Troyer490430d2015-01-30 14:38:35 -0600420 local project_dir=$1
421 local flags=$2
Brant Knudson0842b812015-08-03 13:31:25 -0500422 local extras=$3
Dean Troyer490430d2015-01-30 14:38:35 -0600423
Brant Knudson0842b812015-08-03 13:31:25 -0500424 # if the flags variable exists, and it doesn't look like a flag,
425 # assume it's actually the extras list.
426 if [[ -n "$flags" && -z "$extras" && ! "$flags" =~ ^-.* ]]; then
427 extras=$flags
428 flags=""
429 fi
430
431 if [[ ! -z "$extras" ]]; then
432 extras="[$extras]"
433 fi
434
Ian Wienand58243f62018-12-13 14:05:53 +1100435 # install any bindep packages
436 if [[ $bindep == 1 ]]; then
437 install_bindep $project_dir/bindep.txt $bindep_profiles
438 fi
439
Brant Knudson0842b812015-08-03 13:31:25 -0500440 pip_install $flags "$project_dir$extras"
Dean Troyer490430d2015-01-30 14:38:35 -0600441 # ensure that further actions can do things like setup.py sdist
442 if [[ "$flags" == "-e" ]]; then
443 safe_chown -R $STACK_USER $1/*.egg-info
444 fi
445}
446
Doug Hellmannddc38392015-05-07 21:06:24 +0000447# Report whether python 3 should be used
Jens Harbottd7a82f42020-06-23 10:21:09 +0200448# TODO(frickler): drop this once all legacy uses are removed
Doug Hellmannddc38392015-05-07 21:06:24 +0000449function python3_enabled {
Radosław Piliszek3cbb33e2020-06-30 17:52:10 +0200450 return 0
Doug Hellmannddc38392015-05-07 21:06:24 +0000451}
452
Federico Ressi21a10d32020-01-31 07:43:30 +0100453# Provide requested python version and sets PYTHON variable
454function install_python {
Jens Harbottd7a82f42020-06-23 10:21:09 +0200455 install_python3
456 export PYTHON=$(which python${PYTHON3_VERSION} 2>/dev/null)
Federico Ressi21a10d32020-01-31 07:43:30 +0100457}
458
Doug Hellmannddc38392015-05-07 21:06:24 +0000459# Install python3 packages
460function install_python3 {
461 if is_ubuntu; then
Lubosz "diltram" Kosnik0a099762016-08-03 10:21:41 -0500462 apt_get install python${PYTHON3_VERSION} python${PYTHON3_VERSION}-dev
Terry Wilson78cf6f62019-10-15 19:45:09 +0000463 elif is_fedora; then
Federico Ressi2dcbc282020-02-05 11:29:51 +0100464 if [ "$os_VENDOR" = "Fedora" ]; then
465 install_package python${PYTHON3_VERSION//.}
466 else
467 install_package python${PYTHON3_VERSION//.} python${PYTHON3_VERSION//.}-devel
468 fi
Doug Hellmannddc38392015-05-07 21:06:24 +0000469 fi
470}
Dean Troyer490430d2015-01-30 14:38:35 -0600471
Sean Daguef80e2cf2017-01-18 15:42:32 -0500472function install_devstack_tools {
473 # intentionally old to ensure devstack-gate has control
474 local dstools_version=${DSTOOLS_VERSION:-0.1.2}
475 install_python3
476 sudo pip3 install -U devstack-tools==${dstools_version}
477}
478
Dean Troyer490430d2015-01-30 14:38:35 -0600479# Restore xtrace
480$INC_PY_TRACE
481
482# Local variables:
483# mode: shell-script
484# End: