blob: 37e8399f4a68ad9929b7e32761b4f3ed1c31970d [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
10# - is_suse
11# - safe_chown
12
13# Save trace setting
14INC_PY_TRACE=$(set +o | grep xtrace)
15set +o xtrace
16
17
Dean Troyer8c2ce6e2015-02-18 14:47:54 -060018# Global Config Variables
19
Atsushi SAKAI5509ed52015-11-30 20:20:21 +090020# PROJECT_VENV contains the name of the virtual environment for each
Dean Troyer8c2ce6e2015-02-18 14:47:54 -060021# project. A null value installs to the system Python directories.
Sean Dagueafef8bf2017-03-06 14:07:23 -050022declare -A -g PROJECT_VENV
Dean Troyer8c2ce6e2015-02-18 14:47:54 -060023
24
Dean Troyer490430d2015-01-30 14:38:35 -060025# Python Functions
26# ================
27
28# Get the path to the pip command.
29# get_pip_command
30function get_pip_command {
Doug Hellmannddc38392015-05-07 21:06:24 +000031 local version="$1"
Tom Barron4db9d562019-01-09 08:43:52 -050032 if [ -z "$version" ]; then
33 die $LINENO "pip python version is not set."
34 fi
35
Doug Hellmannddc38392015-05-07 21:06:24 +000036 # NOTE(dhellmann): I don't know if we actually get a pip3.4-python
37 # under any circumstances.
38 which pip${version} || which pip${version}-python
Dean Troyer490430d2015-01-30 14:38:35 -060039
40 if [ $? -ne 0 ]; then
Doug Hellmannddc38392015-05-07 21:06:24 +000041 die $LINENO "Unable to find pip${version}; cannot continue"
Dean Troyer490430d2015-01-30 14:38:35 -060042 fi
43}
44
Atsushi SAKAI5509ed52015-11-30 20:20:21 +090045# Get the path to the directory where python executables are installed.
Dean Troyer490430d2015-01-30 14:38:35 -060046# get_python_exec_prefix
47function get_python_exec_prefix {
Ian Wienand433a9b12015-10-07 13:29:31 +110048 local xtrace
49 xtrace=$(set +o | grep xtrace)
Dean Troyer2b564762015-02-11 17:01:02 -060050 set +o xtrace
51 if [[ -z "$os_PACKAGE" ]]; then
52 GetOSVersion
53 fi
54 $xtrace
55
Lenny Verkhovskya30dd1c2019-03-14 13:19:36 +020056 local PYTHON_PATH=/usr/local/bin
57 ( is_fedora && ! python3_enabled ) || is_suse && PYTHON_PATH=/usr/bin
58 echo $PYTHON_PATH
Dean Troyer490430d2015-01-30 14:38:35 -060059}
60
Sean Dague60996b12015-04-08 09:06:49 -040061# Wrapper for ``pip install`` that only installs versions of libraries
62# from the global-requirements specification.
63#
64# Uses globals ``REQUIREMENTS_DIR``
65#
66# pip_install_gr packagename
67function pip_install_gr {
68 local name=$1
Ian Wienandada886d2015-10-07 14:06:26 +110069 local clean_name
70 clean_name=$(get_from_global_requirements $name)
Sean Dague60996b12015-04-08 09:06:49 -040071 pip_install $clean_name
72}
73
Mehdi Abaakouk52b10742016-12-01 16:11:17 +010074# Wrapper for ``pip install`` that only installs versions of libraries
75# from the global-requirements specification with extras.
76#
77# Uses globals ``REQUIREMENTS_DIR``
78#
79# pip_install_gr_extras packagename extra1,extra2,...
80function pip_install_gr_extras {
81 local name=$1
82 local extras=$2
83 local clean_name
84 clean_name=$(get_from_global_requirements $name)
85 pip_install $clean_name[$extras]
86}
87
Doug Hellmann36377f62018-12-04 11:33:03 -050088# enable_python3_package() -- no-op for backwards compatibility
Doug Hellmann94129c72017-01-09 21:24:24 +000089#
Doug Hellmann94129c72017-01-09 21:24:24 +000090# enable_python3_package dir [dir ...]
91function enable_python3_package {
92 local xtrace
93 xtrace=$(set +o | grep xtrace)
94 set +o xtrace
95
Doug Hellmann36377f62018-12-04 11:33:03 -050096 echo "It is no longer necessary to call enable_python3_package()."
Doug Hellmann94129c72017-01-09 21:24:24 +000097
98 $xtrace
99}
100
Stephen Finucane6b6bdc72019-10-09 16:13:20 +0100101# disable_python3_package() -- no-op for backwards compatibility
Doug Hellmann94129c72017-01-09 21:24:24 +0000102#
Doug Hellmann94129c72017-01-09 21:24:24 +0000103# disable_python3_package dir [dir ...]
104function disable_python3_package {
105 local xtrace
106 xtrace=$(set +o | grep xtrace)
107 set +o xtrace
108
Stephen Finucane6b6bdc72019-10-09 16:13:20 +0100109 echo "It is no longer possible to call disable_python3_package()."
Doug Hellmann94129c72017-01-09 21:24:24 +0000110
111 $xtrace
112}
113
Dean Troyer490430d2015-01-30 14:38:35 -0600114# Wrapper for ``pip install`` to set cache and proxy environment variables
Dean Troyer41d6f852015-03-25 22:42:46 -0500115# Uses globals ``OFFLINE``, ``PIP_VIRTUAL_ENV``,
Ian Wienandbcb2c302020-01-13 16:31:20 +1100116# ``PIP_UPGRADE``, ``*_proxy``,
Zane Bitter9e7ead92017-10-05 16:51:09 -0400117# Usage:
118# pip_install pip_arguments
Dean Troyer490430d2015-01-30 14:38:35 -0600119function pip_install {
Federico Ressie208d062015-11-21 11:15:39 +0000120 local xtrace result
Ian Wienand433a9b12015-10-07 13:29:31 +1100121 xtrace=$(set +o | grep xtrace)
Dean Troyer490430d2015-01-30 14:38:35 -0600122 set +o xtrace
Chris Dentebdd9ac2015-03-04 12:35:14 +0000123 local upgrade=""
Dean Troyer490430d2015-01-30 14:38:35 -0600124 local offline=${OFFLINE:-False}
125 if [[ "$offline" == "True" || -z "$@" ]]; then
126 $xtrace
127 return
128 fi
129
Sean Daguecb658fa2015-10-08 17:12:03 -0400130 time_start "pip_install"
131
Chris Dentebdd9ac2015-03-04 12:35:14 +0000132 PIP_UPGRADE=$(trueorfalse False PIP_UPGRADE)
133 if [[ "$PIP_UPGRADE" = "True" ]] ; then
134 upgrade="--upgrade"
135 fi
136
Dean Troyer490430d2015-01-30 14:38:35 -0600137 if [[ -z "$os_PACKAGE" ]]; then
138 GetOSVersion
139 fi
Zane Bitter9e7ead92017-10-05 16:51:09 -0400140
141 # Try to extract the path of the package we are installing into
142 # package_dir. We need this to check for test-requirements.txt,
143 # at least.
144 #
145 # ${!#} expands to the last positional argument to this function.
146 # With "extras" syntax included, our arguments might be something
147 # like:
148 # -e /path/to/fooproject[extra]
149 # Thus this magic line grabs just the path without extras
150 #
151 # Note that this makes no sense if this is a pypi (rather than
152 # local path) install; ergo you must check this path exists before
153 # use. Also, if we had multiple or mixed installs, we would also
154 # likely break. But for historical reasons, it's basically only
155 # the other wrapper functions in here calling this to install
156 # local packages, and they do so with single call per install. So
157 # this works (for now...)
158 local package_dir=${!#%\[*\]}
159
Ian Wienandbcb2c302020-01-13 16:31:20 +1100160 if [[ -n ${PIP_VIRTUAL_ENV:=} && -d ${PIP_VIRTUAL_ENV} ]]; then
161 local cmd_pip=$PIP_VIRTUAL_ENV/bin/pip
Dean Troyer490430d2015-01-30 14:38:35 -0600162 local sudo_pip="env"
163 else
Ian Wienandbcb2c302020-01-13 16:31:20 +1100164 local cmd_pip
Ian Wienandbcb2c302020-01-13 16:31:20 +1100165 local sudo_pip="sudo -H"
166 if python3_enabled; then
Radosław Piliszek29bf8522020-01-24 11:52:13 +0100167 echo "Using python $PYTHON3_VERSION to install $package_dir because python3_enabled=True"
Stephen Finucane6b6bdc72019-10-09 16:13:20 +0100168 sudo_pip="$sudo_pip LC_ALL=en_US.UTF-8"
169 cmd_pip=$(get_pip_command $PYTHON3_VERSION)
Radosław Piliszek29bf8522020-01-24 11:52:13 +0100170 else
171 echo "Using python $PYTHON2_VERSION to install $package_dir because python3_enabled=False"
172 cmd_pip=$(get_pip_command $PYTHON2_VERSION)
Dean Troyer2b564762015-02-11 17:01:02 -0600173 fi
Dean Troyer490430d2015-01-30 14:38:35 -0600174 fi
175
Robert Collins635a5ba2015-06-10 08:48:06 +1200176 cmd_pip="$cmd_pip install"
Clark Boylan05aa3842015-08-03 11:14:13 -0700177 # Always apply constraints
178 cmd_pip="$cmd_pip -c $REQUIREMENTS_DIR/upper-constraints.txt"
Robert Collins635a5ba2015-06-10 08:48:06 +1200179
Dean Troyer490430d2015-01-30 14:38:35 -0600180 $xtrace
Clark Boylanf266a2d2017-06-12 14:57:59 -0700181
182 # Also install test requirements
183 local install_test_reqs=""
Zane Bitter9e7ead92017-10-05 16:51:09 -0400184 local test_req="${package_dir}/test-requirements.txt"
Clark Boylanf266a2d2017-06-12 14:57:59 -0700185 if [[ -e "$test_req" ]]; then
186 install_test_reqs="-r $test_req"
187 fi
188
Spyros Trigazis88ccd472016-07-24 22:13:57 +0200189 # adding SETUPTOOLS_SYS_PATH_TECHNIQUE is a workaround to keep
190 # the same behaviour of setuptools before version 25.0.0.
191 # related issue: https://github.com/pypa/pip/issues/3874
Dean Troyer490430d2015-01-30 14:38:35 -0600192 $sudo_pip \
Eli Qiao6a83c422015-03-17 16:54:16 +0800193 http_proxy="${http_proxy:-}" \
194 https_proxy="${https_proxy:-}" \
195 no_proxy="${no_proxy:-}" \
Joe Gordoncd8824a2015-03-04 16:40:19 -0800196 PIP_FIND_LINKS=$PIP_FIND_LINKS \
Spyros Trigazis88ccd472016-07-24 22:13:57 +0200197 SETUPTOOLS_SYS_PATH_TECHNIQUE=rewrite \
Clark Boylanf266a2d2017-06-12 14:57:59 -0700198 $cmd_pip $upgrade $install_test_reqs \
Dean Troyer490430d2015-01-30 14:38:35 -0600199 $@
Federico Ressie208d062015-11-21 11:15:39 +0000200 result=$?
Dean Troyer490430d2015-01-30 14:38:35 -0600201
Sean Daguecb658fa2015-10-08 17:12:03 -0400202 time_stop "pip_install"
Federico Ressie208d062015-11-21 11:15:39 +0000203 return $result
Dean Troyer490430d2015-01-30 14:38:35 -0600204}
205
Sean Daguef28e7ef2017-05-07 22:02:10 -0400206function pip_uninstall {
Sampath Priyankara87d23962017-08-03 16:12:40 +0900207 # Skip uninstall if offline
208 [[ "${OFFLINE}" = "True" ]] && return
209
Sean Daguef28e7ef2017-05-07 22:02:10 -0400210 local name=$1
211 if [[ -n ${PIP_VIRTUAL_ENV:=} && -d ${PIP_VIRTUAL_ENV} ]]; then
212 local cmd_pip=$PIP_VIRTUAL_ENV/bin/pip
213 local sudo_pip="env"
214 else
215 local cmd_pip
Sean Daguef28e7ef2017-05-07 22:02:10 -0400216 local sudo_pip="sudo -H"
Radosław Piliszek29bf8522020-01-24 11:52:13 +0100217 if python3_enabled; then
218 sudo_pip="$sudo_pip LC_ALL=en_US.UTF-8"
219 cmd_pip=$(get_pip_command $PYTHON3_VERSION)
220 else
221 cmd_pip=$(get_pip_command $PYTHON2_VERSION)
222 fi
Sean Daguef28e7ef2017-05-07 22:02:10 -0400223 fi
224 # don't error if we can't uninstall, it might not be there
Brian Haley954fd1b2017-05-16 12:24:45 -0400225 $sudo_pip $cmd_pip uninstall -y $name || /bin/true
Sean Daguef28e7ef2017-05-07 22:02:10 -0400226}
227
Joe Gordond5ac7852015-02-06 19:29:23 -0800228# get version of a package from global requirements file
229# get_from_global_requirements <package>
230function get_from_global_requirements {
231 local package=$1
Ian Wienandada886d2015-10-07 14:06:26 +1100232 local required_pkg
233 required_pkg=$(grep -i -h ^${package} $REQUIREMENTS_DIR/global-requirements.txt | cut -d\# -f1)
Joe Gordond5ac7852015-02-06 19:29:23 -0800234 if [[ $required_pkg == "" ]]; then
235 die $LINENO "Can't find package $package in requirements"
236 fi
237 echo $required_pkg
238}
239
Dean Troyer490430d2015-01-30 14:38:35 -0600240# should we use this library from their git repo, or should we let it
241# get pulled in via pip dependencies.
242function use_library_from_git {
243 local name=$1
244 local enabled=1
Marc Koderer46f8cb72016-05-13 09:08:16 +0200245 [[ ${LIBS_FROM_GIT} = 'ALL' ]] || [[ ,${LIBS_FROM_GIT}, =~ ,${name}, ]] && enabled=0
Dean Troyer490430d2015-01-30 14:38:35 -0600246 return $enabled
247}
248
Sean Daguec71973e2015-09-08 07:12:48 -0400249# determine if a package was installed from git
250function lib_installed_from_git {
251 local name=$1
DamonLi007f5882017-11-23 10:05:46 +0800252 local safe_name
253 safe_name=$(python -c "from pkg_resources import safe_name; \
254 print(safe_name('${name}'))")
Ian Wienandae9c6ab2017-09-29 10:16:47 +1000255 # Note "pip freeze" doesn't always work here, because it tries to
256 # be smart about finding the remote of the git repo the package
257 # was installed from. This doesn't work with zuul which clones
258 # repos with no remote.
259 #
260 # The best option seems to be to use "pip list" which will tell
261 # you the path an editable install was installed from; for example
262 # in response to something like
Matt Riedemann9b6d2f22019-06-18 10:43:16 -0400263 # pip install -e 'git+https://opendev.org/openstack/bashate#egg=bashate'
Monty Taylorf0cd9a82017-10-06 13:11:48 -0500264 # pip list --format columns shows
265 # bashate 0.5.2.dev19 /tmp/env/src/bashate
266 # Thus we check the third column to see if we're installed from
267 # some local place.
DamonLi007f5882017-11-23 10:05:46 +0800268 [[ -n $(pip list --format=columns 2>/dev/null | awk "/^$safe_name/ {print \$3}") ]]
Sean Daguec71973e2015-09-08 07:12:48 -0400269}
270
Dean Troyer490430d2015-01-30 14:38:35 -0600271# setup a library by name. If we are trying to use the library from
272# git, we'll do a git based install, otherwise we'll punt and the
273# library should be installed by a requirements pull from another
274# project.
275function setup_lib {
276 local name=$1
277 local dir=${GITDIR[$name]}
278 setup_install $dir
279}
280
Atsushi SAKAI5509ed52015-11-30 20:20:21 +0900281# setup a library by name in editable mode. If we are trying to use
Dean Troyer490430d2015-01-30 14:38:35 -0600282# the library from git, we'll do a git based install, otherwise we'll
283# punt and the library should be installed by a requirements pull from
284# another project.
285#
286# use this for non namespaced libraries
Ian Wienand58243f62018-12-13 14:05:53 +1100287#
288# setup_dev_lib [-bindep] <name>
Dean Troyer490430d2015-01-30 14:38:35 -0600289function setup_dev_lib {
Ian Wienand58243f62018-12-13 14:05:53 +1100290 local bindep
291 if [[ $1 == -bindep* ]]; then
292 bindep="${1}"
293 shift
294 fi
Dean Troyer490430d2015-01-30 14:38:35 -0600295 local name=$1
296 local dir=${GITDIR[$name]}
Ian Wienand58243f62018-12-13 14:05:53 +1100297 setup_develop $bindep $dir
Dean Troyer490430d2015-01-30 14:38:35 -0600298}
299
300# this should be used if you want to install globally, all libraries should
301# use this, especially *oslo* ones
Brant Knudson0842b812015-08-03 13:31:25 -0500302#
303# setup_install project_dir [extras]
304# project_dir: directory of project repo (e.g., /opt/stack/keystone)
305# extras: comma-separated list of optional dependencies to install
306# (e.g., ldap,memcache).
Takashi NATSUMEfa007772017-07-22 08:59:43 +0900307# See https://docs.openstack.org/pbr/latest/user/using.html#extra-requirements
Ian Wienand58243f62018-12-13 14:05:53 +1100308# bindep: Set "-bindep" as first argument to install bindep.txt packages
Brant Knudson0842b812015-08-03 13:31:25 -0500309# The command is like "pip install <project_dir>[<extras>]"
Dean Troyer490430d2015-01-30 14:38:35 -0600310function setup_install {
Ian Wienand58243f62018-12-13 14:05:53 +1100311 local bindep
312 if [[ $1 == -bindep* ]]; then
313 bindep="${1}"
314 shift
315 fi
Dean Troyer490430d2015-01-30 14:38:35 -0600316 local project_dir=$1
Brant Knudson0842b812015-08-03 13:31:25 -0500317 local extras=$2
Ian Wienand58243f62018-12-13 14:05:53 +1100318 _setup_package_with_constraints_edit $bindep $project_dir "" $extras
Dean Troyer490430d2015-01-30 14:38:35 -0600319}
320
321# this should be used for projects which run services, like all services
Brant Knudson0842b812015-08-03 13:31:25 -0500322#
323# setup_develop project_dir [extras]
324# project_dir: directory of project repo (e.g., /opt/stack/keystone)
325# extras: comma-separated list of optional dependencies to install
326# (e.g., ldap,memcache).
Takashi NATSUMEfa007772017-07-22 08:59:43 +0900327# See https://docs.openstack.org/pbr/latest/user/using.html#extra-requirements
Brant Knudson0842b812015-08-03 13:31:25 -0500328# The command is like "pip install -e <project_dir>[<extras>]"
Dean Troyer490430d2015-01-30 14:38:35 -0600329function setup_develop {
Ian Wienand58243f62018-12-13 14:05:53 +1100330 local bindep
331 if [[ $1 == -bindep* ]]; then
332 bindep="${1}"
333 shift
334 fi
Dean Troyer490430d2015-01-30 14:38:35 -0600335 local project_dir=$1
Brant Knudson0842b812015-08-03 13:31:25 -0500336 local extras=$2
Ian Wienand58243f62018-12-13 14:05:53 +1100337 _setup_package_with_constraints_edit $bindep $project_dir -e $extras
Dean Troyer490430d2015-01-30 14:38:35 -0600338}
339
Dean Troyer490430d2015-01-30 14:38:35 -0600340# ``pip install -e`` the package, which processes the dependencies
341# using pip before running `setup.py develop`
342#
Clark Boylan05aa3842015-08-03 11:14:13 -0700343# Updates the constraints from REQUIREMENTS_DIR to reflect the
344# future installed state of this package. This ensures when we
345# install this package we get the from source version.
Dean Troyer490430d2015-01-30 14:38:35 -0600346#
Clark Boylan05aa3842015-08-03 11:14:13 -0700347# Uses globals ``REQUIREMENTS_DIR``
Brant Knudson0842b812015-08-03 13:31:25 -0500348# _setup_package_with_constraints_edit project_dir flags [extras]
349# project_dir: directory of project repo (e.g., /opt/stack/keystone)
350# flags: pip CLI options/flags
351# extras: comma-separated list of optional dependencies to install
352# (e.g., ldap,memcache).
Takashi NATSUMEfa007772017-07-22 08:59:43 +0900353# See https://docs.openstack.org/pbr/latest/user/using.html#extra-requirements
Brant Knudson0842b812015-08-03 13:31:25 -0500354# The command is like "pip install <flags> <project_dir>[<extras>]"
355function _setup_package_with_constraints_edit {
Ian Wienand58243f62018-12-13 14:05:53 +1100356 local bindep
357 if [[ $1 == -bindep* ]]; then
358 bindep="${1}"
359 shift
360 fi
Dean Troyer490430d2015-01-30 14:38:35 -0600361 local project_dir=$1
362 local flags=$2
Brant Knudson0842b812015-08-03 13:31:25 -0500363 local extras=$3
Dean Troyer490430d2015-01-30 14:38:35 -0600364
YAMAMOTO Takashic8c1c612016-03-22 14:29:47 +0900365 # Normalize the directory name to avoid
366 # "installation from path or url cannot be constrained to a version"
367 # error.
368 # REVISIT(yamamoto): Remove this when fixed in pip.
369 # https://github.com/pypa/pip/pull/3582
370 project_dir=$(cd $project_dir && pwd)
371
Robert Collins635a5ba2015-06-10 08:48:06 +1200372 if [ -n "$REQUIREMENTS_DIR" ]; then
373 # Constrain this package to this project directory from here on out.
Ian Wienandada886d2015-10-07 14:06:26 +1100374 local name
375 name=$(awk '/^name.*=/ {print $3}' $project_dir/setup.cfg)
Robert Collins7c838612015-07-03 13:28:09 +1200376 $REQUIREMENTS_DIR/.venv/bin/edit-constraints \
377 $REQUIREMENTS_DIR/upper-constraints.txt -- $name \
378 "$flags file://$project_dir#egg=$name"
Robert Collins635a5ba2015-06-10 08:48:06 +1200379 fi
380
Ian Wienand58243f62018-12-13 14:05:53 +1100381 setup_package $bindep $project_dir "$flags" $extras
Dean Troyer490430d2015-01-30 14:38:35 -0600382
James E. Blaire1edde32018-03-02 15:05:14 +0000383 # If this project is in LIBS_FROM_GIT, verify it was actually installed
384 # correctly. This helps catch errors caused by constraints mismatches.
385 if use_library_from_git "$project_dir"; then
386 if ! lib_installed_from_git "$project_dir"; then
387 die $LINENO "The following LIBS_FROM_GIT was not installed correctly: $project_dir"
388 fi
389 fi
Dean Troyer490430d2015-01-30 14:38:35 -0600390}
391
392# ``pip install -e`` the package, which processes the dependencies
Ian Wienand58243f62018-12-13 14:05:53 +1100393# using pip before running `setup.py develop`. The command is like
394# "pip install <flags> <project_dir>[<extras>]"
Brant Knudson0842b812015-08-03 13:31:25 -0500395#
Dean Troyer490430d2015-01-30 14:38:35 -0600396# Uses globals ``STACK_USER``
Ian Wienand58243f62018-12-13 14:05:53 +1100397#
398# Usage:
399# setup_package [-bindep[=profile,profile]] <project_dir> <flags> [extras]
400#
401# -bindep : Use bindep to install dependencies; select extra profiles
402# as comma separated arguments after "="
403# project_dir : directory of project repo (e.g., /opt/stack/keystone)
404# flags : pip CLI options/flags
405# extras : comma-separated list of optional dependencies to install
406# (e.g., ldap,memcache).
407# See https://docs.openstack.org/pbr/latest/user/using.html#extra-requirements
Dean Troyer490430d2015-01-30 14:38:35 -0600408function setup_package {
Ian Wienand58243f62018-12-13 14:05:53 +1100409 local bindep=0
410 local bindep_flag=""
411 local bindep_profiles=""
412 if [[ $1 == -bindep* ]]; then
413 bindep=1
414 IFS="=" read bindep_flag bindep_profiles <<< ${1}
415 shift
416 fi
Dean Troyer490430d2015-01-30 14:38:35 -0600417 local project_dir=$1
418 local flags=$2
Brant Knudson0842b812015-08-03 13:31:25 -0500419 local extras=$3
Dean Troyer490430d2015-01-30 14:38:35 -0600420
Brant Knudson0842b812015-08-03 13:31:25 -0500421 # if the flags variable exists, and it doesn't look like a flag,
422 # assume it's actually the extras list.
423 if [[ -n "$flags" && -z "$extras" && ! "$flags" =~ ^-.* ]]; then
424 extras=$flags
425 flags=""
426 fi
427
428 if [[ ! -z "$extras" ]]; then
429 extras="[$extras]"
430 fi
431
Ian Wienand58243f62018-12-13 14:05:53 +1100432 # install any bindep packages
433 if [[ $bindep == 1 ]]; then
434 install_bindep $project_dir/bindep.txt $bindep_profiles
435 fi
436
Brant Knudson0842b812015-08-03 13:31:25 -0500437 pip_install $flags "$project_dir$extras"
Dean Troyer490430d2015-01-30 14:38:35 -0600438 # ensure that further actions can do things like setup.py sdist
439 if [[ "$flags" == "-e" ]]; then
440 safe_chown -R $STACK_USER $1/*.egg-info
441 fi
442}
443
Doug Hellmannddc38392015-05-07 21:06:24 +0000444# Report whether python 3 should be used
445function python3_enabled {
446 if [[ $USE_PYTHON3 == "True" ]]; then
447 return 0
448 else
449 return 1
450 fi
451}
452
453# Install python3 packages
454function install_python3 {
455 if is_ubuntu; then
Lubosz "diltram" Kosnik0a099762016-08-03 10:21:41 -0500456 apt_get install python${PYTHON3_VERSION} python${PYTHON3_VERSION}-dev
Armando Migliacciobacfb942017-03-20 22:27:20 -0700457 elif is_suse; then
458 install_package python3-devel python3-dbm
Doug Hellmannddc38392015-05-07 21:06:24 +0000459 fi
460}
Dean Troyer490430d2015-01-30 14:38:35 -0600461
Sean Daguef80e2cf2017-01-18 15:42:32 -0500462function install_devstack_tools {
463 # intentionally old to ensure devstack-gate has control
464 local dstools_version=${DSTOOLS_VERSION:-0.1.2}
465 install_python3
466 sudo pip3 install -U devstack-tools==${dstools_version}
467}
468
Dean Troyer490430d2015-01-30 14:38:35 -0600469# Restore xtrace
470$INC_PY_TRACE
471
472# Local variables:
473# mode: shell-script
474# End: