From f86a9cc04981f1411ef2c7f1b8112f33bcc7a8d5 Mon Sep 17 00:00:00 2001 From: Carlos Herrero Date: Mon, 25 Jul 2022 21:20:29 +0200 Subject: [PATCH] Prepare ropository for ROS2 (#108) --- jupyros/__init__.py | 14 ++++++------- jupyros/ros1/__init__.py | 16 +++++++++++++++ jupyros/{ => ros1}/ipy.py | 11 +++++----- jupyros/{ => ros1}/pubsub.py | 8 ++++---- jupyros/{ => ros1}/ros3d.py | 7 ++----- jupyros/{ => ros1}/ros_widgets.py | 28 ++++++++++++++++---------- jupyros/{ => ros1}/server_extension.py | 7 ++++--- jupyros/{ => ros1}/turtle_sim.py | 10 +++++---- jupyros/ros2/__init__.py | 16 +++++++++++++++ 9 files changed, 77 insertions(+), 40 deletions(-) create mode 100644 jupyros/ros1/__init__.py rename jupyros/{ => ros1}/ipy.py (85%) rename jupyros/{ => ros1}/pubsub.py (94%) rename jupyros/{ => ros1}/ros3d.py (99%) rename jupyros/{ => ros1}/ros_widgets.py (99%) rename jupyros/{ => ros1}/server_extension.py (96%) rename jupyros/{ => ros1}/turtle_sim.py (99%) create mode 100644 jupyros/ros2/__init__.py diff --git a/jupyros/__init__.py b/jupyros/__init__.py index 533e0f4..8f597ef 100644 --- a/jupyros/__init__.py +++ b/jupyros/__init__.py @@ -8,12 +8,12 @@ from ._version import version_info, __version__ -from .ros_widgets import * -from .pubsub import * -from .ipy import * -from .server_extension import * - -from .ros3d import * +from .ros1.ipy import * +from .ros1.pubsub import * +from .ros1.ros_widgets import * +from .ros1.ros3d import * +from .ros1.server_extension import * +from .ros1.turtle_sim import * def _jupyter_nbextension_paths(): return [{ @@ -32,4 +32,4 @@ def _jupyter_labextension_paths(): def _jupyter_server_extension_paths(): return [{ "module": "jupyros" - }] \ No newline at end of file + }] diff --git a/jupyros/ros1/__init__.py b/jupyros/ros1/__init__.py new file mode 100644 index 0000000..5ac9211 --- /dev/null +++ b/jupyros/ros1/__init__.py @@ -0,0 +1,16 @@ +############################################################################# +# Copyright (c) Wolf Vollprecht, QuantStack # +# # +# Distributed under the terms of the BSD 3-Clause License. # +# # +# The full license is in the file LICENSE, distributed with this software. # +############################################################################# + +from .._version import __version__ + +from .ipy import * +from .pubsub import * +from .ros_widgets import * +from .ros3d import * +from .server_extension import * +from .turtle_sim import * diff --git a/jupyros/ipy.py b/jupyros/ros1/ipy.py similarity index 85% rename from jupyros/ipy.py rename to jupyros/ros1/ipy.py index 7c0f0cd..97d10d7 100644 --- a/jupyros/ipy.py +++ b/jupyros/ros1/ipy.py @@ -5,14 +5,13 @@ # # # The full license is in the file LICENSE, distributed with this software. # ############################################################################# - -from IPython import get_ipython -from IPython.core.magic import register_line_magic, register_cell_magic, register_line_cell_magic +import sys from threading import Thread -import time -from jupyros.pubsub import output_registry + import ipywidgets as widgets -import sys +from IPython.core.magic import register_cell_magic + +from .pubsub import output_registry def executor(cell, gbls, lcls): exec(cell, gbls, lcls) diff --git a/jupyros/pubsub.py b/jupyros/ros1/pubsub.py similarity index 94% rename from jupyros/pubsub.py rename to jupyros/ros1/pubsub.py index 215e558..dd3ddbb 100644 --- a/jupyros/pubsub.py +++ b/jupyros/ros1/pubsub.py @@ -8,18 +8,18 @@ from __future__ import print_function +import sys import threading -import time + import ipywidgets as widgets -import sys try: import rospy except: + print("The actionlib package is not found in your $PYTHONPATH. Action clients are not going to work.") + print("Do you need to activate your ROS environment?") pass -import inspect - output_registry = {} subscriber_registry = {} diff --git a/jupyros/ros3d.py b/jupyros/ros1/ros3d.py similarity index 99% rename from jupyros/ros3d.py rename to jupyros/ros1/ros3d.py index 4b7f5df..4fddb31 100644 --- a/jupyros/ros3d.py +++ b/jupyros/ros1/ros3d.py @@ -8,13 +8,10 @@ import os -import ipywidgets as widgets from traitlets import * +import ipywidgets as widgets -try: - from _version import version_info -except: - from ._version import version_info +from .._version import version_info js_version = '^' + '.'.join([str(x) for x in version_info[:3]]) diff --git a/jupyros/ros_widgets.py b/jupyros/ros1/ros_widgets.py similarity index 99% rename from jupyros/ros_widgets.py rename to jupyros/ros1/ros_widgets.py index 9521103..06b0ffd 100644 --- a/jupyros/ros_widgets.py +++ b/jupyros/ros1/ros_widgets.py @@ -5,29 +5,35 @@ # # # The full license is in the file LICENSE, distributed with this software. # ############################################################################# +import os +import yaml +import threading +import subprocess +import numpy as np + +import bqplot as bq +import ipywidgets as widgets + try: import rospy except: print("The rospy package is not found in your $PYTHONPATH. Subscribe and publish are not going to work.") print("Do you need to activate your ROS environment?") + +try: + import actionlib +except: + print("The actionlib package is not found in your $PYTHONPATH. Action clients are not going to work.") + print("Do you need to activate your ROS environment?") + try: - from cv_bridge import CvBridge, CvBridgeError + from cv_bridge import CvBridge import cv2 bridge = CvBridge() except: pass -import bqplot as bq -import ipywidgets as widgets -import numpy as np -import threading -import subprocess, yaml, os - -try: - import actionlib -except: - print("The actionlib package is not found in your $PYTHONPATH. Action clients are not going to work.") def add_widgets(msg_instance, widget_dict, widget_list, prefix=''): diff --git a/jupyros/server_extension.py b/jupyros/ros1/server_extension.py similarity index 96% rename from jupyros/server_extension.py rename to jupyros/ros1/server_extension.py index 9844f3d..8907a64 100644 --- a/jupyros/server_extension.py +++ b/jupyros/ros1/server_extension.py @@ -5,15 +5,16 @@ # # # The full license is in the file LICENSE, distributed with this software. # ############################################################################# +import os from notebook.utils import url_path_join from notebook.base.handlers import IPythonHandler -from jupyros import _version import rospkg -import os -__version__ = _version.__version__ +from .._version import __version__ + +__version__ = __version__ if os.getenv('JUPYROS_DEFAULT_WS'): envs = os.getenv('JUPYROS_DEFAULT_WS').split(';') diff --git a/jupyros/turtle_sim.py b/jupyros/ros1/turtle_sim.py similarity index 99% rename from jupyros/turtle_sim.py rename to jupyros/ros1/turtle_sim.py index 52d099a..ddc13ad 100644 --- a/jupyros/turtle_sim.py +++ b/jupyros/ros1/turtle_sim.py @@ -1,10 +1,12 @@ +import os +import time +import math +import random + import ipycanvas import ipywidgets + import rospkg -import random -import time -import math -import os class TurtleSim: diff --git a/jupyros/ros2/__init__.py b/jupyros/ros2/__init__.py new file mode 100644 index 0000000..05a3273 --- /dev/null +++ b/jupyros/ros2/__init__.py @@ -0,0 +1,16 @@ +############################################################################# +# Copyright (c) Wolf Vollprecht, QuantStack # +# # +# Distributed under the terms of the BSD 3-Clause License. # +# # +# The full license is in the file LICENSE, distributed with this software. # +############################################################################# + +from .._version import __version__ + +from ..ros1.ipy import * +from ..ros1.pubsub import * +from ..ros1.ros_widgets import * +from ..ros1.ros3d import * +from ..ros1.server_extension import * +from ..ros1.turtle_sim import *