Browse code

Add options for development bindep install

This adds a -bindep option to the key development library install
functions. With this option the bindep.txt file will be referenced
and the relevant packages installed.

Change-Id: I856f1f59fca49b6020920d8f859b797f3b904300

Ian Wienand authored on 2018/12/13 12:05:53
Showing 4 changed files
... ...
@@ -1381,6 +1381,35 @@ function zypper_install {
1381 1381
         zypper --non-interactive install --auto-agree-with-licenses --no-recommends "$@"
1382 1382
 }
1383 1383
 
1384
+# Run bindep and install packages it outputs
1385
+#
1386
+# Usage:
1387
+#  install_bindep <path-to-bindep.txt> [profile,profile]
1388
+#
1389
+# Note unlike the bindep command itself, profile(s) specified should
1390
+# be a single, comma-separated string, no spaces.
1391
+function install_bindep {
1392
+    local file=$1
1393
+    local profiles=${2:-""}
1394
+    local pkgs
1395
+
1396
+    if [[ ! -f $file ]]; then
1397
+        die $LINENO "Can not find bindep file: $file"
1398
+    fi
1399
+
1400
+    # converting here makes it much easier to work with passing
1401
+    # arguments
1402
+    profiles=${profiles/,/ /}
1403
+
1404
+    # Note bindep returns 1 when packages need to be installed, so we
1405
+    # have to ignore it's return for "-e"
1406
+    pkgs=$($DEST/bindep-venv/bin/bindep -b --file $file $profiles || true)
1407
+
1408
+    if [[ -n "${pkgs}" ]]; then
1409
+        install_package ${pkgs}
1410
+    fi
1411
+}
1412
+
1384 1413
 function write_user_unit_file {
1385 1414
     local service=$1
1386 1415
     local command="$2"
... ...
@@ -445,7 +445,14 @@ function setup_lib {
445 445
 # another project.
446 446
 #
447 447
 # use this for non namespaced libraries
448
+#
449
+# setup_dev_lib [-bindep] <name>
448 450
 function setup_dev_lib {
451
+    local bindep
452
+    if [[ $1 == -bindep* ]]; then
453
+        bindep="${1}"
454
+        shift
455
+    fi
449 456
     local name=$1
450 457
     local dir=${GITDIR[$name]}
451 458
     if python3_enabled; then
... ...
@@ -455,10 +462,10 @@ function setup_dev_lib {
455 455
         # of Python.
456 456
         echo "Installing $name again without Python 3 enabled"
457 457
         USE_PYTHON3=False
458
-        setup_develop $dir
458
+        setup_develop $bindep $dir
459 459
         USE_PYTHON3=True
460 460
     fi
461
-    setup_develop $dir
461
+    setup_develop $bindep $dir
462 462
 }
463 463
 
464 464
 # this should be used if you want to install globally, all libraries should
... ...
@@ -469,11 +476,17 @@ function setup_dev_lib {
469 469
 # extras: comma-separated list of optional dependencies to install
470 470
 #         (e.g., ldap,memcache).
471 471
 #         See https://docs.openstack.org/pbr/latest/user/using.html#extra-requirements
472
+# bindep: Set "-bindep" as first argument to install bindep.txt packages
472 473
 # The command is like "pip install <project_dir>[<extras>]"
473 474
 function setup_install {
475
+    local bindep
476
+    if [[ $1 == -bindep* ]]; then
477
+        bindep="${1}"
478
+        shift
479
+    fi
474 480
     local project_dir=$1
475 481
     local extras=$2
476
-    _setup_package_with_constraints_edit $project_dir "" $extras
482
+    _setup_package_with_constraints_edit $bindep $project_dir "" $extras
477 483
 }
478 484
 
479 485
 # this should be used for projects which run services, like all services
... ...
@@ -485,9 +498,14 @@ function setup_install {
485 485
 #         See https://docs.openstack.org/pbr/latest/user/using.html#extra-requirements
486 486
 # The command is like "pip install -e <project_dir>[<extras>]"
487 487
 function setup_develop {
488
+    local bindep
489
+    if [[ $1 == -bindep* ]]; then
490
+        bindep="${1}"
491
+        shift
492
+    fi
488 493
     local project_dir=$1
489 494
     local extras=$2
490
-    _setup_package_with_constraints_edit $project_dir -e $extras
495
+    _setup_package_with_constraints_edit $bindep $project_dir -e $extras
491 496
 }
492 497
 
493 498
 # ``pip install -e`` the package, which processes the dependencies
... ...
@@ -506,6 +524,11 @@ function setup_develop {
506 506
 #         See https://docs.openstack.org/pbr/latest/user/using.html#extra-requirements
507 507
 # The command is like "pip install <flags> <project_dir>[<extras>]"
508 508
 function _setup_package_with_constraints_edit {
509
+    local bindep
510
+    if [[ $1 == -bindep* ]]; then
511
+        bindep="${1}"
512
+        shift
513
+    fi
509 514
     local project_dir=$1
510 515
     local flags=$2
511 516
     local extras=$3
... ...
@@ -526,7 +549,7 @@ function _setup_package_with_constraints_edit {
526 526
             "$flags file://$project_dir#egg=$name"
527 527
     fi
528 528
 
529
-    setup_package $project_dir "$flags" $extras
529
+    setup_package $bindep $project_dir "$flags" $extras
530 530
 
531 531
     # If this project is in LIBS_FROM_GIT, verify it was actually installed
532 532
     # correctly.  This helps catch errors caused by constraints mismatches.
... ...
@@ -538,17 +561,30 @@ function _setup_package_with_constraints_edit {
538 538
 }
539 539
 
540 540
 # ``pip install -e`` the package, which processes the dependencies
541
-# using pip before running `setup.py develop`
541
+# using pip before running `setup.py develop`.  The command is like
542
+# "pip install <flags> <project_dir>[<extras>]"
542 543
 #
543 544
 # Uses globals ``STACK_USER``
544
-# setup_package project_dir [flags] [extras]
545
-# project_dir: directory of project repo (e.g., /opt/stack/keystone)
546
-# flags: pip CLI options/flags
547
-# extras: comma-separated list of optional dependencies to install
548
-#         (e.g., ldap,memcache).
549
-#         See https://docs.openstack.org/pbr/latest/user/using.html#extra-requirements
550
-# The command is like "pip install <flags> <project_dir>[<extras>]"
545
+#
546
+# Usage:
547
+#  setup_package [-bindep[=profile,profile]] <project_dir> <flags> [extras]
548
+#
549
+# -bindep     : Use bindep to install dependencies; select extra profiles
550
+#               as comma separated arguments after "="
551
+# project_dir : directory of project repo (e.g., /opt/stack/keystone)
552
+# flags       : pip CLI options/flags
553
+# extras      : comma-separated list of optional dependencies to install
554
+#               (e.g., ldap,memcache).
555
+#               See https://docs.openstack.org/pbr/latest/user/using.html#extra-requirements
551 556
 function setup_package {
557
+    local bindep=0
558
+    local bindep_flag=""
559
+    local bindep_profiles=""
560
+    if [[ $1 == -bindep* ]]; then
561
+        bindep=1
562
+        IFS="=" read bindep_flag bindep_profiles <<< ${1}
563
+        shift
564
+    fi
552 565
     local project_dir=$1
553 566
     local flags=$2
554 567
     local extras=$3
... ...
@@ -564,6 +600,11 @@ function setup_package {
564 564
         extras="[$extras]"
565 565
     fi
566 566
 
567
+    # install any bindep packages
568
+    if [[ $bindep == 1 ]]; then
569
+        install_bindep $project_dir/bindep.txt $bindep_profiles
570
+    fi
571
+
567 572
     pip_install $flags "$project_dir$extras"
568 573
     # ensure that further actions can do things like setup.py sdist
569 574
     if [[ "$flags" == "-e" ]]; then
... ...
@@ -801,6 +801,11 @@ fi
801 801
 # Install required infra support libraries
802 802
 install_infra
803 803
 
804
+# Install bindep
805
+$VIRTUALENV_CMD $DEST/bindep-venv
806
+# TODO(ianw) : optionally install from zuul checkout?
807
+$DEST/bindep-venv/bin/pip install bindep
808
+
804 809
 # Extras Pre-install
805 810
 # ------------------
806 811
 # Phase: pre-install
... ...
@@ -149,6 +149,13 @@ export PYTHON3_VERSION=${PYTHON3_VERSION:-${_DEFAULT_PYTHON3_VERSION:-3.5}}
149 149
 _DEFAULT_PYTHON2_VERSION="$(_get_python_version python2)"
150 150
 export PYTHON2_VERSION=${PYTHON2_VERSION:-${_DEFAULT_PYTHON2_VERSION:-2.7}}
151 151
 
152
+# Create a virtualenv with this
153
+if [[ ${USE_PYTHON3} == True ]]; then
154
+    export VIRTUALENV_CMD="python3 -m venv"
155
+else
156
+    export VIRTUALENV_CMD="virtualenv "
157
+fi
158
+
152 159
 # allow local overrides of env variables, including repo config
153 160
 if [[ -f $RC_DIR/localrc ]]; then
154 161
     # Old-style user-supplied config