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