Dean Troyer | 490430d | 2015-01-30 14:38:35 -0600 | [diff] [blame] | 1 | #!/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 |
| 14 | INC_PY_TRACE=$(set +o | grep xtrace) |
| 15 | set +o xtrace |
| 16 | |
| 17 | |
Dean Troyer | 8c2ce6e | 2015-02-18 14:47:54 -0600 | [diff] [blame] | 18 | # Global Config Variables |
| 19 | |
Atsushi SAKAI | 5509ed5 | 2015-11-30 20:20:21 +0900 | [diff] [blame] | 20 | # PROJECT_VENV contains the name of the virtual environment for each |
Dean Troyer | 8c2ce6e | 2015-02-18 14:47:54 -0600 | [diff] [blame] | 21 | # project. A null value installs to the system Python directories. |
| 22 | declare -A PROJECT_VENV |
| 23 | |
| 24 | |
Dean Troyer | 490430d | 2015-01-30 14:38:35 -0600 | [diff] [blame] | 25 | # Python Functions |
| 26 | # ================ |
| 27 | |
| 28 | # Get the path to the pip command. |
| 29 | # get_pip_command |
| 30 | function get_pip_command { |
Doug Hellmann | ddc3839 | 2015-05-07 21:06:24 +0000 | [diff] [blame] | 31 | local version="$1" |
| 32 | # NOTE(dhellmann): I don't know if we actually get a pip3.4-python |
| 33 | # under any circumstances. |
| 34 | which pip${version} || which pip${version}-python |
Dean Troyer | 490430d | 2015-01-30 14:38:35 -0600 | [diff] [blame] | 35 | |
| 36 | if [ $? -ne 0 ]; then |
Doug Hellmann | ddc3839 | 2015-05-07 21:06:24 +0000 | [diff] [blame] | 37 | die $LINENO "Unable to find pip${version}; cannot continue" |
Dean Troyer | 490430d | 2015-01-30 14:38:35 -0600 | [diff] [blame] | 38 | fi |
| 39 | } |
| 40 | |
Atsushi SAKAI | 5509ed5 | 2015-11-30 20:20:21 +0900 | [diff] [blame] | 41 | # Get the path to the directory where python executables are installed. |
Dean Troyer | 490430d | 2015-01-30 14:38:35 -0600 | [diff] [blame] | 42 | # get_python_exec_prefix |
| 43 | function get_python_exec_prefix { |
Ian Wienand | 433a9b1 | 2015-10-07 13:29:31 +1100 | [diff] [blame] | 44 | local xtrace |
| 45 | xtrace=$(set +o | grep xtrace) |
Dean Troyer | 2b56476 | 2015-02-11 17:01:02 -0600 | [diff] [blame] | 46 | set +o xtrace |
| 47 | if [[ -z "$os_PACKAGE" ]]; then |
| 48 | GetOSVersion |
| 49 | fi |
| 50 | $xtrace |
| 51 | |
Dean Troyer | 490430d | 2015-01-30 14:38:35 -0600 | [diff] [blame] | 52 | if is_fedora || is_suse; then |
| 53 | echo "/usr/bin" |
| 54 | else |
| 55 | echo "/usr/local/bin" |
| 56 | fi |
| 57 | } |
| 58 | |
Sean Dague | 60996b1 | 2015-04-08 09:06:49 -0400 | [diff] [blame] | 59 | # Wrapper for ``pip install`` that only installs versions of libraries |
| 60 | # from the global-requirements specification. |
| 61 | # |
| 62 | # Uses globals ``REQUIREMENTS_DIR`` |
| 63 | # |
| 64 | # pip_install_gr packagename |
| 65 | function pip_install_gr { |
| 66 | local name=$1 |
Ian Wienand | ada886d | 2015-10-07 14:06:26 +1100 | [diff] [blame] | 67 | local clean_name |
| 68 | clean_name=$(get_from_global_requirements $name) |
Sean Dague | 60996b1 | 2015-04-08 09:06:49 -0400 | [diff] [blame] | 69 | pip_install $clean_name |
| 70 | } |
| 71 | |
Doug Hellmann | ddc3839 | 2015-05-07 21:06:24 +0000 | [diff] [blame] | 72 | # Determine the python versions supported by a package |
| 73 | function get_python_versions_for_package { |
| 74 | local name=$1 |
| 75 | cd $name && python setup.py --classifiers \ |
| 76 | | grep 'Language' | cut -f5 -d: | grep '\.' | tr '\n' ' ' |
| 77 | } |
| 78 | |
Dean Troyer | 490430d | 2015-01-30 14:38:35 -0600 | [diff] [blame] | 79 | # Wrapper for ``pip install`` to set cache and proxy environment variables |
Dean Troyer | 41d6f85 | 2015-03-25 22:42:46 -0500 | [diff] [blame] | 80 | # Uses globals ``OFFLINE``, ``PIP_VIRTUAL_ENV``, |
Robert Collins | 635a5ba | 2015-06-10 08:48:06 +1200 | [diff] [blame] | 81 | # ``PIP_UPGRADE``, ``TRACK_DEPENDS``, ``*_proxy``, |
Dean Troyer | 490430d | 2015-01-30 14:38:35 -0600 | [diff] [blame] | 82 | # pip_install package [package ...] |
| 83 | function pip_install { |
Federico Ressi | e208d06 | 2015-11-21 11:15:39 +0000 | [diff] [blame] | 84 | local xtrace result |
Ian Wienand | 433a9b1 | 2015-10-07 13:29:31 +1100 | [diff] [blame] | 85 | xtrace=$(set +o | grep xtrace) |
Dean Troyer | 490430d | 2015-01-30 14:38:35 -0600 | [diff] [blame] | 86 | set +o xtrace |
Chris Dent | ebdd9ac | 2015-03-04 12:35:14 +0000 | [diff] [blame] | 87 | local upgrade="" |
Dean Troyer | 490430d | 2015-01-30 14:38:35 -0600 | [diff] [blame] | 88 | local offline=${OFFLINE:-False} |
| 89 | if [[ "$offline" == "True" || -z "$@" ]]; then |
| 90 | $xtrace |
| 91 | return |
| 92 | fi |
| 93 | |
Sean Dague | cb658fa | 2015-10-08 17:12:03 -0400 | [diff] [blame] | 94 | time_start "pip_install" |
| 95 | |
Chris Dent | ebdd9ac | 2015-03-04 12:35:14 +0000 | [diff] [blame] | 96 | PIP_UPGRADE=$(trueorfalse False PIP_UPGRADE) |
| 97 | if [[ "$PIP_UPGRADE" = "True" ]] ; then |
| 98 | upgrade="--upgrade" |
| 99 | fi |
| 100 | |
Dean Troyer | 490430d | 2015-01-30 14:38:35 -0600 | [diff] [blame] | 101 | if [[ -z "$os_PACKAGE" ]]; then |
| 102 | GetOSVersion |
| 103 | fi |
| 104 | if [[ $TRACK_DEPENDS = True && ! "$@" =~ virtualenv ]]; then |
| 105 | # TRACK_DEPENDS=True installation creates a circular dependency when |
Atsushi SAKAI | 5509ed5 | 2015-11-30 20:20:21 +0900 | [diff] [blame] | 106 | # we attempt to install virtualenv into a virtualenv, so we must global |
Dean Troyer | 490430d | 2015-01-30 14:38:35 -0600 | [diff] [blame] | 107 | # that installation. |
| 108 | source $DEST/.venv/bin/activate |
| 109 | local cmd_pip=$DEST/.venv/bin/pip |
| 110 | local sudo_pip="env" |
| 111 | else |
Dean Troyer | 2b56476 | 2015-02-11 17:01:02 -0600 | [diff] [blame] | 112 | if [[ -n ${PIP_VIRTUAL_ENV:=} && -d ${PIP_VIRTUAL_ENV} ]]; then |
| 113 | local cmd_pip=$PIP_VIRTUAL_ENV/bin/pip |
| 114 | local sudo_pip="env" |
| 115 | else |
Ian Wienand | ada886d | 2015-10-07 14:06:26 +1100 | [diff] [blame] | 116 | local cmd_pip |
Doug Hellmann | ddc3839 | 2015-05-07 21:06:24 +0000 | [diff] [blame] | 117 | cmd_pip=$(get_pip_command $PYTHON2_VERSION) |
Dean Troyer | 2b56476 | 2015-02-11 17:01:02 -0600 | [diff] [blame] | 118 | local sudo_pip="sudo -H" |
Doug Hellmann | ddc3839 | 2015-05-07 21:06:24 +0000 | [diff] [blame] | 119 | if python3_enabled; then |
| 120 | # Look at the package classifiers to find the python |
| 121 | # versions supported, and if we find the version of |
| 122 | # python3 we've been told to use, use that instead of the |
| 123 | # default pip |
| 124 | local package_dir=${!#} |
| 125 | local python_versions |
| 126 | if [[ -d "$package_dir" ]]; then |
| 127 | python_versions=$(get_python_versions_for_package $package_dir) |
| 128 | if [[ $python_versions =~ $PYTHON3_VERSION ]]; then |
| 129 | cmd_pip=$(get_pip_command $PYTHON3_VERSION) |
| 130 | fi |
| 131 | fi |
| 132 | fi |
Dean Troyer | 2b56476 | 2015-02-11 17:01:02 -0600 | [diff] [blame] | 133 | fi |
Dean Troyer | 490430d | 2015-01-30 14:38:35 -0600 | [diff] [blame] | 134 | fi |
| 135 | |
Robert Collins | 635a5ba | 2015-06-10 08:48:06 +1200 | [diff] [blame] | 136 | cmd_pip="$cmd_pip install" |
Clark Boylan | 05aa384 | 2015-08-03 11:14:13 -0700 | [diff] [blame] | 137 | # Always apply constraints |
| 138 | cmd_pip="$cmd_pip -c $REQUIREMENTS_DIR/upper-constraints.txt" |
Robert Collins | 635a5ba | 2015-06-10 08:48:06 +1200 | [diff] [blame] | 139 | |
Doug Hellmann | ddc3839 | 2015-05-07 21:06:24 +0000 | [diff] [blame] | 140 | # FIXME(dhellmann): Need to force multiple versions of pip for |
| 141 | # packages like setuptools? |
Ian Wienand | ada886d | 2015-10-07 14:06:26 +1100 | [diff] [blame] | 142 | local pip_version |
| 143 | pip_version=$(python -c "import pip; \ |
Dean Troyer | 490430d | 2015-01-30 14:38:35 -0600 | [diff] [blame] | 144 | print(pip.__version__.strip('.')[0])") |
| 145 | if (( pip_version<6 )); then |
| 146 | die $LINENO "Currently installed pip version ${pip_version} does not" \ |
| 147 | "meet minimum requirements (>=6)." |
| 148 | fi |
| 149 | |
| 150 | $xtrace |
Spyros Trigazis | 88ccd47 | 2016-07-24 22:13:57 +0200 | [diff] [blame] | 151 | # adding SETUPTOOLS_SYS_PATH_TECHNIQUE is a workaround to keep |
| 152 | # the same behaviour of setuptools before version 25.0.0. |
| 153 | # related issue: https://github.com/pypa/pip/issues/3874 |
Dean Troyer | 490430d | 2015-01-30 14:38:35 -0600 | [diff] [blame] | 154 | $sudo_pip \ |
Eli Qiao | 6a83c42 | 2015-03-17 16:54:16 +0800 | [diff] [blame] | 155 | http_proxy="${http_proxy:-}" \ |
| 156 | https_proxy="${https_proxy:-}" \ |
| 157 | no_proxy="${no_proxy:-}" \ |
Joe Gordon | cd8824a | 2015-03-04 16:40:19 -0800 | [diff] [blame] | 158 | PIP_FIND_LINKS=$PIP_FIND_LINKS \ |
Spyros Trigazis | 88ccd47 | 2016-07-24 22:13:57 +0200 | [diff] [blame] | 159 | SETUPTOOLS_SYS_PATH_TECHNIQUE=rewrite \ |
Robert Collins | 635a5ba | 2015-06-10 08:48:06 +1200 | [diff] [blame] | 160 | $cmd_pip $upgrade \ |
Dean Troyer | 490430d | 2015-01-30 14:38:35 -0600 | [diff] [blame] | 161 | $@ |
Federico Ressi | e208d06 | 2015-11-21 11:15:39 +0000 | [diff] [blame] | 162 | result=$? |
Dean Troyer | 490430d | 2015-01-30 14:38:35 -0600 | [diff] [blame] | 163 | |
Sean Dague | eeb7bda | 2015-03-25 11:55:32 -0400 | [diff] [blame] | 164 | # Also install test requirements |
Sirushti Murugesan | 713fd2f | 2015-09-30 15:12:50 +0530 | [diff] [blame] | 165 | local test_req="${!#}/test-requirements.txt" |
Federico Ressi | e208d06 | 2015-11-21 11:15:39 +0000 | [diff] [blame] | 166 | if [[ $result == 0 ]] && [[ -e "$test_req" ]]; then |
Sean Dague | eeb7bda | 2015-03-25 11:55:32 -0400 | [diff] [blame] | 167 | echo "Installing test-requirements for $test_req" |
| 168 | $sudo_pip \ |
| 169 | http_proxy=${http_proxy:-} \ |
| 170 | https_proxy=${https_proxy:-} \ |
| 171 | no_proxy=${no_proxy:-} \ |
| 172 | PIP_FIND_LINKS=$PIP_FIND_LINKS \ |
Robert Collins | 635a5ba | 2015-06-10 08:48:06 +1200 | [diff] [blame] | 173 | $cmd_pip $upgrade \ |
Sean Dague | eeb7bda | 2015-03-25 11:55:32 -0400 | [diff] [blame] | 174 | -r $test_req |
Federico Ressi | e208d06 | 2015-11-21 11:15:39 +0000 | [diff] [blame] | 175 | result=$? |
Dean Troyer | 490430d | 2015-01-30 14:38:35 -0600 | [diff] [blame] | 176 | fi |
Sean Dague | cb658fa | 2015-10-08 17:12:03 -0400 | [diff] [blame] | 177 | |
| 178 | time_stop "pip_install" |
Federico Ressi | e208d06 | 2015-11-21 11:15:39 +0000 | [diff] [blame] | 179 | return $result |
Dean Troyer | 490430d | 2015-01-30 14:38:35 -0600 | [diff] [blame] | 180 | } |
| 181 | |
Joe Gordon | d5ac785 | 2015-02-06 19:29:23 -0800 | [diff] [blame] | 182 | # get version of a package from global requirements file |
| 183 | # get_from_global_requirements <package> |
| 184 | function get_from_global_requirements { |
| 185 | local package=$1 |
Ian Wienand | ada886d | 2015-10-07 14:06:26 +1100 | [diff] [blame] | 186 | local required_pkg |
| 187 | required_pkg=$(grep -i -h ^${package} $REQUIREMENTS_DIR/global-requirements.txt | cut -d\# -f1) |
Joe Gordon | d5ac785 | 2015-02-06 19:29:23 -0800 | [diff] [blame] | 188 | if [[ $required_pkg == "" ]]; then |
| 189 | die $LINENO "Can't find package $package in requirements" |
| 190 | fi |
| 191 | echo $required_pkg |
| 192 | } |
| 193 | |
Dean Troyer | 490430d | 2015-01-30 14:38:35 -0600 | [diff] [blame] | 194 | # should we use this library from their git repo, or should we let it |
| 195 | # get pulled in via pip dependencies. |
| 196 | function use_library_from_git { |
| 197 | local name=$1 |
| 198 | local enabled=1 |
Marc Koderer | 46f8cb7 | 2016-05-13 09:08:16 +0200 | [diff] [blame] | 199 | [[ ${LIBS_FROM_GIT} = 'ALL' ]] || [[ ,${LIBS_FROM_GIT}, =~ ,${name}, ]] && enabled=0 |
Dean Troyer | 490430d | 2015-01-30 14:38:35 -0600 | [diff] [blame] | 200 | return $enabled |
| 201 | } |
| 202 | |
Sean Dague | c71973e | 2015-09-08 07:12:48 -0400 | [diff] [blame] | 203 | # determine if a package was installed from git |
| 204 | function lib_installed_from_git { |
| 205 | local name=$1 |
| 206 | pip freeze 2>/dev/null | grep -- "$name" | grep -q -- '-e git' |
| 207 | } |
| 208 | |
| 209 | # check that everything that's in LIBS_FROM_GIT was actually installed |
| 210 | # correctly, this helps double check issues with library fat fingering. |
| 211 | function check_libs_from_git { |
| 212 | local lib="" |
| 213 | local not_installed="" |
| 214 | for lib in $(echo ${LIBS_FROM_GIT} | tr "," " "); do |
| 215 | if ! lib_installed_from_git "$lib"; then |
| 216 | not_installed+=" $lib" |
| 217 | fi |
| 218 | done |
| 219 | # if anything is not installed, say what it is. |
| 220 | if [[ -n "$not_installed" ]]; then |
| 221 | die $LINENO "The following LIBS_FROM_GIT were not installed correct: $not_installed" |
| 222 | fi |
| 223 | } |
| 224 | |
Dean Troyer | 490430d | 2015-01-30 14:38:35 -0600 | [diff] [blame] | 225 | # setup a library by name. If we are trying to use the library from |
| 226 | # git, we'll do a git based install, otherwise we'll punt and the |
| 227 | # library should be installed by a requirements pull from another |
| 228 | # project. |
| 229 | function setup_lib { |
| 230 | local name=$1 |
| 231 | local dir=${GITDIR[$name]} |
| 232 | setup_install $dir |
| 233 | } |
| 234 | |
Atsushi SAKAI | 5509ed5 | 2015-11-30 20:20:21 +0900 | [diff] [blame] | 235 | # setup a library by name in editable mode. If we are trying to use |
Dean Troyer | 490430d | 2015-01-30 14:38:35 -0600 | [diff] [blame] | 236 | # the library from git, we'll do a git based install, otherwise we'll |
| 237 | # punt and the library should be installed by a requirements pull from |
| 238 | # another project. |
| 239 | # |
| 240 | # use this for non namespaced libraries |
| 241 | function setup_dev_lib { |
| 242 | local name=$1 |
| 243 | local dir=${GITDIR[$name]} |
| 244 | setup_develop $dir |
| 245 | } |
| 246 | |
| 247 | # this should be used if you want to install globally, all libraries should |
| 248 | # use this, especially *oslo* ones |
Brant Knudson | 0842b81 | 2015-08-03 13:31:25 -0500 | [diff] [blame] | 249 | # |
| 250 | # setup_install project_dir [extras] |
| 251 | # project_dir: directory of project repo (e.g., /opt/stack/keystone) |
| 252 | # extras: comma-separated list of optional dependencies to install |
| 253 | # (e.g., ldap,memcache). |
| 254 | # See http://docs.openstack.org/developer/pbr/#extra-requirements |
| 255 | # The command is like "pip install <project_dir>[<extras>]" |
Dean Troyer | 490430d | 2015-01-30 14:38:35 -0600 | [diff] [blame] | 256 | function setup_install { |
| 257 | local project_dir=$1 |
Brant Knudson | 0842b81 | 2015-08-03 13:31:25 -0500 | [diff] [blame] | 258 | local extras=$2 |
| 259 | _setup_package_with_constraints_edit $project_dir "" $extras |
Dean Troyer | 490430d | 2015-01-30 14:38:35 -0600 | [diff] [blame] | 260 | } |
| 261 | |
| 262 | # this should be used for projects which run services, like all services |
Brant Knudson | 0842b81 | 2015-08-03 13:31:25 -0500 | [diff] [blame] | 263 | # |
| 264 | # setup_develop project_dir [extras] |
| 265 | # project_dir: directory of project repo (e.g., /opt/stack/keystone) |
| 266 | # extras: comma-separated list of optional dependencies to install |
| 267 | # (e.g., ldap,memcache). |
| 268 | # See http://docs.openstack.org/developer/pbr/#extra-requirements |
| 269 | # The command is like "pip install -e <project_dir>[<extras>]" |
Dean Troyer | 490430d | 2015-01-30 14:38:35 -0600 | [diff] [blame] | 270 | function setup_develop { |
| 271 | local project_dir=$1 |
Brant Knudson | 0842b81 | 2015-08-03 13:31:25 -0500 | [diff] [blame] | 272 | local extras=$2 |
| 273 | _setup_package_with_constraints_edit $project_dir -e $extras |
Dean Troyer | 490430d | 2015-01-30 14:38:35 -0600 | [diff] [blame] | 274 | } |
| 275 | |
| 276 | # determine if a project as specified by directory is in |
| 277 | # projects.txt. This will not be an exact match because we throw away |
| 278 | # the namespacing when we clone, but it should be good enough in all |
| 279 | # practical ways. |
| 280 | function is_in_projects_txt { |
| 281 | local project_dir=$1 |
Ian Wienand | ada886d | 2015-10-07 14:06:26 +1100 | [diff] [blame] | 282 | local project_name |
| 283 | project_name=$(basename $project_dir) |
Ihar Hrachyshka | 2ba4a72 | 2015-06-26 10:45:44 +0200 | [diff] [blame] | 284 | grep -q "/$project_name\$" $REQUIREMENTS_DIR/projects.txt |
Dean Troyer | 490430d | 2015-01-30 14:38:35 -0600 | [diff] [blame] | 285 | } |
| 286 | |
| 287 | # ``pip install -e`` the package, which processes the dependencies |
| 288 | # using pip before running `setup.py develop` |
| 289 | # |
Clark Boylan | 05aa384 | 2015-08-03 11:14:13 -0700 | [diff] [blame] | 290 | # Updates the constraints from REQUIREMENTS_DIR to reflect the |
| 291 | # future installed state of this package. This ensures when we |
| 292 | # install this package we get the from source version. |
Dean Troyer | 490430d | 2015-01-30 14:38:35 -0600 | [diff] [blame] | 293 | # |
Clark Boylan | 05aa384 | 2015-08-03 11:14:13 -0700 | [diff] [blame] | 294 | # Uses globals ``REQUIREMENTS_DIR`` |
Brant Knudson | 0842b81 | 2015-08-03 13:31:25 -0500 | [diff] [blame] | 295 | # _setup_package_with_constraints_edit project_dir flags [extras] |
| 296 | # project_dir: directory of project repo (e.g., /opt/stack/keystone) |
| 297 | # flags: pip CLI options/flags |
| 298 | # extras: comma-separated list of optional dependencies to install |
| 299 | # (e.g., ldap,memcache). |
| 300 | # See http://docs.openstack.org/developer/pbr/#extra-requirements |
| 301 | # The command is like "pip install <flags> <project_dir>[<extras>]" |
| 302 | function _setup_package_with_constraints_edit { |
Dean Troyer | 490430d | 2015-01-30 14:38:35 -0600 | [diff] [blame] | 303 | local project_dir=$1 |
| 304 | local flags=$2 |
Brant Knudson | 0842b81 | 2015-08-03 13:31:25 -0500 | [diff] [blame] | 305 | local extras=$3 |
Dean Troyer | 490430d | 2015-01-30 14:38:35 -0600 | [diff] [blame] | 306 | |
YAMAMOTO Takashi | c8c1c61 | 2016-03-22 14:29:47 +0900 | [diff] [blame] | 307 | # Normalize the directory name to avoid |
| 308 | # "installation from path or url cannot be constrained to a version" |
| 309 | # error. |
| 310 | # REVISIT(yamamoto): Remove this when fixed in pip. |
| 311 | # https://github.com/pypa/pip/pull/3582 |
| 312 | project_dir=$(cd $project_dir && pwd) |
| 313 | |
Robert Collins | 635a5ba | 2015-06-10 08:48:06 +1200 | [diff] [blame] | 314 | if [ -n "$REQUIREMENTS_DIR" ]; then |
| 315 | # Constrain this package to this project directory from here on out. |
Ian Wienand | ada886d | 2015-10-07 14:06:26 +1100 | [diff] [blame] | 316 | local name |
| 317 | name=$(awk '/^name.*=/ {print $3}' $project_dir/setup.cfg) |
Robert Collins | 7c83861 | 2015-07-03 13:28:09 +1200 | [diff] [blame] | 318 | $REQUIREMENTS_DIR/.venv/bin/edit-constraints \ |
| 319 | $REQUIREMENTS_DIR/upper-constraints.txt -- $name \ |
| 320 | "$flags file://$project_dir#egg=$name" |
Robert Collins | 635a5ba | 2015-06-10 08:48:06 +1200 | [diff] [blame] | 321 | fi |
| 322 | |
Brant Knudson | 0842b81 | 2015-08-03 13:31:25 -0500 | [diff] [blame] | 323 | setup_package $project_dir "$flags" $extras |
Dean Troyer | 490430d | 2015-01-30 14:38:35 -0600 | [diff] [blame] | 324 | |
Dean Troyer | 490430d | 2015-01-30 14:38:35 -0600 | [diff] [blame] | 325 | } |
| 326 | |
| 327 | # ``pip install -e`` the package, which processes the dependencies |
| 328 | # using pip before running `setup.py develop` |
Brant Knudson | 0842b81 | 2015-08-03 13:31:25 -0500 | [diff] [blame] | 329 | # |
Dean Troyer | 490430d | 2015-01-30 14:38:35 -0600 | [diff] [blame] | 330 | # Uses globals ``STACK_USER`` |
Brant Knudson | 0842b81 | 2015-08-03 13:31:25 -0500 | [diff] [blame] | 331 | # setup_package project_dir [flags] [extras] |
| 332 | # project_dir: directory of project repo (e.g., /opt/stack/keystone) |
| 333 | # flags: pip CLI options/flags |
| 334 | # extras: comma-separated list of optional dependencies to install |
| 335 | # (e.g., ldap,memcache). |
| 336 | # See http://docs.openstack.org/developer/pbr/#extra-requirements |
| 337 | # The command is like "pip install <flags> <project_dir>[<extras>]" |
Dean Troyer | 490430d | 2015-01-30 14:38:35 -0600 | [diff] [blame] | 338 | function setup_package { |
| 339 | local project_dir=$1 |
| 340 | local flags=$2 |
Brant Knudson | 0842b81 | 2015-08-03 13:31:25 -0500 | [diff] [blame] | 341 | local extras=$3 |
Dean Troyer | 490430d | 2015-01-30 14:38:35 -0600 | [diff] [blame] | 342 | |
Brant Knudson | 0842b81 | 2015-08-03 13:31:25 -0500 | [diff] [blame] | 343 | # if the flags variable exists, and it doesn't look like a flag, |
| 344 | # assume it's actually the extras list. |
| 345 | if [[ -n "$flags" && -z "$extras" && ! "$flags" =~ ^-.* ]]; then |
| 346 | extras=$flags |
| 347 | flags="" |
| 348 | fi |
| 349 | |
| 350 | if [[ ! -z "$extras" ]]; then |
| 351 | extras="[$extras]" |
| 352 | fi |
| 353 | |
| 354 | pip_install $flags "$project_dir$extras" |
Dean Troyer | 490430d | 2015-01-30 14:38:35 -0600 | [diff] [blame] | 355 | # ensure that further actions can do things like setup.py sdist |
| 356 | if [[ "$flags" == "-e" ]]; then |
| 357 | safe_chown -R $STACK_USER $1/*.egg-info |
| 358 | fi |
| 359 | } |
| 360 | |
Doug Hellmann | ddc3839 | 2015-05-07 21:06:24 +0000 | [diff] [blame] | 361 | # Report whether python 3 should be used |
| 362 | function python3_enabled { |
| 363 | if [[ $USE_PYTHON3 == "True" ]]; then |
| 364 | return 0 |
| 365 | else |
| 366 | return 1 |
| 367 | fi |
| 368 | } |
| 369 | |
| 370 | # Install python3 packages |
| 371 | function install_python3 { |
| 372 | if is_ubuntu; then |
Lubosz "diltram" Kosnik | 0a09976 | 2016-08-03 10:21:41 -0500 | [diff] [blame] | 373 | apt_get install python${PYTHON3_VERSION} python${PYTHON3_VERSION}-dev |
Doug Hellmann | ddc3839 | 2015-05-07 21:06:24 +0000 | [diff] [blame] | 374 | fi |
| 375 | } |
Dean Troyer | 490430d | 2015-01-30 14:38:35 -0600 | [diff] [blame] | 376 | |
| 377 | # Restore xtrace |
| 378 | $INC_PY_TRACE |
| 379 | |
| 380 | # Local variables: |
| 381 | # mode: shell-script |
| 382 | # End: |