Browse code

Merge "Add options for development bindep install"

Zuul authored on 2019/02/07 01:34:56
Showing 4 changed files
... ...
@@ -1389,6 +1389,35 @@ function zypper_install {
1389 1389
         zypper --non-interactive install --auto-agree-with-licenses --no-recommends "$@"
1390 1390
 }
1391 1391
 
1392
+# Run bindep and install packages it outputs
1393
+#
1394
+# Usage:
1395
+#  install_bindep <path-to-bindep.txt> [profile,profile]
1396
+#
1397
+# Note unlike the bindep command itself, profile(s) specified should
1398
+# be a single, comma-separated string, no spaces.
1399
+function install_bindep {
1400
+    local file=$1
1401
+    local profiles=${2:-""}
1402
+    local pkgs
1403
+
1404
+    if [[ ! -f $file ]]; then
1405
+        die $LINENO "Can not find bindep file: $file"
1406
+    fi
1407
+
1408
+    # converting here makes it much easier to work with passing
1409
+    # arguments
1410
+    profiles=${profiles/,/ /}
1411
+
1412
+    # Note bindep returns 1 when packages need to be installed, so we
1413
+    # have to ignore it's return for "-e"
1414
+    pkgs=$($DEST/bindep-venv/bin/bindep -b --file $file $profiles || true)
1415
+
1416
+    if [[ -n "${pkgs}" ]]; then
1417
+        install_package ${pkgs}
1418
+    fi
1419
+}
1420
+
1392 1421
 function write_user_unit_file {
1393 1422
     local service=$1
1394 1423
     local command="$2"
... ...
@@ -428,7 +428,14 @@ function setup_lib {
428 428
 # another project.
429 429
 #
430 430
 # use this for non namespaced libraries
431
+#
432
+# setup_dev_lib [-bindep] <name>
431 433
 function setup_dev_lib {
434
+    local bindep
435
+    if [[ $1 == -bindep* ]]; then
436
+        bindep="${1}"
437
+        shift
438
+    fi
432 439
     local name=$1
433 440
     local dir=${GITDIR[$name]}
434 441
     if python3_enabled; then
... ...
@@ -438,10 +445,10 @@ function setup_dev_lib {
438 438
         # of Python.
439 439
         echo "Installing $name again without Python 3 enabled"
440 440
         USE_PYTHON3=False
441
-        setup_develop $dir
441
+        setup_develop $bindep $dir
442 442
         USE_PYTHON3=True
443 443
     fi
444
-    setup_develop $dir
444
+    setup_develop $bindep $dir
445 445
 }
446 446
 
447 447
 # this should be used if you want to install globally, all libraries should
... ...
@@ -452,11 +459,17 @@ function setup_dev_lib {
452 452
 # extras: comma-separated list of optional dependencies to install
453 453
 #         (e.g., ldap,memcache).
454 454
 #         See https://docs.openstack.org/pbr/latest/user/using.html#extra-requirements
455
+# bindep: Set "-bindep" as first argument to install bindep.txt packages
455 456
 # The command is like "pip install <project_dir>[<extras>]"
456 457
 function setup_install {
458
+    local bindep
459
+    if [[ $1 == -bindep* ]]; then
460
+        bindep="${1}"
461
+        shift
462
+    fi
457 463
     local project_dir=$1
458 464
     local extras=$2
459
-    _setup_package_with_constraints_edit $project_dir "" $extras
465
+    _setup_package_with_constraints_edit $bindep $project_dir "" $extras
460 466
 }
461 467
 
462 468
 # this should be used for projects which run services, like all services
... ...
@@ -468,9 +481,14 @@ function setup_install {
468 468
 #         See https://docs.openstack.org/pbr/latest/user/using.html#extra-requirements
469 469
 # The command is like "pip install -e <project_dir>[<extras>]"
470 470
 function setup_develop {
471
+    local bindep
472
+    if [[ $1 == -bindep* ]]; then
473
+        bindep="${1}"
474
+        shift
475
+    fi
471 476
     local project_dir=$1
472 477
     local extras=$2
473
-    _setup_package_with_constraints_edit $project_dir -e $extras
478
+    _setup_package_with_constraints_edit $bindep $project_dir -e $extras
474 479
 }
475 480
 
476 481
 # ``pip install -e`` the package, which processes the dependencies
... ...
@@ -489,6 +507,11 @@ function setup_develop {
489 489
 #         See https://docs.openstack.org/pbr/latest/user/using.html#extra-requirements
490 490
 # The command is like "pip install <flags> <project_dir>[<extras>]"
491 491
 function _setup_package_with_constraints_edit {
492
+    local bindep
493
+    if [[ $1 == -bindep* ]]; then
494
+        bindep="${1}"
495
+        shift
496
+    fi
492 497
     local project_dir=$1
493 498
     local flags=$2
494 499
     local extras=$3
... ...
@@ -509,7 +532,7 @@ function _setup_package_with_constraints_edit {
509 509
             "$flags file://$project_dir#egg=$name"
510 510
     fi
511 511
 
512
-    setup_package $project_dir "$flags" $extras
512
+    setup_package $bindep $project_dir "$flags" $extras
513 513
 
514 514
     # If this project is in LIBS_FROM_GIT, verify it was actually installed
515 515
     # correctly.  This helps catch errors caused by constraints mismatches.
... ...
@@ -521,17 +544,30 @@ function _setup_package_with_constraints_edit {
521 521
 }
522 522
 
523 523
 # ``pip install -e`` the package, which processes the dependencies
524
-# using pip before running `setup.py develop`
524
+# using pip before running `setup.py develop`.  The command is like
525
+# "pip install <flags> <project_dir>[<extras>]"
525 526
 #
526 527
 # Uses globals ``STACK_USER``
527
-# setup_package project_dir [flags] [extras]
528
-# project_dir: directory of project repo (e.g., /opt/stack/keystone)
529
-# flags: pip CLI options/flags
530
-# extras: comma-separated list of optional dependencies to install
531
-#         (e.g., ldap,memcache).
532
-#         See https://docs.openstack.org/pbr/latest/user/using.html#extra-requirements
533
-# The command is like "pip install <flags> <project_dir>[<extras>]"
528
+#
529
+# Usage:
530
+#  setup_package [-bindep[=profile,profile]] <project_dir> <flags> [extras]
531
+#
532
+# -bindep     : Use bindep to install dependencies; select extra profiles
533
+#               as comma separated arguments after "="
534
+# project_dir : directory of project repo (e.g., /opt/stack/keystone)
535
+# flags       : pip CLI options/flags
536
+# extras      : comma-separated list of optional dependencies to install
537
+#               (e.g., ldap,memcache).
538
+#               See https://docs.openstack.org/pbr/latest/user/using.html#extra-requirements
534 539
 function setup_package {
540
+    local bindep=0
541
+    local bindep_flag=""
542
+    local bindep_profiles=""
543
+    if [[ $1 == -bindep* ]]; then
544
+        bindep=1
545
+        IFS="=" read bindep_flag bindep_profiles <<< ${1}
546
+        shift
547
+    fi
535 548
     local project_dir=$1
536 549
     local flags=$2
537 550
     local extras=$3
... ...
@@ -547,6 +583,11 @@ function setup_package {
547 547
         extras="[$extras]"
548 548
     fi
549 549
 
550
+    # install any bindep packages
551
+    if [[ $bindep == 1 ]]; then
552
+        install_bindep $project_dir/bindep.txt $bindep_profiles
553
+    fi
554
+
550 555
     pip_install $flags "$project_dir$extras"
551 556
     # ensure that further actions can do things like setup.py sdist
552 557
     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
... ...
@@ -143,6 +143,13 @@ export PYTHON3_VERSION=${PYTHON3_VERSION:-${_DEFAULT_PYTHON3_VERSION:-3.5}}
143 143
 _DEFAULT_PYTHON2_VERSION="$(_get_python_version python2)"
144 144
 export PYTHON2_VERSION=${PYTHON2_VERSION:-${_DEFAULT_PYTHON2_VERSION:-2.7}}
145 145
 
146
+# Create a virtualenv with this
147
+if [[ ${USE_PYTHON3} == True ]]; then
148
+    export VIRTUALENV_CMD="python3 -m venv"
149
+else
150
+    export VIRTUALENV_CMD="virtualenv "
151
+fi
152
+
146 153
 # allow local overrides of env variables, including repo config
147 154
 if [[ -f $RC_DIR/localrc ]]; then
148 155
     # Old-style user-supplied config