From 43bfa4dc3ae18ab66eaeadd01fb463f206adcf39 Mon Sep 17 00:00:00 2001 From: Xiang Lei Date: Wed, 11 Dec 2024 10:05:30 +0800 Subject: [PATCH 1/3] ci: Create GitHub Actions workflow to build and deploy documentation - Create new GitHub Actions workflow for building GitHub Pages - Added GitHub Pages workflow to build and deploy Sphinx documentation - Configured workflow to run on pushes to the "main" branch - Deployed built documentation to GitHub Pages using `github-pages-deploy-action` --- .github/workflows/build.yml | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 .github/workflows/build.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..bbcf041 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,37 @@ +name: GitHub Pages + +on: + push: + branches: ["main"] + +# 权限 +permissions: + contents: write + +jobs: + build-and-deploy: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: 3.12 + + - name: Install dependencies + run: | + pip install -e .[docs] + + - name: Build Sphinx documentation + run: | + sphinx-build -b html docs build + # 创建 .nojekyll 文件以允许下划线开头的文件夹 + touch build/.nojekyll + + - name: Deploy to GitHub Pages + uses: JamesIves/github-pages-deploy-action@4.1.4 + with: + branch: gh-pages + folder: build \ No newline at end of file From e256de5fb92769a7c23ad5b7d56927d5dfe39824 Mon Sep 17 00:00:00 2001 From: Xiang Lei Date: Wed, 11 Dec 2024 11:22:23 +0800 Subject: [PATCH 2/3] Update build.yml --- .github/workflows/build.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index bbcf041..fb0cd92 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -22,6 +22,7 @@ jobs: - name: Install dependencies run: | + pip install -e . pip install -e .[docs] - name: Build Sphinx documentation @@ -34,4 +35,4 @@ jobs: uses: JamesIves/github-pages-deploy-action@4.1.4 with: branch: gh-pages - folder: build \ No newline at end of file + folder: build From 839e48a7bf765a1351c5ed24c2235ad07378f715 Mon Sep 17 00:00:00 2001 From: Yiwen Lu Date: Wed, 11 Dec 2024 11:30:10 +0800 Subject: [PATCH 3/3] fix(ros_compat): handle missing ROS imports gracefully This update modifies the import handling for ROS1 and ROS2 in the ros_compat module. Instead of raising an ImportError when neither rospy nor rclpy is found, a warning is issued, and ROS_VERSION is set to None. This change ensures that the system can handle the absence of both ROS versions more gracefully, allowing for better error management and debugging. --- ros_compat/__init__.py | 4 +++- ros_compat/logging.py | 7 ++++++- ros_compat/node.py | 6 +++++- ros_compat/time.py | 11 +++++++++-- 4 files changed, 23 insertions(+), 5 deletions(-) diff --git a/ros_compat/__init__.py b/ros_compat/__init__.py index 31eb6c9..a017981 100644 --- a/ros_compat/__init__.py +++ b/ros_compat/__init__.py @@ -7,7 +7,9 @@ import rospy ROS_VERSION = 1 except ImportError: - raise ImportError("Neither ROS1 (rospy) nor ROS2 (rclpy) was found") + import warnings + warnings.warn("Neither ROS1 (rospy) nor ROS2 (rclpy) was found") + ROS_VERSION = None from .node import ROSNode from .time import ROSTime diff --git a/ros_compat/logging.py b/ros_compat/logging.py index bbd80b7..5cba576 100644 --- a/ros_compat/logging.py +++ b/ros_compat/logging.py @@ -5,7 +5,10 @@ try: import rclpy as ros except ImportError: - import rospy as ros + try: + import rospy as ros + except ImportError: + ros = None class ROSLogger: """Wrapper for ROS logging functions. @@ -16,6 +19,8 @@ class ROSLogger: node_name (str): Name of the node for logging context """ def __init__(self, node_name: str): + if ROS_VERSION is None: + raise ImportError("Neither ROS1 (rospy) nor ROS2 (rclpy) was found") self.node_name = node_name if ROS_VERSION == 2: self.logger = ros.logging.get_logger(node_name) diff --git a/ros_compat/node.py b/ros_compat/node.py index 254e286..ff9544b 100644 --- a/ros_compat/node.py +++ b/ros_compat/node.py @@ -12,10 +12,12 @@ from rclpy.time import Time as ROS2Time from rclpy.timer import Timer as ROS2Timer from rclpy.qos import QoSProfile, ReliabilityPolicy -else: +elif ROS_VERSION == 1: import rospy ros = rospy # For consistent naming from rospy import Time as ROS1Time +else: + ros = None from .time import ROSTime from .logging import ROSLogger @@ -30,6 +32,8 @@ class ROSNode: node_name (str): Name of the node """ def __init__(self, node_name: str): + if ROS_VERSION is None: + raise ImportError("Neither ROS1 (rospy) nor ROS2 (rclpy) was found") self.node_name = node_name if ROS_VERSION == 2: diff --git a/ros_compat/time.py b/ros_compat/time.py index 9967364..8ebedf8 100644 --- a/ros_compat/time.py +++ b/ros_compat/time.py @@ -4,8 +4,11 @@ import rclpy as ros from rclpy.time import Time as ROS2Time except ImportError: - import rospy as ros - from rospy import Time as ROS1Time + try: + import rospy as ros + from rospy import Time as ROS1Time + except ImportError: + ros = None class ROSTime: @@ -26,6 +29,8 @@ def now() -> float: >>> current_time = ROSTime.now() >>> print(f"Current time: {current_time}") """ + if ROS_VERSION is None: + raise ImportError("Neither ROS1 (rospy) nor ROS2 (rclpy) was found") if ROS_VERSION == 2: return float(ros.time.Time().nanoseconds / 1e9) return float(ros.Time.now().to_sec()) @@ -33,6 +38,8 @@ def now() -> float: @staticmethod def sleep(duration: float) -> None: """Sleep for specified duration in seconds.""" + if ROS_VERSION is None: + raise ImportError("Neither ROS1 (rospy) nor ROS2 (rclpy) was found") if ROS_VERSION == 2: ros.time.sleep(duration) else: