Strip the [<extras>] string from a <package_dir>[<extras>] argument
when looking for the package directory. Explain what the heck is
going on.
Change-Id: I79beb5c3e9e7c35c91cdd0d5a1d91532bebc4b6d
Closes-Bug: #1721638
... | ... |
@@ -219,7 +219,8 @@ function disable_python3_package { |
219 | 219 |
# Wrapper for ``pip install`` to set cache and proxy environment variables |
220 | 220 |
# Uses globals ``OFFLINE``, ``PIP_VIRTUAL_ENV``, |
221 | 221 |
# ``PIP_UPGRADE``, ``TRACK_DEPENDS``, ``*_proxy``, |
222 |
-# pip_install package [package ...] |
|
222 |
+# Usage: |
|
223 |
+# pip_install pip_arguments |
|
223 | 224 |
function pip_install { |
224 | 225 |
local xtrace result |
225 | 226 |
xtrace=$(set +o | grep xtrace) |
... | ... |
@@ -241,6 +242,26 @@ function pip_install { |
241 | 241 |
if [[ -z "$os_PACKAGE" ]]; then |
242 | 242 |
GetOSVersion |
243 | 243 |
fi |
244 |
+ |
|
245 |
+ # Try to extract the path of the package we are installing into |
|
246 |
+ # package_dir. We need this to check for test-requirements.txt, |
|
247 |
+ # at least. |
|
248 |
+ # |
|
249 |
+ # ${!#} expands to the last positional argument to this function. |
|
250 |
+ # With "extras" syntax included, our arguments might be something |
|
251 |
+ # like: |
|
252 |
+ # -e /path/to/fooproject[extra] |
|
253 |
+ # Thus this magic line grabs just the path without extras |
|
254 |
+ # |
|
255 |
+ # Note that this makes no sense if this is a pypi (rather than |
|
256 |
+ # local path) install; ergo you must check this path exists before |
|
257 |
+ # use. Also, if we had multiple or mixed installs, we would also |
|
258 |
+ # likely break. But for historical reasons, it's basically only |
|
259 |
+ # the other wrapper functions in here calling this to install |
|
260 |
+ # local packages, and they do so with single call per install. So |
|
261 |
+ # this works (for now...) |
|
262 |
+ local package_dir=${!#%\[*\]} |
|
263 |
+ |
|
244 | 264 |
if [[ $TRACK_DEPENDS = True && ! "$@" =~ virtualenv ]]; then |
245 | 265 |
# TRACK_DEPENDS=True installation creates a circular dependency when |
246 | 266 |
# we attempt to install virtualenv into a virtualenv, so we must global |
... | ... |
@@ -261,7 +282,6 @@ function pip_install { |
261 | 261 |
# versions supported, and if we find the version of |
262 | 262 |
# python3 we've been told to use, use that instead of the |
263 | 263 |
# default pip |
264 |
- local package_dir=${!#} |
|
265 | 264 |
local python_versions |
266 | 265 |
|
267 | 266 |
# Special case some services that have experimental |
... | ... |
@@ -323,7 +343,7 @@ function pip_install { |
323 | 323 |
|
324 | 324 |
# Also install test requirements |
325 | 325 |
local install_test_reqs="" |
326 |
- local test_req="${!#}/test-requirements.txt" |
|
326 |
+ local test_req="${package_dir}/test-requirements.txt" |
|
327 | 327 |
if [[ -e "$test_req" ]]; then |
328 | 328 |
install_test_reqs="-r $test_req" |
329 | 329 |
fi |