|
45 | 45 | SCRIPT_DIR=$( cd -P "$( dirname "$SOURCE" )" >/dev/null 2>&1 && pwd )
|
46 | 46 | echo "Script directory: $SCRIPT_DIR"
|
47 | 47 |
|
48 |
| -# Check if the package is installed |
49 |
| -if python -c "import platform_problem_monitoring_core" &>/dev/null; then |
| 48 | +# Try to determine which Python executable to use |
| 49 | +PYTHON_CMD="python3" |
| 50 | + |
| 51 | +# Check if Python 3 is available |
| 52 | +if ! command -v python3 &>/dev/null; then |
| 53 | + # Fall back to just 'python' if python3 is not available |
| 54 | + if command -v python &>/dev/null; then |
| 55 | + PYTHON_CMD="python" |
| 56 | + else |
| 57 | + echo "Error: Neither python3 nor python found in PATH" |
| 58 | + exit 1 |
| 59 | + fi |
| 60 | +fi |
| 61 | + |
| 62 | +echo "Using Python: $($PYTHON_CMD --version)" |
| 63 | + |
| 64 | +# More robust check for installed package |
| 65 | +PACKAGE_INSTALLED=false |
| 66 | +if $PYTHON_CMD -c "import platform_problem_monitoring_core" &>/dev/null; then |
| 67 | + echo "Package found in primary Python installation" |
| 68 | + PACKAGE_INSTALLED=true |
| 69 | +# Try with pip list as a fallback check |
| 70 | +elif $PYTHON_CMD -m pip list | grep -i "platform-problem-monitoring-core" &>/dev/null; then |
| 71 | + echo "Package found in pip list" |
| 72 | + PACKAGE_INSTALLED=true |
| 73 | +fi |
| 74 | + |
| 75 | +# Determine if we're running from source or an installed package |
| 76 | +if [ "$PACKAGE_INSTALLED" = true ]; then |
50 | 77 | echo "Running from installed package"
|
51 |
| - PYTHON_CMD="python" |
| 78 | + PYTHON_CMD=$PYTHON_CMD |
52 | 79 | else
|
53 | 80 | # If running from source, detect package root and create/use virtual environment
|
54 | 81 | # When running from source, the script should be in bin/ which is at the root of the project
|
|
62 | 89 |
|
63 | 90 | if [ ! -d "venv" ]; then
|
64 | 91 | echo "Creating virtual environment"
|
65 |
| - python3 -m venv venv |
| 92 | + $PYTHON_CMD -m venv venv |
66 | 93 | fi
|
67 | 94 |
|
68 | 95 | source venv/bin/activate
|
|
0 commit comments