diff --git a/setup.py b/setup.py index d5a5543..424d9ea 100755 --- a/setup.py +++ b/setup.py @@ -34,7 +34,7 @@ def check_cv2(default_python="opencv-python"): setuptools.setup( name = 'wrapyfi', - version = '0.4.30', + version = '0.4.31', description = 'Wrapyfi is a wrapper for simplifying Middleware communication', url = 'https://github.com/fabawi/wrapyfi/blob/main/', project_urls={ diff --git a/wrapyfi/__init__.py b/wrapyfi/__init__.py index f2ffc58..003cc19 100755 --- a/wrapyfi/__init__.py +++ b/wrapyfi/__init__.py @@ -3,9 +3,10 @@ def get_project_info_from_setup(): + # when Wrapyfi is not installed try: curr_dir = os.path.dirname(__file__) - setup_path = os.path.join(curr_dir, '..', 'setup.py') + setup_path = os.path.join(curr_dir, "..", "setup.py") with open(setup_path, 'r') as f: content = f.read() except FileNotFoundError: @@ -13,6 +14,7 @@ def get_project_info_from_setup(): name_match = re.search(r"name\s*=\s*['\"]([^'\"]*)['\"]", content) version_match = re.search(r"version\s*=\s*['\"]([^'\"]*)['\"]", content) url_match = re.search(r"url\s*=\s*['\"]([^'\"]*)['\"]", content) + doc_match = re.search(r"'Documentation':\s*['\"]([^'\"]*)['\"]", content) if not name_match or not version_match or not url_match: # raise RuntimeError("Unable to find name, version, or url string.") @@ -21,7 +23,8 @@ def get_project_info_from_setup(): return { 'name': name_match.group(1), 'version': version_match.group(1), - 'url': url_match.group(1) + 'url': url_match.group(1), + 'doc': None if not doc_match else doc_match.group(1) } @@ -30,27 +33,44 @@ def get_project_info_from_setup(): __version__ = project_info.get('version', None) __url__ = project_info.get('url', None) +__doc__ = project_info.get('doc', None) name = project_info.get('name', 'wrapyfi') -if __version__ is None or __url__ is None: +if __version__ is None or __url__ is None or __doc__ is None: try: from importlib import metadata + mdata = metadata.metadata(__name__) __version__ = metadata.version(__name__) - __url__ = metadata.metadata(__name__)["Home-page"] + __url__ = mdata["Home-page"] + # when installed with PyPi if __url__ is None: - for url_extract in metadata.metadata("wrapyfi").get_all('Project-URL'): + for url_extract in mdata.get_all("Project-URL"): __url__ = url_extract.split(", ")[1] if url_extract.split(", ")[0] == "Homepage" else __url__ + if __doc__ is None: + for url_extract in mdata.get_all("Project-URL"): + __doc__ = url_extract.split(", ")[1] if url_extract.split(", ")[0] == "Documentation" else __doc__ except ImportError: try: + # when Python < 3.8 and setuptools/pip have not been updated import pkg_resources - __version__ = pkg_resources.require(name)[0].version - __url__ = pkg_resources.get_distribution(__name__).metadata["Home-page"] + mdata = pkg_resources.get_distribution(__name__).metadata + __version__ = pkg_resources.require(__name__)[0].version + __url__ = mdata["Home-page"] + # when installed with PyPi + if __url__ is None: + for url_extract in mdata.get_all("Project-URL"): + __url__ = url_extract.split(", ")[1] if url_extract.split(", ")[0] == "Homepage" else __url__ + if __doc__ is None: + for url_extract in mdata.get_all("Project-URL"): + __doc__ = url_extract.split(", ")[1] if url_extract.split(", ")[0] == "Documentation" else __doc__ except pkg_resources.DistributionNotFound: __version__ = "unknown_version" __url__ = "unknown_url" + __doc__ = "unknown_url" except Exception: __version__ = "unknown_version" __url__ = "unknown_url" + __doc__ = "unknown_url" from wrapyfi.utils import PluginRegistrar diff --git a/wrapyfi/clients/ros.py b/wrapyfi/clients/ros.py index fb7f7fc..ec02b12 100755 --- a/wrapyfi/clients/ros.py +++ b/wrapyfi/clients/ros.py @@ -274,7 +274,7 @@ def establish(self): logging.error("[ROS] Could not import ROSAudioService. " "Make sure the ROS services in wrapyfi_extensions/wrapyfi_ros_interfaces are compiled. " "Refer to the documentation for more information: \n" + - wrapyfi.__url__ + "wrapyfi_extensions/wrapyfi_ros_interfaces/README.md") + wrapyfi.__doc__ + "ros_interfaces_lnk.html") sys.exit(1) self._client = rospy.ServiceProxy(self.in_topic, ROSAudioService, persistent=self.persistent) self._req_msg = ROSAudioService._request_class() diff --git a/wrapyfi/clients/ros2.py b/wrapyfi/clients/ros2.py index aa2fc02..291d84e 100755 --- a/wrapyfi/clients/ros2.py +++ b/wrapyfi/clients/ros2.py @@ -86,7 +86,7 @@ def establish(self): logging.error("[ROS 2] Could not import ROS2NativeObjectService. " "Make sure the ROS 2 services in wrapyfi_extensions/wrapyfi_ros2_interfaces are compiled. " "Refer to the documentation for more information: \n" + - wrapyfi.__url__ + "wrapyfi_extensions/wrapyfi_ros2_interfaces/README.md") + wrapyfi.__doc__ + "ros2_interfaces_lnk.html") sys.exit(1) self._client = self.create_client(ROS2NativeObjectService, self.in_topic) self._req_msg = ROS2NativeObjectService.Request() @@ -202,7 +202,7 @@ def establish(self): logging.error("[ROS 2] Could not import ROS2ImageService. " "Make sure the ROS 2 services in wrapyfi_extensions/wrapyfi_ros2_interfaces are compiled. " "Refer to the documentation for more information: \n" + - wrapyfi.__url__ + "wrapyfi_extensions/wrapyfi_ros2_interfaces/README.md") + wrapyfi.__doc__ + "ros2_interfaces_lnk.html") sys.exit(1) if self.jpg: self._client = self.create_client(ROS2CompressedImageService, self.in_topic) @@ -331,7 +331,7 @@ def establish(self): logging.error("[ROS 2] Could not import ROS2AudioService. " "Make sure the ROS 2 services in wrapyfi_extensions/wrapyfi_ros2_interfaces are compiled. " "Refer to the documentation for more information: \n" + - wrapyfi.__url__ + "wrapyfi_extensions/wrapyfi_ros2_interfaces/README.md") + wrapyfi.__doc__ + "ros2_interfaces_lnk.html") sys.exit(1) self._client = self.create_client(ROS2AudioService, self.in_topic) self._req_msg = ROS2AudioService.Request() diff --git a/wrapyfi/listeners/ros.py b/wrapyfi/listeners/ros.py index bd6d02b..456cdf3 100755 --- a/wrapyfi/listeners/ros.py +++ b/wrapyfi/listeners/ros.py @@ -251,7 +251,7 @@ def establish(self): logging.error("[ROS] Could not import ROSAudioMessage. " "Make sure the ROS messages in wrapyfi_extensions/wrapyfi_ros_interfaces are compiled. " "Refer to the documentation for more information: \n" + - wrapyfi.__url__ + "wrapyfi_extensions/wrapyfi_ros_interfaces/README.md") + wrapyfi.__doc__ + "ros_interfaces_lnk.html") sys.exit(1) self._queue = queue.Queue(maxsize=0 if self.queue_size is None or self.queue_size <= 0 else self.queue_size) self._subscriber = rospy.Subscriber(self.in_topic, ROSAudioMessage, callback=self._message_callback) diff --git a/wrapyfi/listeners/ros2.py b/wrapyfi/listeners/ros2.py index 08d4fc3..984528b 100755 --- a/wrapyfi/listeners/ros2.py +++ b/wrapyfi/listeners/ros2.py @@ -256,7 +256,7 @@ def establish(self): logging.error("[ROS 2] Could not import ROS2AudioMessage. " "Make sure the ROS 2 services in wrapyfi_extensions/wrapyfi_ros2_interfaces are compiled. " "Refer to the documentation for more information: \n" + - wrapyfi.__url__ + "wrapyfi_extensions/wrapyfi_ros2_interfaces/README.md") + wrapyfi.__doc__ + "ros2_interfaces_lnk.html") sys.exit(1) self._queue = queue.Queue(maxsize=0 if self.queue_size is None or self.queue_size <= 0 else self.queue_size) self._subscriber = self.create_subscription(ROS2AudioMessage, self.in_topic, callback=self._message_callback, qos_profile=self.queue_size) diff --git a/wrapyfi/publishers/ros.py b/wrapyfi/publishers/ros.py index 2744e54..f4570d5 100755 --- a/wrapyfi/publishers/ros.py +++ b/wrapyfi/publishers/ros.py @@ -273,7 +273,7 @@ def establish(self, repeats: Optional[int] = None, **kwargs): logging.error("[ROS] Could not import ROSAudioMessage. " "Make sure the ROS messages in wrapyfi_extensions/wrapyfi_ros_interfaces are compiled. " "Refer to the documentation for more information: \n" + - wrapyfi.__url__ + "wrapyfi_extensions/wrapyfi_ros_interfaces/README.md") + wrapyfi.__doc__ + "ros_interfaces_lnk.html") sys.exit(1) self._publisher = rospy.Publisher(self.out_topic, ROSAudioMessage, queue_size=self.queue_size) self._sound_msg = ROSAudioMessage() diff --git a/wrapyfi/publishers/ros2.py b/wrapyfi/publishers/ros2.py index 1d307f8..40c6ae9 100755 --- a/wrapyfi/publishers/ros2.py +++ b/wrapyfi/publishers/ros2.py @@ -273,7 +273,7 @@ def establish(self, repeats: Optional[int] = None, **kwargs): logging.error("[ROS 2] Could not import ROS2AudioMessage. " "Make sure the ROS 2 services in wrapyfi_extensions/wrapyfi_ros2_interfaces are compiled. " "Refer to the documentation for more information: \n" + - wrapyfi.__url__ + "wrapyfi_extensions/wrapyfi_ros2_interfaces/README.md") + wrapyfi.__doc__ + "ros2_interfaces_lnk.html") sys.exit(1) self._publisher = self.create_publisher(ROS2AudioMessage, self.out_topic, qos_profile=self.queue_size) self._sound_msg = ROS2AudioMessage() diff --git a/wrapyfi/servers/ros.py b/wrapyfi/servers/ros.py index faf5442..c5c1fda 100755 --- a/wrapyfi/servers/ros.py +++ b/wrapyfi/servers/ros.py @@ -274,7 +274,7 @@ def establish(self): logging.error("[ROS] Could not import ROSAudioService. " "Make sure the ROS services in wrapyfi_extensions/wrapyfi_ros_interfaces are compiled. " "Refer to the documentation for more information: \n" + - wrapyfi.__url__ + "wrapyfi_extensions/wrapyfi_ros_interfaces/README.md") + wrapyfi.__doc__ + "ros_interfaces_lnk.html") sys.exit(1) self._server = rospy.Service(self.out_topic, ROSAudioService, self._service_callback) self._rep_msg = ROSAudioService._response_class().response diff --git a/wrapyfi/servers/ros2.py b/wrapyfi/servers/ros2.py index 3b0a3d5..89f16ae 100755 --- a/wrapyfi/servers/ros2.py +++ b/wrapyfi/servers/ros2.py @@ -92,7 +92,7 @@ def establish(self): logging.error("[ROS 2] Could not import ROS2NativeObjectService. " "Make sure the ROS 2 services in wrapyfi_extensions/wrapyfi_ros2_interfaces are compiled. " "Refer to the documentation for more information: \n" + - wrapyfi.__url__ + "wrapyfi_extensions/wrapyfi_ros2_interfaces/README.md") + wrapyfi.__doc__ + "ros2_interfaces_lnk.html") sys.exit(1) self._server = self.create_service(ROS2NativeObjectService, self.out_topic, self._service_callback) @@ -209,7 +209,7 @@ def establish(self): logging.error("[ROS 2] Could not import ROS2NativeObjectService. " "Make sure the ROS 2 services in wrapyfi_extensions/wrapyfi_ros2_interfaces are compiled. " "Refer to the documentation for more information: \n" + - wrapyfi.__url__ + "wrapyfi_extensions/wrapyfi_ros2_interfaces/README.md") + wrapyfi.__doc__ + "ros2_interfaces_lnk.html") sys.exit(1) if self.jpg: self._server = self.create_service(ROS2CompressedImageService, self.out_topic, self._service_callback) @@ -328,7 +328,7 @@ def establish(self): logging.error("[ROS 2] Could not import ROS2AudioService. " "Make sure the ROS 2 services in wrapyfi_extensions/wrapyfi_ros2_interfaces are compiled. " "Refer to the documentation for more information: \n" + - wrapyfi.__url__ + "wrapyfi_extensions/wrapyfi_ros2_interfaces/README.md") + wrapyfi.__doc__ + "ros2_interfaces_lnk.html") sys.exit(1) self._server = self.create_service(ROS2AudioService, self.out_topic, self._service_callback) self._req_msg = ROS2AudioService.Request()