Skip to content

Commit

Permalink
Merge pull request #82 from modular-ml/dev
Browse files Browse the repository at this point in the history
Updated links to documentation after ROS and ROS 2 interface separation into repos
  • Loading branch information
fabawi authored Jan 12, 2024
2 parents cb8cdbd + 413a1a2 commit 0b606f5
Show file tree
Hide file tree
Showing 10 changed files with 40 additions and 20 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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={
Expand Down
34 changes: 27 additions & 7 deletions wrapyfi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,18 @@


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:
return {}
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.")
Expand All @@ -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)
}


Expand All @@ -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

Expand Down
2 changes: 1 addition & 1 deletion wrapyfi/clients/ros.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
6 changes: 3 additions & 3 deletions wrapyfi/clients/ros2.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion wrapyfi/listeners/ros.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion wrapyfi/listeners/ros2.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion wrapyfi/publishers/ros.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion wrapyfi/publishers/ros2.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion wrapyfi/servers/ros.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions wrapyfi/servers/ros2.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 0b606f5

Please sign in to comment.