Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Import rosbag2_transport Python module on demand #190

Merged
merged 2 commits into from
Oct 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions ros2bag/ros2bag/verb/info.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@

from ros2bag.verb import VerbExtension

from rosbag2_transport import rosbag2_transport_py


class InfoVerb(VerbExtension):
"""ros2 bag info."""
Expand All @@ -34,5 +32,10 @@ def main(self, *, args): # noqa: D102
bag_file = args.bag_file
if not os.path.exists(bag_file):
return "[ERROR] [ros2bag]: bag file '{}' does not exist!".format(bag_file)

# NOTE(hidmic): in merged install workspaces on Windows, Python entrypoint lookups
# combined with constrained environments (as imposed by colcon test)
# may result in DLL loading failures when attempting to import a C
# extension. Therefore, do not import rosbag2_transport at the module
# level but on demand, right before first use.
from rosbag2_transport import rosbag2_transport_py
rosbag2_transport_py.info(uri=bag_file, storage_id=args.storage)
8 changes: 6 additions & 2 deletions ros2bag/ros2bag/verb/play.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

from ros2bag.verb import VerbExtension
from ros2cli.node import NODE_NAME_PREFIX
from rosbag2_transport import rosbag2_transport_py


class PlayVerb(VerbExtension):
Expand All @@ -38,7 +37,12 @@ def main(self, *, args): # noqa: D102
bag_file = args.bag_file
if not os.path.exists(bag_file):
return "[ERROR] [ros2bag] bag file '{}' does not exist!".format(bag_file)

# NOTE(hidmic): in merged install workspaces on Windows, Python entrypoint lookups
# combined with constrained environments (as imposed by colcon test)
# may result in DLL loading failures when attempting to import a C
# extension. Therefore, do not import rosbag2_transport at the module
# level but on demand, right before first use.
from rosbag2_transport import rosbag2_transport_py
rosbag2_transport_py.play(
uri=bag_file,
storage_id=args.storage,
Expand Down
15 changes: 14 additions & 1 deletion ros2bag/ros2bag/verb/record.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
from ros2cli.node.strategy import NodeStrategy
from ros2cli.node.strategy import add_arguments
from ros2cli.node import NODE_NAME_PREFIX
from rosbag2_transport import rosbag2_transport_py


class RecordVerb(VerbExtension):
Expand Down Expand Up @@ -73,6 +72,13 @@ def main(self, *, args): # noqa: D102
self.create_bag_directory(uri)

if args.all:
# NOTE(hidmic): in merged install workspaces on Windows, Python entrypoint lookups
# combined with constrained environments (as imposed by colcon test)
# may result in DLL loading failures when attempting to import a C
# extension. Therefore, do not import rosbag2_transport at the module
# level but on demand, right before first use.
from rosbag2_transport import rosbag2_transport_py

rosbag2_transport_py.record(
uri=uri,
storage_id=args.storage,
Expand All @@ -82,6 +88,13 @@ def main(self, *, args): # noqa: D102
no_discovery=args.no_discovery,
polling_interval=args.polling_interval)
elif args.topics and len(args.topics) > 0:
# NOTE(hidmic): in merged install workspaces on Windows, Python entrypoint lookups
# combined with constrained environments (as imposed by colcon test)
# may result in DLL loading failures when attempting to import a C
# extension. Therefore, do not import rosbag2_transport at the module
# level but on demand, right before first use.
from rosbag2_transport import rosbag2_transport_py

rosbag2_transport_py.record(
uri=uri,
storage_id=args.storage,
Expand Down