-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.sourceme
More file actions
137 lines (121 loc) · 5.46 KB
/
setup.sourceme
File metadata and controls
137 lines (121 loc) · 5.46 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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# SPDX-FileCopyrightText: 2026 Real-Time Innovations, Inc.
# SPDX-License-Identifier: Apache-2.0
##########
# Set up the Python environment for the tractor fleet comparison demo.
#
# Usage:
# source setup.sourceme # install all dependencies
# source setup.sourceme grpc # install only gRPC approach deps
# source setup.sourceme dds # install only DDS approach deps
# source setup.sourceme grpc-dds # install hybrid approach deps
#
# Environment variables you can override:
# PYTHON – Python interpreter (default: python3)
# VENV_DIR – venv directory name (default: venv)
# NDDSHOME – RTI Connext DDS installation directory (auto-detected if not set)
# RTI_PYTHON_DIR – RTI Connext Python API wheel directory
# (default: $NDDSHOME/resource/python_api)
# This file is sourced, not executed. Never use set -e/-u/-o pipefail at the
# top level — those options propagate to the interactive shell and cause it to
# exit on any error. We use explicit error checking instead.
# Find repo root as the directory containing this file (works in bash and zsh)
if [ -n "${BASH_SOURCE[0]+x}" ]; then
REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
else
REPO_ROOT="$(cd "$(dirname "$0")" && pwd)"
fi
cd "$REPO_ROOT"
APPROACH="${1:-all}"
REQS_FILE="$REPO_ROOT/requirements/${APPROACH}.txt"
if [ ! -f "$REQS_FILE" ]; then
echo "Unknown approach: $APPROACH"
echo "Available:"
for f in "$REPO_ROOT"/requirements/*.txt; do
echo " $(basename "$f" .txt)"
done
return 1 2>/dev/null || exit 1
fi
PYTHON="${PYTHON:-python3}"
VENV_DIR="${VENV_DIR:-venv}"
# ── Locate RTI Connext DDS installation ──────────────────────────────────
# Auto-detect NDDSHOME if not set. Exported so demo_start.sh scripts inherit it.
if [ -z "${NDDSHOME:-}" ]; then
# Use find to avoid zsh glob errors when a directory pattern has no matches
while IFS= read -r d; do
[ -d "$d/bin" ] && NDDSHOME="$d" # picks the last (newest) match
done < <(find /Applications /opt "$HOME" -maxdepth 1 -name 'rti_connext_dds-*' -type d 2>/dev/null | sort)
if [ -n "${NDDSHOME:-}" ]; then
echo "NOTE: NDDSHOME was not set — auto-detected $NDDSHOME"
fi
fi
if [ -n "${NDDSHOME:-}" ]; then
export NDDSHOME
fi
# ─────────────────────────────────────────────────────────────────────────
# Require Python >= 3.14.3
PY_VERSION=$($PYTHON -c 'import sys; print(f"{sys.version_info.major}.{sys.version_info.minor}.{sys.version_info.micro}")')
PY_OK=$($PYTHON -c 'import sys; print(1 if sys.version_info >= (3,14,3) else 0)')
if [ "$PY_OK" -ne 1 ]; then
echo "ERROR: Python >= 3.14.3 is required (found $PY_VERSION from '$PYTHON')"
echo " Set PYTHON to a supported interpreter, e.g.:"
echo " PYTHON=python3.14 source setup.sourceme $APPROACH"
return 1 2>/dev/null || exit 1
fi
if [ ! -d "$VENV_DIR" ]; then
"$PYTHON" -m venv "$VENV_DIR" --prompt venv
fi
# shellcheck disable=SC1091
source "$VENV_DIR/bin/activate"
python -m pip install --upgrade pip setuptools wheel
# macOS: pybullet's bundled zlib redefines fdopen which clashes with
# the Apple SDK _stdio.h header. This flag suppresses the TARGET_OS_*
# macros that trigger the conflict.
if [[ "$(uname)" == "Darwin" ]]; then
export CFLAGS="${CFLAGS:-} -fno-define-target-os-macros"
fi
# Install dependencies (excluding rti.connext which is not on PyPI)
{ grep -v 'rti\.connext' "$REQS_FILE" || true; } | { grep -v '^-r ' || true; } > /tmp/_reqs_filtered.txt
# Resolve -r references manually (one level deep)
for inc in $({ grep '^-r ' "$REQS_FILE" || true; } | sed 's/^-r //'); do
inc_path="$REPO_ROOT/requirements/$inc"
{ grep -v 'rti\.connext' "$inc_path" || true; } | { grep -v '^-r ' || true; } >> /tmp/_reqs_filtered.txt
# Handle nested -r (e.g., grpc-dds -> grpc -> common)
for inc2 in $({ grep '^-r ' "$inc_path" || true; } | sed 's/^-r //'); do
inc2_path="$REPO_ROOT/requirements/$inc2"
{ grep -v 'rti\.connext' "$inc2_path" || true; } | { grep -v '^-r ' || true; } >> /tmp/_reqs_filtered.txt
done
done
sort -u /tmp/_reqs_filtered.txt | python -m pip install -r /dev/stdin
rm -f /tmp/_reqs_filtered.txt
# RTI Connext Python API – installed from a local directory (not on PyPI).
if grep -rq 'rti\.connext' "$REQS_FILE" "$REPO_ROOT"/requirements/*.txt 2>/dev/null; then
# Check if rti.connext is actually needed for this approach
NEEDS_RTI=false
if grep -q 'rti\.connext' "$REQS_FILE"; then
NEEDS_RTI=true
else
for inc in $(grep '^-r ' "$REQS_FILE" | sed 's/^-r //'); do
if grep -q 'rti\.connext' "$REPO_ROOT/requirements/$inc"; then
NEEDS_RTI=true
break
fi
done
fi
if [ "$NEEDS_RTI" = true ]; then
RTI_PYTHON_DIR="${RTI_PYTHON_DIR:-${NDDSHOME:-}/resource/python_api}"
if [ -d "$RTI_PYTHON_DIR" ]; then
python -m pip install "rti.connext>=7.6.0" -f "$RTI_PYTHON_DIR"
else
echo "WARNING: RTI Python API directory not found at $RTI_PYTHON_DIR"
echo " Ensure NDDSHOME is set or set RTI_PYTHON_DIR manually:"
echo " RTI_PYTHON_DIR=/path/to/rti/resource/python_api source setup.sourceme $APPROACH"
fi
fi
fi
echo ""
echo "Environment ready for: $APPROACH"
echo " Python: $(which python)"
echo " venv: $REPO_ROOT/$VENV_DIR"
if [ -n "${NDDSHOME:-}" ]; then
echo " NDDSHOME: $NDDSHOME"
fi