Skip to content

Commit

Permalink
[jsk_unitree_startup/cross] Use sitecustomize.py instead of setting P…
Browse files Browse the repository at this point in the history
…YTHONPATH

[jsk_unitree_startup/cross] Install sitecustomize.py for real unitree robot
[jsk_unitree_startup/cross] Recursively append python site/dist-package paths
[jsk_unitree_startup/cross] Passthrough password
  • Loading branch information
iory authored and k-okada committed Oct 13, 2023
1 parent 10fcc21 commit f5c7b5d
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 3 deletions.
3 changes: 3 additions & 0 deletions jsk_unitree_robot/cross/build_ros1.sh
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ docker run -it --rm \
-e MAKEFLAGS=${MAKEFLAGS} \
-v ${HOST_INSTALL_ROOT}/ros1_dependencies:/opt/jsk/${INSTALL_ROOT}/ros1_dependencies:ro \
-v ${HOST_INSTALL_ROOT}/ros1_dependencies_setup.bash:/opt/jsk/${INSTALL_ROOT}/ros1_dependencies_setup.bash:ro \
-v ${PWD}/startup_scripts/sitecustomize.py:/usr/lib/python2.7/sitecustomize.py:ro \
-v ${PWD}/startup_scripts/sitecustomize.py:/usr/lib/python3.6/sitecustomize.py:ro \
-v ${HOST_INSTALL_ROOT}/ros1_inst:/opt/jsk/${INSTALL_ROOT}/ros1_inst:rw \
-v ${PWD}/${SOURCE_ROOT}:/home/user/${SOURCE_ROOT}:rw \
${IMAGE_NAME}:${TARGET_MACHINE} \
Expand All @@ -74,3 +76,4 @@ docker run -it --rm \
" 2>&1 | tee ${TARGET_MACHINE}_build_ros1.log

cp ${PWD}/startup_scripts/system_setup.bash ${HOST_INSTALL_ROOT}/
cp ${PWD}/startup_scripts/sitecustomize.py ${HOST_INSTALL_ROOT}/
4 changes: 3 additions & 1 deletion jsk_unitree_robot/cross/build_user.sh
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ docker run -it --rm \
-v ${HOST_INSTALL_ROOT}/ros1_inst:/opt/jsk/${INSTALL_ROOT}/ros1_inst:ro \
-v ${HOST_INSTALL_ROOT}/ros1_dependencies_setup.bash:/opt/jsk/${INSTALL_ROOT}/ros1_dependencies_setup.bash:ro \
-v ${HOST_INSTALL_ROOT}/system_setup.bash:/opt/jsk/${INSTALL_ROOT}/system_setup.bash:ro \
-v ${HOST_INSTALL_ROOT}/sitecustomize.py:/usr/lib/python2.7/sitecustomize.py:ro \
-v ${HOST_INSTALL_ROOT}/sitecustomize.py:/usr/lib/python3.6/sitecustomize.py:ro \
-v ${PWD}/${SOURCE_ROOT}:/opt/jsk/User:rw \
-v ${PWD}/rosinstall_generator_unreleased.py:/home/user/rosinstall_generator_unreleased.py:ro \
${IMAGE_NAME}:${TARGET_MACHINE} \
Expand All @@ -60,7 +62,7 @@ docker run -it --rm \
set -xeuf -o pipefail && \
cd /opt/jsk/User && \
[ ${UPDATE_SOURCE_ROOT} -eq 0 ] || ROS_PACKAGE_PATH=src:\${ROS_PACKAGE_PATH} /home/user/rosinstall_generator_unreleased.py jsk_${TARGET_ROBOT}_startup ${TARGET_ROBOT}eus --rosdistro melodic --exclude RPP --exclude mongodb_store | tee user.repos && \
[ ${UPDATE_SOURCE_ROOT} -eq 0 -o -z \"\$(cat user.repos)\" ] || PYTHONPATH= vcs import src < user.repos && \
[ ${UPDATE_SOURCE_ROOT} -eq 0 -o -z \"\$(cat user.repos)\" ] || vcs import src < user.repos && \
catkin build jsk_${TARGET_ROBOT}_startup ${TARGET_ROBOT}eus -s -vi \
--cmake-args -DCATKIN_ENABLE_TESTING=FALSE \
" 2>&1 | tee ${TARGET_MACHINE}_build_user.log
Expand Down
6 changes: 6 additions & 0 deletions jsk_unitree_robot/cross/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ function copy_data () {
ssh-keygen -f "${HOME}/.ssh/known_hosts" -R "${hostname}" || echo "OK"
sshpass -p $PASS ssh -o StrictHostKeyChecking=no ${user}@${hostname} exit

if [[ "${TARGET_DIRECTORY}" == "System" ]]; then
sshpass -p 123 scp ${TARGET_MACHINE}_${TARGET_DIRECTORY}/sitecustomize.py ${user}@${hostname}:/tmp/sitecustomize.py
sshpass -p $PASS ssh -t ${user}@${hostname} "echo $PASS | sudo -S cp -f /tmp/sitecustomize.py /usr/lib/python2.7/sitecustomize.py"
sshpass -p $PASS ssh -t ${user}@${hostname} "echo $PASS | sudo -S cp -f /tmp/sitecustomize.py /usr/lib/python3/sitecustomize.py"
fi

# cehck disk space
echo "Copy ${TARGET_MACHINE}_${TARGET_DIRECTORY} ...."
echo "==="
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@
export CMAKE_PREFIX_PATH="/opt/jsk/System/ros1_dependencies:${CMAKE_PREFIX_PATH}"
export PKG_CONFIG_PATH="/opt/jsk/System/ros1_dependencies/lib/pkgconfig:${PKG_CONFIG_PATH}"
export LD_LIBRARY_PATH="/opt/jsk/System/ros1_dependencies/lib:${LD_LIBRARY_PATH}"
export PYTHONPATH="/opt/jsk/System/ros1_dependencies/lib/python2.7/site-packages:${PYTHONPATH}"
# Python's sys.path is automatically set in /usr/lib/python2.7/sitecustomize.py
# export PYTHONPATH="/opt/jsk/System/ros1_dependencies/lib/python2.7/site-packages:${PYTHONPATH}"

# GI : for gir1.2-gstreamer-1.0, which is installed by ros1_dependencies_build_scripts/0006-gstreamer
export GI_TYPELIB_PATH="/opt/jsk/System/ros1_dependencies/lib/girepository-1.0"

# Python
export LD_LIBRARY_PATH="/opt/jsk/System/Python/lib:${LD_LIBRARY_PATH}"
export PYTHONPATH="/opt/jsk/System/Python/lib/python2.7/site-packages:${PYTHONPATH}"
# Python's sys.path is automatically set in /usr/lib/python2.7/sitecustomize.py
# export PYTHONPATH="/opt/jsk/System/Python/lib/python2.7/site-packages:${PYTHONPATH}"
export PATH="/opt/jsk/System/Python/bin:${PATH}"


39 changes: 39 additions & 0 deletions jsk_unitree_robot/cross/startup_scripts/sitecustomize.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# install the apport exception handler if available
import site
import sys
import os
import os.path as osp

site.PREFIXES += [
'/opt/jsk/System/Python/',
'/opt/jsk/System/ros1_dependencies/',
'/opt/jsk/System/ros1_inst/',
]


def recursively_listup_paths(path):
paths = []
for sub_path in os.listdir(path):
sub_full_path = osp.join(path, sub_path)
if osp.isdir(sub_full_path) and (sub_path.endswith('.egg-info') or sub_path.endswith('.egg')):
paths.append(sub_full_path)
return paths


paths = []
for path in site.getsitepackages():
if osp.exists(path):
paths.append(path)
paths.extend(recursively_listup_paths(path))
site_package = osp.join(osp.dirname(path), 'site-packages')
if site_package != path and osp.exists(site_package):
paths.append(site_package)
paths.extend(recursively_listup_paths(site_package))

sys.path.extend(paths)
try:
import apport_python_hook
except ImportError:
pass
else:
apport_python_hook.install()

0 comments on commit f5c7b5d

Please sign in to comment.