diff --git a/BUILD.bazel b/BUILD.bazel index a89ad7df..ce3a90b9 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -1,4 +1,4 @@ -load("@rules_python//python:pip.bzl", "compile_pip_requirements") +load("@rules_ros2_pythons//3.10:defs.bzl", "compile_pip_requirements") compile_pip_requirements( name = "python_requirements", diff --git a/WORKSPACE b/WORKSPACE index 1493b660..cd178298 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -10,17 +10,17 @@ load("//repositories:deps.bzl", "ros2_deps") ros2_deps() -load("@rules_python//python:repositories.bzl", "py_repositories", "python_register_toolchains") +load("@rules_python//python:repositories.bzl", "py_repositories", "python_register_multi_toolchains") py_repositories() -python_register_toolchains( - name = "rules_ros2_python", - python_version = "3.10", +python_register_multi_toolchains( + name = "rules_ros2_pythons", + python_versions = ["3.10"], ) load("@rules_python//python:pip.bzl", "pip_parse") -load("@rules_ros2_python//:defs.bzl", python_interpreter_target = "interpreter") +load("@rules_ros2_pythons//3.10:defs.bzl", python_interpreter_target = "interpreter") load("//repositories:pip_annotations.bzl", "PIP_ANNOTATIONS") pip_parse( diff --git a/examples/WORKSPACE b/examples/WORKSPACE index b290b71e..42d2a101 100644 --- a/examples/WORKSPACE +++ b/examples/WORKSPACE @@ -26,18 +26,18 @@ load("@com_github_mvukov_rules_ros2//repositories:deps.bzl", "ros2_deps") ros2_deps() -load("@rules_python//python:repositories.bzl", "py_repositories", "python_register_toolchains") +load("@rules_python//python:repositories.bzl", "py_repositories", "python_register_multi_toolchains") py_repositories() -python_register_toolchains( - name = "rules_ros2_python", - python_version = "3.10", +python_register_multi_toolchains( + name = "rules_ros2_pythons", + python_versions = ["3.10"], ) load("@com_github_mvukov_rules_ros2//repositories:pip_annotations.bzl", "PIP_ANNOTATIONS") load("@rules_python//python:pip.bzl", "pip_parse") -load("@rules_ros2_python//:defs.bzl", python_interpreter_target = "interpreter") +load("@rules_ros2_pythons//3.10:defs.bzl", python_interpreter_target = "interpreter") pip_parse( name = "rules_ros2_pip_deps", diff --git a/repositories/rclcpp.BUILD.bazel b/repositories/rclcpp.BUILD.bazel index ae7c3083..5deb13ec 100644 --- a/repositories/rclcpp.BUILD.bazel +++ b/repositories/rclcpp.BUILD.bazel @@ -10,8 +10,8 @@ load( "rclcpp_interfaces", ) load("@com_github_mvukov_rules_ros2//ros2:cc_defs.bzl", "ros2_cpp_library") -load("@rules_python//python:defs.bzl", "py_binary") load("@rules_ros2_pip_deps//:requirements.bzl", "requirement") +load("@rules_ros2_pythons//3.10:defs.bzl", "py_binary") _GENERATE_LOGGING_MACROS_PY = "@com_github_mvukov_rules_ros2//repositories:generate_rclcpp_logging_macros.py" diff --git a/repositories/rcutils.BUILD.bazel b/repositories/rcutils.BUILD.bazel index b8358f00..0e3ba292 100644 --- a/repositories/rcutils.BUILD.bazel +++ b/repositories/rcutils.BUILD.bazel @@ -7,8 +7,9 @@ load( "logging_macros", ) load("@com_github_mvukov_rules_ros2//ros2:cc_defs.bzl", "ros2_c_library") -load("@rules_python//python:defs.bzl", "py_binary", "py_library") +load("@rules_python//python:defs.bzl", "py_library") load("@rules_ros2_pip_deps//:requirements.bzl", "requirement") +load("@rules_ros2_pythons//3.10:defs.bzl", "py_binary") _GENERATE_LOGGING_MACROS_PY = "@com_github_mvukov_rules_ros2//repositories:generate_rcutils_logging_macros.py" diff --git a/repositories/rosidl.BUILD.bazel b/repositories/rosidl.BUILD.bazel index 45c8ff74..d1be4bf0 100644 --- a/repositories/rosidl.BUILD.bazel +++ b/repositories/rosidl.BUILD.bazel @@ -9,8 +9,9 @@ load( "ros2_cpp_binary", "ros2_cpp_library", ) -load("@rules_python//python:defs.bzl", "py_binary", "py_library") +load("@rules_python//python:defs.bzl", "py_library") load("@rules_ros2_pip_deps//:requirements.bzl", "requirement") +load("@rules_ros2_pythons//3.10:defs.bzl", "py_binary") ros2_c_library( name = "rosidl_typesupport_interface", diff --git a/repositories/rosidl_python.BUILD.bazel b/repositories/rosidl_python.BUILD.bazel index ef4ae4fc..7bf60857 100644 --- a/repositories/rosidl_python.BUILD.bazel +++ b/repositories/rosidl_python.BUILD.bazel @@ -2,8 +2,9 @@ """ load("@bazel_skylib//rules:copy_file.bzl", "copy_file") -load("@rules_python//python:defs.bzl", "py_binary", "py_library") +load("@rules_python//python:defs.bzl", "py_library") load("@rules_ros2_pip_deps//:requirements.bzl", "requirement") +load("@rules_ros2_pythons//3.10:defs.bzl", "py_binary") py_library( name = "rosidl_generator_py_lib", diff --git a/repositories/rosidl_typesupport.BUILD.bazel b/repositories/rosidl_typesupport.BUILD.bazel index c06b233c..a517ecab 100644 --- a/repositories/rosidl_typesupport.BUILD.bazel +++ b/repositories/rosidl_typesupport.BUILD.bazel @@ -7,7 +7,8 @@ load( "ros2_c_library", "ros2_cpp_library", ) -load("@rules_python//python:defs.bzl", "py_binary", "py_library") +load("@rules_python//python:defs.bzl", "py_library") +load("@rules_ros2_pythons//3.10:defs.bzl", "py_binary") ros2_c_library( name = "rosidl_typesupport_c_c", diff --git a/repositories/xacro.BUILD.bazel b/repositories/xacro.BUILD.bazel index 4fb1e309..66d4f9bb 100644 --- a/repositories/xacro.BUILD.bazel +++ b/repositories/xacro.BUILD.bazel @@ -1,8 +1,9 @@ """ Builds xacro. """ -load("@rules_python//python:defs.bzl", "py_binary", "py_library") +load("@rules_python//python:defs.bzl", "py_library") load("@rules_ros2_pip_deps//:requirements.bzl", "requirement") +load("@rules_ros2_pythons//3.10:defs.bzl", "py_binary") py_library( name = "xacro", diff --git a/ros2/BUILD.bazel b/ros2/BUILD.bazel index 59a136f2..3cf1d6a9 100644 --- a/ros2/BUILD.bazel +++ b/ros2/BUILD.bazel @@ -1,7 +1,8 @@ """ ROS 2 common definitions. """ -load("@rules_python//python:defs.bzl", "py_binary", "py_library") +load("@rules_python//python:defs.bzl", "py_library") +load("@rules_ros2_pythons//3.10:defs.bzl", "py_binary") exports_files([ "ament.bzl", diff --git a/ros2/bag.bzl b/ros2/bag.bzl index 4a6f6ed1..3948352b 100644 --- a/ros2/bag.bzl +++ b/ros2/bag.bzl @@ -3,7 +3,7 @@ load("@bazel_skylib//lib:paths.bzl", "paths") load("@com_github_mvukov_rules_ros2//ros2:ament.bzl", "py_launcher") -load("@rules_python//python:defs.bzl", "py_binary") +load("@rules_ros2_pythons//3.10:defs.bzl", "py_binary") def ros2_bag(name, idl_deps = None, **kwargs): """ Defines a binary target for a bag app. diff --git a/ros2/launch.bzl b/ros2/launch.bzl index 37d27724..297ad795 100644 --- a/ros2/launch.bzl +++ b/ros2/launch.bzl @@ -2,7 +2,7 @@ """ load("@com_github_mvukov_rules_ros2//ros2:ament.bzl", "py_launcher") -load("@rules_python//python:defs.bzl", "py_binary") +load("@rules_ros2_pythons//3.10:defs.bzl", "py_binary") def ros2_launch(name, launch_file, nodes = None, deps = None, data = None, idl_deps = None, **kwargs): """ Defines a ROS 2 deployment. diff --git a/ros2/plugin_aspects.bzl b/ros2/plugin_aspects.bzl index e29f2795..f807c2f7 100644 --- a/ros2/plugin_aspects.bzl +++ b/ros2/plugin_aspects.bzl @@ -38,15 +38,16 @@ Ros2PluginCollectorAspectInfo = provider( ], ) -_ROS2_COLLECTOR_ATTR_ASPECTS = ["data", "deps"] +# From https://github.com/bazelbuild/rules_python/blob/0.33.2/python/config_settings/transition.bzl#L121-L140 +_py_transition_attrs = ["target", "tools"] + +_ROS2_COLLECTOR_ATTR_ASPECTS = ["data", "deps"] + _py_transition_attrs def _get_list_attr(rule_attr, attr_name): - if not hasattr(rule_attr, attr_name): - return [] - candidate = getattr(rule_attr, attr_name) - if type(candidate) != "list": - fail("Expected a list for attribute `{}`!".format(attr_name)) - return candidate + candidate = getattr(rule_attr, attr_name, []) + if type(candidate) == type([]): + return candidate + return [candidate] def _collect_deps(rule_attr, attr_name, provider_info): return [ diff --git a/ros2/py_defs.bzl b/ros2/py_defs.bzl index e0f7901a..24a44b1e 100644 --- a/ros2/py_defs.bzl +++ b/ros2/py_defs.bzl @@ -3,7 +3,7 @@ load("@com_github_mvukov_rules_ros2//ros2:ament.bzl", "sh_launcher", "split_kwargs") load("@com_github_mvukov_rules_ros2//third_party:symlink.bzl", "symlink") -load("@rules_python//python:defs.bzl", "py_binary", "py_test") +load("@rules_ros2_pythons//3.10:defs.bzl", "py_binary", "py_test") def _ros2_py_exec(target, name, srcs, main, set_up_ament, **kwargs): if set_up_ament == False: diff --git a/ros2/service.bzl b/ros2/service.bzl index 10fcf77b..9d5924b6 100644 --- a/ros2/service.bzl +++ b/ros2/service.bzl @@ -1,7 +1,7 @@ """ Implements a macro for setting up a ROS 2 service app. """ -load("@rules_python//python:defs.bzl", "py_binary") +load("@rules_ros2_pythons//3.10:defs.bzl", "py_binary") def ros2_service(name, deps, **kwargs): """ Defines a ROS 2 service app for a set of deps. diff --git a/ros2/test.bzl b/ros2/test.bzl index df964399..ebea8c63 100644 --- a/ros2/test.bzl +++ b/ros2/test.bzl @@ -2,8 +2,8 @@ """ load("@com_github_mvukov_rules_ros2//ros2:ament.bzl", "py_launcher") -load("@rules_python//python:defs.bzl", "py_test") load("@rules_ros2_pip_deps//:requirements.bzl", "requirement") +load("@rules_ros2_pythons//3.10:defs.bzl", "py_test") def ros2_test(name, launch_file, nodes = None, deps = None, data = None, idl_deps = None, use_pytest = False, **kwargs): """ Defines a ROS 2 test. diff --git a/ros2/topic.bzl b/ros2/topic.bzl index 75c2b0c1..1e11f5a4 100644 --- a/ros2/topic.bzl +++ b/ros2/topic.bzl @@ -1,7 +1,7 @@ """ Implements a macro for setting up a ROS 2 topic app. """ -load("@rules_python//python:defs.bzl", "py_binary") +load("@rules_ros2_pythons//3.10:defs.bzl", "py_binary") def ros2_topic(name, deps, **kwargs): """ Defines a ROS 2 topic app for a set of deps.