This is an automated email from the ASF dual-hosted git repository.
doleyzi pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/inlong.git
The following commit(s) were added to refs/heads/master by this push:
new 60b8df3d0a [INLONG-12012][SDK] Put the Python Dataproxy SDK target
directory in the command line parameters to avoid interruption of the build
process (#12017)
60b8df3d0a is described below
commit 60b8df3d0a667469daa981bebbb53b26af3f2332
Author: yfsn666 <[email protected]>
AuthorDate: Tue Oct 14 10:04:35 2025 +0800
[INLONG-12012][SDK] Put the Python Dataproxy SDK target directory in the
command line parameters to avoid interruption of the build process (#12017)
* [INLONG-12012][SDK] Put the Python Dataproxy SDK target directory in the
command line parameters to avoid interruption of the build process
* fix comments
---
.../dataproxy-sdk-python/README.md | 27 ++++++--
.../dataproxy-sdk-python/build.sh | 75 ++++++++++++----------
2 files changed, 63 insertions(+), 39 deletions(-)
diff --git a/inlong-sdk/dataproxy-sdk-twins/dataproxy-sdk-python/README.md
b/inlong-sdk/dataproxy-sdk-twins/dataproxy-sdk-python/README.md
index d4e4f94bb2..7a11d83700 100644
--- a/inlong-sdk/dataproxy-sdk-twins/dataproxy-sdk-python/README.md
+++ b/inlong-sdk/dataproxy-sdk-twins/dataproxy-sdk-python/README.md
@@ -48,17 +48,32 @@ Go to the `dataproxy-sdk-python` root directory, and run
the following commands:
```bash
chmod +x ./build.sh
-./build.sh
+./build.sh [target_directory]
```
-When the .so file is generated, you will see the following message, you can
choose to enter the target directory for the .so files. By default, the .so
file will be copied to the system python site-packages directory:
-```txt
-Your system's Python site-packages directory is: xxx/xxx
-Enter the target directory for the .so files (Press Enter to use the default
site-packages directory):
-```
+**Parameters:**
+- `target_directory` (optional): Directory to install .so files. If not
provided, the .so files will be copied to the system Python site-packages
directories automatically.
+
+**Usage Examples:**
+
+1. **Install to system site-packages (default behavior):**
+ ```bash
+ ./build.sh
+ ```
+ The script will automatically detect and copy .so files to all available
Python site-packages directories.
+
+2. **Install to a specific directory:**
+ ```bash
+ ./build.sh /path/to/your/target/directory
+ ```
+ The script will copy .so files to the specified directory. Make sure the
target directory exists before running the command.
After the build process finished, you can import the package (`import
inlong_dataproxy`) in your python project to use InLong dataproxy.
+**Important Notes:**
+- If you specify a target directory, make sure it exists before running the
build script. The script will exit with an error if the specified directory
doesn't exist.
+- If no target directory is specified and no system site-packages directories
are found, the .so files will remain in the `build` directory and you'll need
to copy them manually to your project.
+
> **Note**: When the C++ SDK or the version of Python you're using is updated,
> you'll need to rebuild it by the above steps.
## Config Parameters
diff --git a/inlong-sdk/dataproxy-sdk-twins/dataproxy-sdk-python/build.sh
b/inlong-sdk/dataproxy-sdk-twins/dataproxy-sdk-python/build.sh
index 51bfcd7ced..664fe637a5 100755
--- a/inlong-sdk/dataproxy-sdk-twins/dataproxy-sdk-python/build.sh
+++ b/inlong-sdk/dataproxy-sdk-twins/dataproxy-sdk-python/build.sh
@@ -1,3 +1,4 @@
+#!/bin/bash
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
@@ -16,10 +17,24 @@
# Initialize the configuration files of inlong components
#
-#!/bin/bash
-
set -e
+# Parse command line arguments
+TARGET_DIR=""
+if [ $# -eq 1 ]; then
+ TARGET_DIR="$1"
+ echo "Using user-specified target directory: $TARGET_DIR"
+ # Check if the target directory exists early to avoid wasting compilation
time
+ if [ ! -d "$TARGET_DIR" ]; then
+ echo "Error: Target directory '$TARGET_DIR' does not exist!"
+ exit 1
+ fi
+elif [ $# -gt 1 ]; then
+ echo "Usage: $0 [target_directory]"
+ echo " target_directory: Optional. Directory to install .so files. If not
provided, will use system site-packages directories."
+ exit 1
+fi
+
BASE_DIR=$(dirname "$0")
PY_SDK_DIR=$(cd "$BASE_DIR"; pwd)
@@ -73,8 +88,8 @@ if [ ! -d "$PY_SDK_DIR/pybind11/build" ]; then
trap 'echo "Error occurred during pybind11 build. Deleting pybind11
folder..."; cd $PY_SDK_DIR; rm -r pybind11; exit 1' ERR
cmake "$PY_SDK_DIR/pybind11"
- cmake --build "$PY_SDK_DIR/pybind11/build" --config Release --target check
- make -j 4
+ cmake --build "$PY_SDK_DIR/pybind11/build" --config Release
+ make -j"$(nproc)"
# Remove the trap command if the build is successful
trap - ERR
@@ -105,37 +120,31 @@ if [ -d "$PY_SDK_DIR/build" ]; then
fi
mkdir "$PY_SDK_DIR/build" && cd "$PY_SDK_DIR/build"
cmake "$PY_SDK_DIR"
-make -j 4
-
-# Get all existing Python site-packages directories
-SITE_PACKAGES_DIRS=($(python -c "import site,os; print(' '.join([p for p in
site.getsitepackages() if os.path.isdir(p)]))"))
-
-# Check if the SITE_PACKAGES_DIRS array is not empty
-if [ ${#SITE_PACKAGES_DIRS[@]} -ne 0 ]; then
- # If not empty, display all found site-packages directories to the user
- echo "Your system's existing Python site-packages directories are:"
- for dir in "${SITE_PACKAGES_DIRS[@]}"; do
- echo " $dir"
- done
-else
- # If empty, warn the user and prompt them to enter the target directory in
the next step
- echo "Warn: No existing site-packages directories found, please enter the
target directory for the .so files in the following step!"
-fi
+make -j"$(nproc)"
-# Prompt user for the target directory for .so files
-read -r -p "Enter the target directory for the .so files (Press Enter to use
all above site-packages directories): " target_dir
-
-# If user input is empty, use all found site-packages directories
-if [ -z "$target_dir" ]; then
- for dir in "${SITE_PACKAGES_DIRS[@]}"; do
- echo "Copying .so files to $dir"
- # Find all .so files in $PY_SDK_DIR/build and copy them to the current
site-packages directory
- find "$PY_SDK_DIR/build" -name "*.so" -print0 | xargs -0 -I {} cp {}
"$dir"
- done
+# Handle installation based on command line arguments
+if [ -n "$TARGET_DIR" ]; then
+ # User specified a target directory via command line argument
+ echo "Copying .so files to user-specified directory: $TARGET_DIR"
+ find "$PY_SDK_DIR/build" -name "*.so" -print0 | xargs -0 -I {} cp {}
"$TARGET_DIR"
else
- # If user specified a directory, copy .so files there
- echo "Copying .so files to $target_dir"
- find "$PY_SDK_DIR/build" -name "*.so" -print0 | xargs -0 -I {} cp {}
"$target_dir"
+ # No command line argument provided, use system site-packages directories
+ # Get all existing Python site-packages directories
+ SITE_PACKAGES_DIRS=($(python -c "import site,os; print(' '.join([p for p
in site.getsitepackages() if os.path.isdir(p)]))"))
+ if [ ${#SITE_PACKAGES_DIRS[@]} -ne 0 ]; then
+ echo "No target directory specified, using system site-packages
directories:"
+ for dir in "${SITE_PACKAGES_DIRS[@]}"; do
+ echo " $dir"
+ done
+ for dir in "${SITE_PACKAGES_DIRS[@]}"; do
+ echo "Copying .so files to $dir"
+ # Find all .so files in $PY_SDK_DIR/build and copy them to the
current site-packages directory
+ find "$PY_SDK_DIR/build" -name "*.so" -print0 | xargs -0 -I {} cp
{} "$dir"
+ done
+ else
+ echo "Error: No system site-packages directories found and no target
directory specified!"
+ echo "The .so file is located in $PY_SDK_DIR/build, you can copy it
manually to your project"
+ fi
fi
# Clean the cpp dataproxy directory