Repository navigation
Expand file tree
/
Copy pathrunner.sh
More file actions
executable file
·89 lines (75 loc) · 2.69 KB
/
Copy pathrunner.sh
File metadata and controls
executable file
·89 lines (75 loc) · 2.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/bin/bash
# --- Configuration ---
# Set the path to your Poetry project directory.
# If left empty, the script will assume the current directory is the project root.
POETRY_PROJECT_DIR=""
# Name of the Python script to execute (e.g., "main.py", "my_app/run.py")
PYTHON_SCRIPT_TO_RUN=""
# Optional arguments to pass to the Python script
PYTHON_SCRIPT_ARGS=""
# --- Script Logic ---
# Function to display usage information
usage() {
echo "Usage: $0 -s <python_script_path> [-d <project_directory>] [-a <script_arguments>]"
echo ""
echo " -s <python_script_path> : Required. Path to the Python script to execute (e.g., 'main.py', 'src/app.py')."
echo " -d <project_directory> : Optional. Path to the Poetry project directory. Defaults to current directory."
echo " -a <script_arguments> : Optional. Arguments to pass to the Python script (e.g., '--verbose --config=dev.ini')."
echo " -h : Display this help message."
echo ""
echo "Example: $0 -s kbt-core/ai_function_server.py -d $PWD -a extra-arg"
exit 1
}
# Parse command-line arguments
while getopts "s:d:a:h" opt; do
case ${opt} in
s )
PYTHON_SCRIPT_TO_RUN=$OPTARG
;;
d )
POETRY_PROJECT_DIR=$OPTARG
;;
a )
PYTHON_SCRIPT_ARGS=$OPTARG
;;
h )
usage
;;
\? )
echo "Invalid option: -$OPTARG" >&2
usage
;;
esac
done
shift $((OPTIND -1))
# Validate required arguments
if [ -z "$PYTHON_SCRIPT_TO_RUN" ]; then
echo "Error: Python script path (-s) is required."
usage
fi
# Determine the project directory
if [ -z "$POETRY_PROJECT_DIR" ]; then
POETRY_PROJECT_DIR=$(pwd)
echo "No project directory specified. Assuming current directory: $POETRY_PROJECT_DIR"
else
echo "Using specified project directory: $POETRY_PROJECT_DIR"
fi
# Check if the project directory exists
if [ ! -d "$POETRY_PROJECT_DIR" ]; then
echo "Error: Project directory '$POETRY_PROJECT_DIR' does not exist."
exit 1
fi
# Navigate to the Poetry project directory
cd "$POETRY_PROJECT_DIR" || { echo "Error: Could not change to directory $POETRY_PROJECT_DIR"; exit 1; }
# --- Dependency Management ---
if ! command -v poetry &> /dev/null; then
echo "Error: Poetry is not installed or not in your PATH."
echo "Please install Poetry: https://python-poetry.org/docs/#installation"
exit 1
fi
if ! poetry install --no-interaction; then
echo "Error: Failed to install dependencies. Please check your pyproject.toml and network connection."
exit 1
fi
# --- Python Script Execution ---
poetry run python "$PYTHON_SCRIPT_TO_RUN" $PYTHON_SCRIPT_ARGS