Skip to content

Commit

Permalink
Fix synchros2 aliasing as bdai_ros2_wrappers (#135)
Browse files Browse the repository at this point in the history
Signed-off-by: Michel Hidalgo <mhidalgo@theaiinstitute.com>
  • Loading branch information
mhidalgo-bdai authored Dec 20, 2024
1 parent 539c962 commit 8793817
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 3 deletions.
16 changes: 15 additions & 1 deletion bdai_ros2_wrappers/bdai_ros2_wrappers/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
# Copyright (c) 2024 Boston Dynamics AI Institute Inc. All rights reserved.

import importlib
import pkgutil
import sys

sys.modules[__name__] = __import__("synchros2")

def aliased_import(name, alias):
"""Import a module or a package using an alias for it.
For packages, this function will recursively import all its subpackages and modules.
"""
sys.modules[alias] = module = importlib.import_module(name)
if hasattr(module, "__path__"):
for info in pkgutil.iter_modules(module.__path__):
aliased_import(f"{name}.{info.name}", f"{alias}.{info.name}")


aliased_import("synchros2", alias=__name__)
3 changes: 2 additions & 1 deletion bdai_ros2_wrappers/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@
],
install_requires=["setuptools"],
maintainer="The AI Institute",
maintainer_email="engineering@theaiinstitute.com",
maintainer_email="opensource@theaiinstitute.com",
description="The AI Institute's wrappers for ROS2",
tests_require=["pytest"],
zip_safe=True,
license="MIT",
)
13 changes: 13 additions & 0 deletions bdai_ros2_wrappers/test/test_import.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Copyright (c) 2024 Boston Dynamics AI Institute Inc. All rights reserved.

import bdai_ros2_wrappers.scope
import synchros2.scope


def test_submodule_aliasing() -> None:
assert id(bdai_ros2_wrappers.scope) == id(synchros2.scope)


def test_global_aliasing() -> None:
with bdai_ros2_wrappers.scope.top(global_=True) as top:
assert synchros2.scope.current() is top
2 changes: 1 addition & 1 deletion synchros2/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
],
install_requires=["setuptools"],
maintainer="The AI Institute",
maintainer_email="engineering@theaiinstitute.com",
maintainer_email="opensource@theaiinstitute.com",
description="The AI Institute's wrappers for ROS2",
tests_require=["pytest"],
zip_safe=True,
Expand Down

0 comments on commit 8793817

Please # to comment.