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

Fix synchros2 aliasing as bdai_ros2_wrappers #135

Merged
merged 1 commit into from
Dec 20, 2024
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
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
Loading