From 635a5ba9929e1594aacfc0229663f43898479e2a Mon Sep 17 00:00:00 2001 From: Robert Collins Date: Wed, 10 Jun 2015 08:48:06 +1200 Subject: [PATCH] constraints file support for devstack. Constraints files allow a global view of dependencies for devstack without the side effect that requirements files have of installing everything everytime. This is part of the cross project requirements-management spec. Change-Id: If089d30146629e6cf817edd634e5c2b80f1366dd --- inc/python | 22 ++++++++++++++++++---- stack.sh | 3 +++ stackrc | 6 ++++++ 3 files changed, 27 insertions(+), 4 deletions(-) diff --git a/inc/python b/inc/python index 07a811e8c3..ca185f05d2 100644 --- a/inc/python +++ b/inc/python @@ -66,7 +66,8 @@ function pip_install_gr { # Wrapper for ``pip install`` to set cache and proxy environment variables # Uses globals ``OFFLINE``, ``PIP_VIRTUAL_ENV``, -# ``PIP_UPGRADE``, ``TRACK_DEPENDS``, ``*_proxy`` +# ``PIP_UPGRADE``, ``TRACK_DEPENDS``, ``*_proxy``, +# ``USE_CONSTRAINTS`` # pip_install package [package ...] function pip_install { local xtrace=$(set +o | grep xtrace) @@ -103,6 +104,13 @@ function pip_install { fi fi + cmd_pip="$cmd_pip install" + + # Handle a constraints file, if needed. + if [[ "$USE_CONSTRAINTS" == "True" ]]; then + cmd_pip="$cmd_pip -c $REQUIREMENTS_DIR/upper-constraints.txt" + fi + local pip_version=$(python -c "import pip; \ print(pip.__version__.strip('.')[0])") if (( pip_version<6 )); then @@ -116,7 +124,7 @@ function pip_install { https_proxy="${https_proxy:-}" \ no_proxy="${no_proxy:-}" \ PIP_FIND_LINKS=$PIP_FIND_LINKS \ - $cmd_pip install $upgrade \ + $cmd_pip $upgrade \ $@ # Also install test requirements @@ -128,7 +136,7 @@ function pip_install { https_proxy=${https_proxy:-} \ no_proxy=${no_proxy:-} \ PIP_FIND_LINKS=$PIP_FIND_LINKS \ - $cmd_pip install $upgrade \ + $cmd_pip $upgrade \ -r $test_req fi } @@ -215,7 +223,7 @@ function setup_package_with_req_sync { # ``errexit`` requires us to trap the exit code when the repo is changed local update_requirements=$(cd $project_dir && git diff --exit-code >/dev/null || echo "changed") - if [[ $update_requirements != "changed" ]]; then + if [[ $update_requirements != "changed" && "$USE_CONSTRAINTS" == "False" ]]; then if is_in_projects_txt $project_dir; then (cd $REQUIREMENTS_DIR; \ ./.venv/bin/python update.py $project_dir) @@ -227,6 +235,12 @@ function setup_package_with_req_sync { fi fi + if [ -n "$REQUIREMENTS_DIR" ]; then + # Constrain this package to this project directory from here on out. + local name=$(awk '/^name.*=/ {print $3}' $project_dir/setup.cfg) + $REQUIREMENTS_DIR/.venv/bin/edit-constraints $REQUIREMENTS_DIR/upper-constraints.txt -- $name "$flags $project_dir" + fi + setup_package $project_dir $flags # We've just gone and possibly modified the user's source tree in an diff --git a/stack.sh b/stack.sh index 591c0dc614..4069509e96 100755 --- a/stack.sh +++ b/stack.sh @@ -683,6 +683,9 @@ save_stackenv $LINENO echo_summary "Installing package prerequisites" source $TOP_DIR/tools/install_prereqs.sh +# Normalise USE_CONSTRAINTS +USE_CONSTRAINTS=$(trueorfalse False USE_CONSTRAINTS) + # Configure an appropriate Python environment if [[ "$OFFLINE" != "True" ]]; then PYPI_ALTERNATIVE_URL=${PYPI_ALTERNATIVE_URL:-""} $TOP_DIR/tools/install_pip.sh diff --git a/stackrc b/stackrc index f2aafe97fc..e76abc0e85 100644 --- a/stackrc +++ b/stackrc @@ -149,6 +149,12 @@ DATABASE_QUERY_LOGGING=$(trueorfalse False DATABASE_QUERY_LOGGING) # Zero disables timeouts GIT_TIMEOUT=${GIT_TIMEOUT:-0} +# Constraints mode +# - False (default) : update git projects dependencies from global-requirements. +# +# - True : use upper-constraints.txt to constrain versions of packages intalled +# and do not edit projects at all. +USE_CONSTRAINTS=${USE_CONSTRAINTS:-False} # Repositories # ------------