Move Python-related functions into inc/python
Should be transparent to all callers as it is sourced from functions-common
Change-Id: I88043830cef9211b4e0baa91bfcc7a92125afa9f
| ... | ... |
@@ -15,7 +15,6 @@ |
| 15 | 15 |
# - OpenStack Functions |
| 16 | 16 |
# - Package Functions |
| 17 | 17 |
# - Process Functions |
| 18 |
-# - Python Functions |
|
| 19 | 18 |
# - Service Functions |
| 20 | 19 |
# - System Functions |
| 21 | 20 |
# |
| ... | ... |
@@ -1590,204 +1589,6 @@ function screen_stop {
|
| 1590 | 1590 |
} |
| 1591 | 1591 |
|
| 1592 | 1592 |
|
| 1593 |
-# Python Functions |
|
| 1594 |
-# ================ |
|
| 1595 |
- |
|
| 1596 |
-# Get the path to the pip command. |
|
| 1597 |
-# get_pip_command |
|
| 1598 |
-function get_pip_command {
|
|
| 1599 |
- which pip || which pip-python |
|
| 1600 |
- |
|
| 1601 |
- if [ $? -ne 0 ]; then |
|
| 1602 |
- die $LINENO "Unable to find pip; cannot continue" |
|
| 1603 |
- fi |
|
| 1604 |
-} |
|
| 1605 |
- |
|
| 1606 |
-# Get the path to the direcotry where python executables are installed. |
|
| 1607 |
-# get_python_exec_prefix |
|
| 1608 |
-function get_python_exec_prefix {
|
|
| 1609 |
- if is_fedora || is_suse; then |
|
| 1610 |
- echo "/usr/bin" |
|
| 1611 |
- else |
|
| 1612 |
- echo "/usr/local/bin" |
|
| 1613 |
- fi |
|
| 1614 |
-} |
|
| 1615 |
- |
|
| 1616 |
-# Wrapper for ``pip install`` to set cache and proxy environment variables |
|
| 1617 |
-# Uses globals ``OFFLINE``, ``TRACK_DEPENDS``, ``*_proxy`` |
|
| 1618 |
-# pip_install package [package ...] |
|
| 1619 |
-function pip_install {
|
|
| 1620 |
- local xtrace=$(set +o | grep xtrace) |
|
| 1621 |
- set +o xtrace |
|
| 1622 |
- local offline=${OFFLINE:-False}
|
|
| 1623 |
- if [[ "$offline" == "True" || -z "$@" ]]; then |
|
| 1624 |
- $xtrace |
|
| 1625 |
- return |
|
| 1626 |
- fi |
|
| 1627 |
- |
|
| 1628 |
- if [[ -z "$os_PACKAGE" ]]; then |
|
| 1629 |
- GetOSVersion |
|
| 1630 |
- fi |
|
| 1631 |
- if [[ $TRACK_DEPENDS = True && ! "$@" =~ virtualenv ]]; then |
|
| 1632 |
- # TRACK_DEPENDS=True installation creates a circular dependency when |
|
| 1633 |
- # we attempt to install virtualenv into a virualenv, so we must global |
|
| 1634 |
- # that installation. |
|
| 1635 |
- source $DEST/.venv/bin/activate |
|
| 1636 |
- local cmd_pip=$DEST/.venv/bin/pip |
|
| 1637 |
- local sudo_pip="env" |
|
| 1638 |
- else |
|
| 1639 |
- local cmd_pip=$(get_pip_command) |
|
| 1640 |
- local sudo_pip="sudo -H" |
|
| 1641 |
- fi |
|
| 1642 |
- |
|
| 1643 |
- local pip_version=$(python -c "import pip; \ |
|
| 1644 |
- print(pip.__version__.strip('.')[0])")
|
|
| 1645 |
- if (( pip_version<6 )); then |
|
| 1646 |
- die $LINENO "Currently installed pip version ${pip_version} does not" \
|
|
| 1647 |
- "meet minimum requirements (>=6)." |
|
| 1648 |
- fi |
|
| 1649 |
- |
|
| 1650 |
- $xtrace |
|
| 1651 |
- $sudo_pip \ |
|
| 1652 |
- http_proxy=${http_proxy:-} \
|
|
| 1653 |
- https_proxy=${https_proxy:-} \
|
|
| 1654 |
- no_proxy=${no_proxy:-} \
|
|
| 1655 |
- $cmd_pip install \ |
|
| 1656 |
- $@ |
|
| 1657 |
- |
|
| 1658 |
- INSTALL_TESTONLY_PACKAGES=$(trueorfalse False INSTALL_TESTONLY_PACKAGES) |
|
| 1659 |
- if [[ "$INSTALL_TESTONLY_PACKAGES" == "True" ]]; then |
|
| 1660 |
- local test_req="$@/test-requirements.txt" |
|
| 1661 |
- if [[ -e "$test_req" ]]; then |
|
| 1662 |
- $sudo_pip \ |
|
| 1663 |
- http_proxy=${http_proxy:-} \
|
|
| 1664 |
- https_proxy=${https_proxy:-} \
|
|
| 1665 |
- no_proxy=${no_proxy:-} \
|
|
| 1666 |
- $cmd_pip install \ |
|
| 1667 |
- -r $test_req |
|
| 1668 |
- fi |
|
| 1669 |
- fi |
|
| 1670 |
-} |
|
| 1671 |
- |
|
| 1672 |
-# should we use this library from their git repo, or should we let it |
|
| 1673 |
-# get pulled in via pip dependencies. |
|
| 1674 |
-function use_library_from_git {
|
|
| 1675 |
- local name=$1 |
|
| 1676 |
- local enabled=1 |
|
| 1677 |
- [[ ,${LIBS_FROM_GIT}, =~ ,${name}, ]] && enabled=0
|
|
| 1678 |
- return $enabled |
|
| 1679 |
-} |
|
| 1680 |
- |
|
| 1681 |
-# setup a library by name. If we are trying to use the library from |
|
| 1682 |
-# git, we'll do a git based install, otherwise we'll punt and the |
|
| 1683 |
-# library should be installed by a requirements pull from another |
|
| 1684 |
-# project. |
|
| 1685 |
-function setup_lib {
|
|
| 1686 |
- local name=$1 |
|
| 1687 |
- local dir=${GITDIR[$name]}
|
|
| 1688 |
- setup_install $dir |
|
| 1689 |
-} |
|
| 1690 |
- |
|
| 1691 |
-# setup a library by name in editiable mode. If we are trying to use |
|
| 1692 |
-# the library from git, we'll do a git based install, otherwise we'll |
|
| 1693 |
-# punt and the library should be installed by a requirements pull from |
|
| 1694 |
-# another project. |
|
| 1695 |
-# |
|
| 1696 |
-# use this for non namespaced libraries |
|
| 1697 |
-function setup_dev_lib {
|
|
| 1698 |
- local name=$1 |
|
| 1699 |
- local dir=${GITDIR[$name]}
|
|
| 1700 |
- setup_develop $dir |
|
| 1701 |
-} |
|
| 1702 |
- |
|
| 1703 |
-# this should be used if you want to install globally, all libraries should |
|
| 1704 |
-# use this, especially *oslo* ones |
|
| 1705 |
-function setup_install {
|
|
| 1706 |
- local project_dir=$1 |
|
| 1707 |
- setup_package_with_req_sync $project_dir |
|
| 1708 |
-} |
|
| 1709 |
- |
|
| 1710 |
-# this should be used for projects which run services, like all services |
|
| 1711 |
-function setup_develop {
|
|
| 1712 |
- local project_dir=$1 |
|
| 1713 |
- setup_package_with_req_sync $project_dir -e |
|
| 1714 |
-} |
|
| 1715 |
- |
|
| 1716 |
-# determine if a project as specified by directory is in |
|
| 1717 |
-# projects.txt. This will not be an exact match because we throw away |
|
| 1718 |
-# the namespacing when we clone, but it should be good enough in all |
|
| 1719 |
-# practical ways. |
|
| 1720 |
-function is_in_projects_txt {
|
|
| 1721 |
- local project_dir=$1 |
|
| 1722 |
- local project_name=$(basename $project_dir) |
|
| 1723 |
- return grep "/$project_name\$" $REQUIREMENTS_DIR/projects.txt >/dev/null |
|
| 1724 |
-} |
|
| 1725 |
- |
|
| 1726 |
-# ``pip install -e`` the package, which processes the dependencies |
|
| 1727 |
-# using pip before running `setup.py develop` |
|
| 1728 |
-# |
|
| 1729 |
-# Updates the dependencies in project_dir from the |
|
| 1730 |
-# openstack/requirements global list before installing anything. |
|
| 1731 |
-# |
|
| 1732 |
-# Uses globals ``TRACK_DEPENDS``, ``REQUIREMENTS_DIR``, ``UNDO_REQUIREMENTS`` |
|
| 1733 |
-# setup_develop directory |
|
| 1734 |
-function setup_package_with_req_sync {
|
|
| 1735 |
- local project_dir=$1 |
|
| 1736 |
- local flags=$2 |
|
| 1737 |
- |
|
| 1738 |
- # Don't update repo if local changes exist |
|
| 1739 |
- # Don't use buggy "git diff --quiet" |
|
| 1740 |
- # ``errexit`` requires us to trap the exit code when the repo is changed |
|
| 1741 |
- local update_requirements=$(cd $project_dir && git diff --exit-code >/dev/null || echo "changed") |
|
| 1742 |
- |
|
| 1743 |
- if [[ $update_requirements != "changed" ]]; then |
|
| 1744 |
- if [[ "$REQUIREMENTS_MODE" == "soft" ]]; then |
|
| 1745 |
- if is_in_projects_txt $project_dir; then |
|
| 1746 |
- (cd $REQUIREMENTS_DIR; \ |
|
| 1747 |
- python update.py $project_dir) |
|
| 1748 |
- else |
|
| 1749 |
- # soft update projects not found in requirements project.txt |
|
| 1750 |
- (cd $REQUIREMENTS_DIR; \ |
|
| 1751 |
- python update.py -s $project_dir) |
|
| 1752 |
- fi |
|
| 1753 |
- else |
|
| 1754 |
- (cd $REQUIREMENTS_DIR; \ |
|
| 1755 |
- python update.py $project_dir) |
|
| 1756 |
- fi |
|
| 1757 |
- fi |
|
| 1758 |
- |
|
| 1759 |
- setup_package $project_dir $flags |
|
| 1760 |
- |
|
| 1761 |
- # We've just gone and possibly modified the user's source tree in an |
|
| 1762 |
- # automated way, which is considered bad form if it's a development |
|
| 1763 |
- # tree because we've screwed up their next git checkin. So undo it. |
|
| 1764 |
- # |
|
| 1765 |
- # However... there are some circumstances, like running in the gate |
|
| 1766 |
- # where we really really want the overridden version to stick. So provide |
|
| 1767 |
- # a variable that tells us whether or not we should UNDO the requirements |
|
| 1768 |
- # changes (this will be set to False in the OpenStack ci gate) |
|
| 1769 |
- if [ $UNDO_REQUIREMENTS = "True" ]; then |
|
| 1770 |
- if [[ $update_requirements != "changed" ]]; then |
|
| 1771 |
- (cd $project_dir && git reset --hard) |
|
| 1772 |
- fi |
|
| 1773 |
- fi |
|
| 1774 |
-} |
|
| 1775 |
- |
|
| 1776 |
-# ``pip install -e`` the package, which processes the dependencies |
|
| 1777 |
-# using pip before running `setup.py develop` |
|
| 1778 |
-# Uses globals ``STACK_USER`` |
|
| 1779 |
-# setup_develop_no_requirements_update directory |
|
| 1780 |
-function setup_package {
|
|
| 1781 |
- local project_dir=$1 |
|
| 1782 |
- local flags=$2 |
|
| 1783 |
- |
|
| 1784 |
- pip_install $flags $project_dir |
|
| 1785 |
- # ensure that further actions can do things like setup.py sdist |
|
| 1786 |
- if [[ "$flags" == "-e" ]]; then |
|
| 1787 |
- safe_chown -R $STACK_USER $1/*.egg-info |
|
| 1788 |
- fi |
|
| 1789 |
-} |
|
| 1790 |
- |
|
| 1791 | 1593 |
# Plugin Functions |
| 1792 | 1594 |
# ================= |
| 1793 | 1595 |
|
| 1794 | 1596 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,223 @@ |
| 0 |
+#!/bin/bash |
|
| 1 |
+# |
|
| 2 |
+# **inc/python** - Python-related functions |
|
| 3 |
+# |
|
| 4 |
+# Support for pip/setuptools interfaces and virtual environments |
|
| 5 |
+# |
|
| 6 |
+# External functions used: |
|
| 7 |
+# - GetOSVersion |
|
| 8 |
+# - is_fedora |
|
| 9 |
+# - is_suse |
|
| 10 |
+# - safe_chown |
|
| 11 |
+ |
|
| 12 |
+# Save trace setting |
|
| 13 |
+INC_PY_TRACE=$(set +o | grep xtrace) |
|
| 14 |
+set +o xtrace |
|
| 15 |
+ |
|
| 16 |
+ |
|
| 17 |
+# Python Functions |
|
| 18 |
+# ================ |
|
| 19 |
+ |
|
| 20 |
+# Get the path to the pip command. |
|
| 21 |
+# get_pip_command |
|
| 22 |
+function get_pip_command {
|
|
| 23 |
+ which pip || which pip-python |
|
| 24 |
+ |
|
| 25 |
+ if [ $? -ne 0 ]; then |
|
| 26 |
+ die $LINENO "Unable to find pip; cannot continue" |
|
| 27 |
+ fi |
|
| 28 |
+} |
|
| 29 |
+ |
|
| 30 |
+# Get the path to the direcotry where python executables are installed. |
|
| 31 |
+# get_python_exec_prefix |
|
| 32 |
+function get_python_exec_prefix {
|
|
| 33 |
+ if is_fedora || is_suse; then |
|
| 34 |
+ echo "/usr/bin" |
|
| 35 |
+ else |
|
| 36 |
+ echo "/usr/local/bin" |
|
| 37 |
+ fi |
|
| 38 |
+} |
|
| 39 |
+ |
|
| 40 |
+# Wrapper for ``pip install`` to set cache and proxy environment variables |
|
| 41 |
+# Uses globals ``INSTALL_TESTONLY_PACKAGES``, ``OFFLINE``, ``TRACK_DEPENDS``, |
|
| 42 |
+# ``*_proxy`` |
|
| 43 |
+# pip_install package [package ...] |
|
| 44 |
+function pip_install {
|
|
| 45 |
+ local xtrace=$(set +o | grep xtrace) |
|
| 46 |
+ set +o xtrace |
|
| 47 |
+ local offline=${OFFLINE:-False}
|
|
| 48 |
+ if [[ "$offline" == "True" || -z "$@" ]]; then |
|
| 49 |
+ $xtrace |
|
| 50 |
+ return |
|
| 51 |
+ fi |
|
| 52 |
+ |
|
| 53 |
+ if [[ -z "$os_PACKAGE" ]]; then |
|
| 54 |
+ GetOSVersion |
|
| 55 |
+ fi |
|
| 56 |
+ if [[ $TRACK_DEPENDS = True && ! "$@" =~ virtualenv ]]; then |
|
| 57 |
+ # TRACK_DEPENDS=True installation creates a circular dependency when |
|
| 58 |
+ # we attempt to install virtualenv into a virualenv, so we must global |
|
| 59 |
+ # that installation. |
|
| 60 |
+ source $DEST/.venv/bin/activate |
|
| 61 |
+ local cmd_pip=$DEST/.venv/bin/pip |
|
| 62 |
+ local sudo_pip="env" |
|
| 63 |
+ else |
|
| 64 |
+ local cmd_pip=$(get_pip_command) |
|
| 65 |
+ local sudo_pip="sudo -H" |
|
| 66 |
+ fi |
|
| 67 |
+ |
|
| 68 |
+ local pip_version=$(python -c "import pip; \ |
|
| 69 |
+ print(pip.__version__.strip('.')[0])")
|
|
| 70 |
+ if (( pip_version<6 )); then |
|
| 71 |
+ die $LINENO "Currently installed pip version ${pip_version} does not" \
|
|
| 72 |
+ "meet minimum requirements (>=6)." |
|
| 73 |
+ fi |
|
| 74 |
+ |
|
| 75 |
+ $xtrace |
|
| 76 |
+ $sudo_pip \ |
|
| 77 |
+ http_proxy=${http_proxy:-} \
|
|
| 78 |
+ https_proxy=${https_proxy:-} \
|
|
| 79 |
+ no_proxy=${no_proxy:-} \
|
|
| 80 |
+ $cmd_pip install \ |
|
| 81 |
+ $@ |
|
| 82 |
+ |
|
| 83 |
+ INSTALL_TESTONLY_PACKAGES=$(trueorfalse False INSTALL_TESTONLY_PACKAGES) |
|
| 84 |
+ if [[ "$INSTALL_TESTONLY_PACKAGES" == "True" ]]; then |
|
| 85 |
+ local test_req="$@/test-requirements.txt" |
|
| 86 |
+ if [[ -e "$test_req" ]]; then |
|
| 87 |
+ $sudo_pip \ |
|
| 88 |
+ http_proxy=${http_proxy:-} \
|
|
| 89 |
+ https_proxy=${https_proxy:-} \
|
|
| 90 |
+ no_proxy=${no_proxy:-} \
|
|
| 91 |
+ $cmd_pip install \ |
|
| 92 |
+ -r $test_req |
|
| 93 |
+ fi |
|
| 94 |
+ fi |
|
| 95 |
+} |
|
| 96 |
+ |
|
| 97 |
+# should we use this library from their git repo, or should we let it |
|
| 98 |
+# get pulled in via pip dependencies. |
|
| 99 |
+function use_library_from_git {
|
|
| 100 |
+ local name=$1 |
|
| 101 |
+ local enabled=1 |
|
| 102 |
+ [[ ,${LIBS_FROM_GIT}, =~ ,${name}, ]] && enabled=0
|
|
| 103 |
+ return $enabled |
|
| 104 |
+} |
|
| 105 |
+ |
|
| 106 |
+# setup a library by name. If we are trying to use the library from |
|
| 107 |
+# git, we'll do a git based install, otherwise we'll punt and the |
|
| 108 |
+# library should be installed by a requirements pull from another |
|
| 109 |
+# project. |
|
| 110 |
+function setup_lib {
|
|
| 111 |
+ local name=$1 |
|
| 112 |
+ local dir=${GITDIR[$name]}
|
|
| 113 |
+ setup_install $dir |
|
| 114 |
+} |
|
| 115 |
+ |
|
| 116 |
+# setup a library by name in editiable mode. If we are trying to use |
|
| 117 |
+# the library from git, we'll do a git based install, otherwise we'll |
|
| 118 |
+# punt and the library should be installed by a requirements pull from |
|
| 119 |
+# another project. |
|
| 120 |
+# |
|
| 121 |
+# use this for non namespaced libraries |
|
| 122 |
+function setup_dev_lib {
|
|
| 123 |
+ local name=$1 |
|
| 124 |
+ local dir=${GITDIR[$name]}
|
|
| 125 |
+ setup_develop $dir |
|
| 126 |
+} |
|
| 127 |
+ |
|
| 128 |
+# this should be used if you want to install globally, all libraries should |
|
| 129 |
+# use this, especially *oslo* ones |
|
| 130 |
+function setup_install {
|
|
| 131 |
+ local project_dir=$1 |
|
| 132 |
+ setup_package_with_req_sync $project_dir |
|
| 133 |
+} |
|
| 134 |
+ |
|
| 135 |
+# this should be used for projects which run services, like all services |
|
| 136 |
+function setup_develop {
|
|
| 137 |
+ local project_dir=$1 |
|
| 138 |
+ setup_package_with_req_sync $project_dir -e |
|
| 139 |
+} |
|
| 140 |
+ |
|
| 141 |
+# determine if a project as specified by directory is in |
|
| 142 |
+# projects.txt. This will not be an exact match because we throw away |
|
| 143 |
+# the namespacing when we clone, but it should be good enough in all |
|
| 144 |
+# practical ways. |
|
| 145 |
+function is_in_projects_txt {
|
|
| 146 |
+ local project_dir=$1 |
|
| 147 |
+ local project_name=$(basename $project_dir) |
|
| 148 |
+ return grep "/$project_name\$" $REQUIREMENTS_DIR/projects.txt >/dev/null |
|
| 149 |
+} |
|
| 150 |
+ |
|
| 151 |
+# ``pip install -e`` the package, which processes the dependencies |
|
| 152 |
+# using pip before running `setup.py develop` |
|
| 153 |
+# |
|
| 154 |
+# Updates the dependencies in project_dir from the |
|
| 155 |
+# openstack/requirements global list before installing anything. |
|
| 156 |
+# |
|
| 157 |
+# Uses globals ``TRACK_DEPENDS``, ``REQUIREMENTS_DIR``, ``UNDO_REQUIREMENTS`` |
|
| 158 |
+# setup_develop directory |
|
| 159 |
+function setup_package_with_req_sync {
|
|
| 160 |
+ local project_dir=$1 |
|
| 161 |
+ local flags=$2 |
|
| 162 |
+ |
|
| 163 |
+ # Don't update repo if local changes exist |
|
| 164 |
+ # Don't use buggy "git diff --quiet" |
|
| 165 |
+ # ``errexit`` requires us to trap the exit code when the repo is changed |
|
| 166 |
+ local update_requirements=$(cd $project_dir && git diff --exit-code >/dev/null || echo "changed") |
|
| 167 |
+ |
|
| 168 |
+ if [[ $update_requirements != "changed" ]]; then |
|
| 169 |
+ if [[ "$REQUIREMENTS_MODE" == "soft" ]]; then |
|
| 170 |
+ if is_in_projects_txt $project_dir; then |
|
| 171 |
+ (cd $REQUIREMENTS_DIR; \ |
|
| 172 |
+ python update.py $project_dir) |
|
| 173 |
+ else |
|
| 174 |
+ # soft update projects not found in requirements project.txt |
|
| 175 |
+ (cd $REQUIREMENTS_DIR; \ |
|
| 176 |
+ python update.py -s $project_dir) |
|
| 177 |
+ fi |
|
| 178 |
+ else |
|
| 179 |
+ (cd $REQUIREMENTS_DIR; \ |
|
| 180 |
+ python update.py $project_dir) |
|
| 181 |
+ fi |
|
| 182 |
+ fi |
|
| 183 |
+ |
|
| 184 |
+ setup_package $project_dir $flags |
|
| 185 |
+ |
|
| 186 |
+ # We've just gone and possibly modified the user's source tree in an |
|
| 187 |
+ # automated way, which is considered bad form if it's a development |
|
| 188 |
+ # tree because we've screwed up their next git checkin. So undo it. |
|
| 189 |
+ # |
|
| 190 |
+ # However... there are some circumstances, like running in the gate |
|
| 191 |
+ # where we really really want the overridden version to stick. So provide |
|
| 192 |
+ # a variable that tells us whether or not we should UNDO the requirements |
|
| 193 |
+ # changes (this will be set to False in the OpenStack ci gate) |
|
| 194 |
+ if [ $UNDO_REQUIREMENTS = "True" ]; then |
|
| 195 |
+ if [[ $update_requirements != "changed" ]]; then |
|
| 196 |
+ (cd $project_dir && git reset --hard) |
|
| 197 |
+ fi |
|
| 198 |
+ fi |
|
| 199 |
+} |
|
| 200 |
+ |
|
| 201 |
+# ``pip install -e`` the package, which processes the dependencies |
|
| 202 |
+# using pip before running `setup.py develop` |
|
| 203 |
+# Uses globals ``STACK_USER`` |
|
| 204 |
+# setup_develop_no_requirements_update directory |
|
| 205 |
+function setup_package {
|
|
| 206 |
+ local project_dir=$1 |
|
| 207 |
+ local flags=$2 |
|
| 208 |
+ |
|
| 209 |
+ pip_install $flags $project_dir |
|
| 210 |
+ # ensure that further actions can do things like setup.py sdist |
|
| 211 |
+ if [[ "$flags" == "-e" ]]; then |
|
| 212 |
+ safe_chown -R $STACK_USER $1/*.egg-info |
|
| 213 |
+ fi |
|
| 214 |
+} |
|
| 215 |
+ |
|
| 216 |
+ |
|
| 217 |
+# Restore xtrace |
|
| 218 |
+$INC_PY_TRACE |
|
| 219 |
+ |
|
| 220 |
+# Local variables: |
|
| 221 |
+# mode: shell-script |
|
| 222 |
+# End: |