diff --git a/bdai_ros2_wrappers/bdai_ros2_wrappers/__init__.py b/bdai_ros2_wrappers/bdai_ros2_wrappers/__init__.py index dd73d13..598bfe3 100644 --- a/bdai_ros2_wrappers/bdai_ros2_wrappers/__init__.py +++ b/bdai_ros2_wrappers/bdai_ros2_wrappers/__init__.py @@ -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__) diff --git a/bdai_ros2_wrappers/setup.py b/bdai_ros2_wrappers/setup.py index a144595..b23ea9c 100644 --- a/bdai_ros2_wrappers/setup.py +++ b/bdai_ros2_wrappers/setup.py @@ -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", ) diff --git a/bdai_ros2_wrappers/test/test_import.py b/bdai_ros2_wrappers/test/test_import.py new file mode 100644 index 0000000..c56ee43 --- /dev/null +++ b/bdai_ros2_wrappers/test/test_import.py @@ -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 diff --git a/synchros2/setup.py b/synchros2/setup.py index 42c6fde..189f47a 100644 --- a/synchros2/setup.py +++ b/synchros2/setup.py @@ -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,