Skip to content

Commit

Permalink
Use our own Python for specific py_binaries and py_tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lalten committed Jun 30, 2024
1 parent b3247c9 commit 89ae747
Show file tree
Hide file tree
Showing 17 changed files with 38 additions and 31 deletions.
2 changes: 1 addition & 1 deletion BUILD.bazel
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
10 changes: 5 additions & 5 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
10 changes: 5 additions & 5 deletions examples/WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion repositories/rclcpp.BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
3 changes: 2 additions & 1 deletion repositories/rcutils.BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
3 changes: 2 additions & 1 deletion repositories/rosidl.BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
3 changes: 2 additions & 1 deletion repositories/rosidl_python.BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
3 changes: 2 additions & 1 deletion repositories/rosidl_typesupport.BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
3 changes: 2 additions & 1 deletion repositories/xacro.BUILD.bazel
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
3 changes: 2 additions & 1 deletion ros2/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
2 changes: 1 addition & 1 deletion ros2/bag.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion ros2/launch.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
15 changes: 8 additions & 7 deletions ros2/plugin_aspects.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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 [
Expand Down
2 changes: 1 addition & 1 deletion ros2/py_defs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion ros2/service.bzl
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
2 changes: 1 addition & 1 deletion ros2/test.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion ros2/topic.bzl
Original file line number Diff line number Diff line change
@@ -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.
Expand Down

0 comments on commit 89ae747

Please sign in to comment.