]> git.apps.os.sepia.ceph.com Git - ceph-build.git/commitdiff
removed build_utils dependency from ceph build pull request job ceph-build-pull-request-refactor 2398/head
authorAdarsha Dinda <adarshadinda@Adarshas-MacBook-Pro.local>
Wed, 9 Jul 2025 11:32:22 +0000 (17:02 +0530)
committerAdarsha Dinda <adarshadinda@Adarshas-MacBook-Pro.local>
Mon, 4 Aug 2025 17:53:51 +0000 (23:23 +0530)
Signed-off-by: Adarsha Dinda <adarshadinda@Adarshas-MacBook-Pro.local>
ceph-build-pull-requests/config/definitions/ceph-build-pull-requests.yml
scripts/setup_python_deps.sh [new file with mode: 0644]

index d92deaa0f3a027fdd4e33c1b5679ff8d9911301b..c2fbe5d9f9a6d56b270829a1fa375535db24af3b 100644 (file)
@@ -51,5 +51,5 @@
     builders:
       - shell:
           !include-raw-verbatim:
-            - ../../../scripts/build_utils.sh
+            - ../../../scripts/setup_python_deps.sh
             - ../../build/build
diff --git a/scripts/setup_python_deps.sh b/scripts/setup_python_deps.sh
new file mode 100644 (file)
index 0000000..18afa6b
--- /dev/null
@@ -0,0 +1,105 @@
+#!/bin/bash -ex
+# vim: ts=4 sw=4 expandtab
+#
+# Script: Python Virtual Environment and Package Installer
+
+create_venv_dir() {
+    local venv_dir
+    venv_dir=$(mktemp -td venv.XXXXXXXXXX)
+    trap "rm -rf ${venv_dir}" EXIT
+    echo "${venv_dir}"
+}
+
+create_virtualenv () {
+    local path=$1
+    if [ -d $path ]; then
+        echo "Will reuse existing virtual env: $path"
+    else
+        if command -v python3 > /dev/null; then
+            python3 -m venv $path
+        else
+            virtualenv -p python $path
+        fi
+    fi
+}
+
+pip_download() {
+    local venv=$1
+    shift
+    local package=$1
+    shift
+    local options=$@
+    if ! $venv/pip download $options --dest="$PIP_SDIST_INDEX" $package; then
+        # pip <8.0.0 does not have "download" command
+        $venv/pip install $options \
+                  --upgrade --exists-action=i --cache-dir="$PIP_SDIST_INDEX" \
+                  $package
+    fi
+}
+
+
+install_python_packages () {
+    local venv_dir=$1
+    shift
+    local venv="$venv_dir/bin"
+    # Use this function to create a virtualenv and install
+    # python packages. Pass a list of package names.
+    #
+    # Usage (with pip 24.0 [the default]):
+    #
+    #   to_install=( "ansible" "chacractl>=0.0.21" )
+    #   install_python_packages $TEMPVENV "to_install[@]"
+    #
+    # Usage (with pip<X.X.X [can also do ==X.X.X or !=X.X.X]):
+    #
+    #   to_install=( "ansible" "chacractl>=0.0.21" )
+    #   install_python_packages_no_binary $TEMPVENV "to_install[@]" "pip<X.X.X"
+    #
+    # Usage (with latest pip):
+    #
+    #   to_install=( "ansible" "chacractl>=0.0.21" )
+    #   install_python_packages $TEMPVENV "to_install[@]" latest
+
+    create_virtualenv $venv_dir
+
+    # Define and ensure the PIP cache
+    PIP_SDIST_INDEX="$HOME/.cache/pip"
+    mkdir -p $PIP_SDIST_INDEX
+
+    # Avoid UnicodeErrors when installing packages.
+    # See https://github.com/ceph/ceph/pull/42811
+    export LC_ALL=en_US.UTF-8
+
+    if [ "$2" == "latest" ]; then
+        echo "Ensuring latest pip is installed"
+        $venv/pip install -U pip
+    elif [[ -n $2 && "$2" != "latest" ]]; then
+        echo "Installing $2"
+        $venv/pip install "$2"
+    else
+        # This is the default for most jobs.
+        # See ff01d2c5 and fea10f52
+        echo "Installing pip 24.0"
+        $venv/pip install "pip==24.0"
+    fi
+
+    echo "Ensuring latest wheel is installed"
+    $venv/pip install -U wheel
+
+    echo "Updating setuptools"
+    pip_download $venv setuptools
+
+    pkgs=("${!1}")
+    for package in ${pkgs[@]}; do
+        echo $package
+        # download packages to the local pip cache
+        pip_download $venv $package
+        # install packages from the local pip cache, ignoring pypi
+        $venv/pip install --upgrade --exists-action=i --find-links="file://$PIP_SDIST_INDEX" --no-index $package
+    done
+
+    # See https://tracker.ceph.com/issues/59652
+    echo "Pinning urllib3 and requests"
+    $venv/pip install "urllib3<2.0.0"
+    $venv/pip install "requests<2.30.0"
+}
\ No newline at end of file