Skip to content

Commit

Permalink
Use rules_python for Python build rules
Browse files Browse the repository at this point in the history
  • Loading branch information
Jamie Snape committed Dec 10, 2019
1 parent 42c5fc4 commit 487f01b
Show file tree
Hide file tree
Showing 39 changed files with 74 additions and 43 deletions.
1 change: 1 addition & 0 deletions BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# This file is named BUILD.bazel instead of the more typical BUILD, so that on
# OSX it won't conflict with a build artifacts directory named "build".

load("//tools/skylark:py.bzl", "py_library")
load("@drake//tools/install:install.bzl", "install", "install_test")
load("//tools/lint:lint.bzl", "add_lint_tests")

Expand Down
1 change: 0 additions & 1 deletion bindings/pydrake/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ load(
"@drake//tools/skylark:drake_py.bzl",
"drake_py_binary",
"drake_py_library",
"drake_py_test",
"drake_py_unittest",
)
load(
Expand Down
1 change: 0 additions & 1 deletion bindings/pydrake/common/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ load(
load(
"@drake//tools/skylark:drake_py.bzl",
"drake_py_library",
"drake_py_test",
"drake_py_unittest",
)
load(
Expand Down
1 change: 0 additions & 1 deletion bindings/pydrake/manipulation/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ load(
)
load(
"@drake//tools/skylark:drake_py.bzl",
"drake_py_binary",
"drake_py_library",
"drake_py_unittest",
)
Expand Down
1 change: 0 additions & 1 deletion bindings/pydrake/solvers/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ load(
load(
"@drake//tools/skylark:drake_py.bzl",
"drake_py_library",
"drake_py_test",
"drake_py_unittest",
)
load(
Expand Down
4 changes: 0 additions & 4 deletions examples/kuka_iiwa_arm/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@ load(
load("@drake//tools/install:install.bzl", "install")
load("@drake//tools/install:install_data.bzl", "install_data")
load("//tools/lint:lint.bzl", "add_lint_tests")
load(
"@drake//tools/skylark:drake_py.bzl",
"drake_py_test",
)

package(
default_visibility = [":__subpackages__"],
Expand Down
5 changes: 0 additions & 5 deletions examples/planar_gripper/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,6 @@

load("@drake//tools/install:install.bzl", "install")
load("//tools/lint:lint.bzl", "add_lint_tests")
load(
"@drake//tools/skylark:drake_py.bzl",
"drake_py_binary",
"drake_py_library",
)
load(
"@drake//tools/skylark:drake_cc.bzl",
"drake_cc_binary",
Expand Down
1 change: 1 addition & 0 deletions tools/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# -*- python -*-

load("//tools/skylark:py.bzl", "py_binary", "py_library")
load("//tools/lint:lint.bzl", "add_lint_tests")
load(
"@drake//tools/skylark:drake_runfiles_binary.bzl",
Expand Down
3 changes: 3 additions & 0 deletions tools/bazel.rc
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ import %workspace%/tools/cc_toolchain/bazel.rc
import %workspace%/tools/dynamic_analysis/bazel.rc
import %workspace%/tools/lint/bazel.rc

# Disable native Python rules in Bazel versions before 2.0.
build --incompatible_load_python_rules_from_bzl=yes

# Default to an optimized build.
build -c opt

Expand Down
1 change: 1 addition & 0 deletions tools/external_data/bazel_external_data/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# -*- python -*-

load("//tools/skylark:py.bzl", "py_test")
load("//tools/external_data:expose_all_files.bzl", "expose_all_files")

# For macro testing.
Expand Down
4 changes: 3 additions & 1 deletion tools/external_data/external_data.bzl
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
# -*- python -*-

load("//tools/skylark:py.bzl", "py_test")

def external_data_stub_test():
# Define stub test using upstream package's file.
file = "@drake//tools/external_data/bazel_external_data:stub_test.py"
native.py_test(
py_test(
name = "stub_test",
srcs = [file],
main = file,
Expand Down
2 changes: 1 addition & 1 deletion tools/install/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

package(default_visibility = ["//visibility:public"])

load("//tools/skylark:py.bzl", "py_library")
load("//tools/lint:lint.bzl", "add_lint_tests")
load(
"@drake//tools/skylark:drake_py.bzl",
"drake_py_test",
"drake_py_unittest",
)

Expand Down
3 changes: 3 additions & 0 deletions tools/install/dummy/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# -*- python -*-

load("//tools/skylark:py.bzl", "py_library")
load("//tools/lint:lint.bzl", "add_lint_tests")
load("//tools/install:install.bzl", "install")
load(
Expand Down
3 changes: 2 additions & 1 deletion tools/install/install.bzl
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# -*- python -*-

load("//tools/skylark:py.bzl", "py_binary")
load("@drake//tools/skylark:drake_java.bzl", "MainClassInfo")
load("@drake//tools/skylark:drake_py.bzl", "drake_py_test")
load(
Expand Down Expand Up @@ -794,7 +795,7 @@ def cmake_config(
if cps_file_name:
fail("cps_file_name should not be set if " +
"script and version_file are set.")
native.py_binary(
py_binary(
name = "create-cps",
srcs = [script],
main = script,
Expand Down
1 change: 1 addition & 0 deletions tools/lint/python_lint.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ def python_lint(
Example:
BUILD:
load("//tools/lint:python_lint.bzl", "python_lint")
load("//tools/skylark:py.bzl", "py_library")
py_library(
name = "foo",
Expand Down
5 changes: 3 additions & 2 deletions tools/skylark/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
# -*- python -*-

package(default_visibility = ["//visibility:public"])

load("//tools/skylark:py.bzl", "py_binary")
load("//tools/lint:lint.bzl", "add_lint_tests")

package(default_visibility = ["//visibility:public"])

# Used by :python_env.bzl.
config_setting(
name = "linux",
Expand Down
3 changes: 2 additions & 1 deletion tools/skylark/alias.bzl
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# -*- python -*-

load("//tools/skylark:py.bzl", "py_library")
load(
"@drake//tools/skylark:drake_cc.bzl",
"drake_cc_library",
Expand Down Expand Up @@ -188,7 +189,7 @@ def drake_py_library_aliases(
),
)
actual_full_label = "//" + actual_subdir + actual_relative_label
native.py_library(
py_library(
name = stub_relative_label[1:],
deps = [actual_full_label],
srcs = [stub_file],
Expand Down
10 changes: 6 additions & 4 deletions tools/skylark/drake_py.bzl
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# -*- python -*-

load("//tools/skylark:py.bzl", "py_binary", "py_library", "py_test")

def drake_py_library(
name,
deps = None,
Expand All @@ -8,7 +10,7 @@ def drake_py_library(

# Work around https://github.com/bazelbuild/bazel/issues/1567.
deps = (deps or []) + ["//:module_py"]
native.py_library(
py_library(
name = name,
deps = deps,
**kwargs
Expand Down Expand Up @@ -130,7 +132,7 @@ def drake_py_binary(
main = srcs[0]
_py_target_isolated(
name = name,
py_target = native.py_binary,
py_target = py_binary,
isolate = isolate,
srcs = srcs,
main = main,
Expand Down Expand Up @@ -223,7 +225,7 @@ def drake_py_test(
tags = tags + ["py"]
_py_target_isolated(
name = name,
py_target = native.py_test,
py_target = py_test,
isolate = isolate,
size = size,
srcs = srcs,
Expand All @@ -240,7 +242,7 @@ def py_test_isolated(
"""
_py_target_isolated(
name = name,
py_target = native.py_test,
py_target = py_test,
isolate = True,
**kwargs
)
14 changes: 14 additions & 0 deletions tools/skylark/py.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# -*- python -*-

load(
"@rules_python//python:defs.bzl",
_py_binary = "py_binary",
_py_library = "py_library",
_py_test = "py_test",
)

py_binary = _py_binary

py_library = _py_library

py_test = _py_test
3 changes: 2 additions & 1 deletion tools/skylark/pybind.bzl
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# -*- python -*-

load("//tools/skylark:py.bzl", "py_library")
load("@cc//:compiler.bzl", "COMPILER_ID")

# @see bazelbuild/bazel#3493 for needing `@drake//` when loading `install`.
Expand All @@ -25,7 +26,7 @@ def pybind_py_library(
py_srcs = [],
py_deps = [],
py_imports = [],
py_library_rule = native.py_library,
py_library_rule = py_library,
**kwargs):
"""Declares a pybind11 Python library with C++ and Python portions.
Expand Down
1 change: 1 addition & 0 deletions tools/workspace/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# -*- python -*-

load("//tools/skylark:py.bzl", "py_library")
load("@drake//tools/install:check_licenses.bzl", "check_licenses")
load("@drake//tools/install:install.bzl", "install")
load(
Expand Down
2 changes: 2 additions & 0 deletions tools/workspace/clang_cindex_python3/package.BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# -*- python -*-

load("@drake//tools/skylark:py.bzl", "py_library")

licenses(["notice"]) # NCSA

py_library(
Expand Down
1 change: 1 addition & 0 deletions tools/workspace/drake_visualizer/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# -*- python -*-

load("//tools/skylark:py.bzl", "py_library")
load("//tools/lint:lint.bzl", "add_lint_tests")

exports_files(
Expand Down
3 changes: 3 additions & 0 deletions tools/workspace/drake_visualizer/plugin/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# -*- python -*-

load("//tools/skylark:py.bzl", "py_library")
load("//tools/lint:lint.bzl", "add_lint_tests")

py_library(
Expand Down
2 changes: 2 additions & 0 deletions tools/workspace/drake_visualizer/repository.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ def _impl(repository_ctx):
# DO NOT EDIT: generated by drake_visualizer_repository()
load("@drake//tools/skylark:py.bzl", "py_library")
licenses([
"notice", # Apache-2.0 AND BSD-3-Clause AND Python-2.0
"reciprocal", # MPL-2.0
Expand Down
6 changes: 2 additions & 4 deletions tools/workspace/github3_py/package.BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
# -*- python -*-

load(
"@drake//tools/install:install.bzl",
"install",
)
load("@drake//tools/install:install.bzl", "install")
load("@drake//tools/skylark:py.bzl", "py_library")

licenses(["notice"]) # BSD-3-Clause

Expand Down
2 changes: 2 additions & 0 deletions tools/workspace/godotengine/package.BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# -*- python -*-

load("@drake//tools/skylark:py.bzl", "py_binary")

licenses([
"notice", # Apache-2.0 AND BSD-3-Clause AND ISC AND MIT AND Zlib
"unencumbered", # Public-Domain
Expand Down
4 changes: 2 additions & 2 deletions tools/workspace/lcm/lcm.bzl
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# -*- python -*-

load("//tools/skylark:py.bzl", "py_library")
load(
"@drake//tools/workspace:generate_include_header.bzl",
"drake_generate_include_header",
Expand Down Expand Up @@ -250,8 +251,7 @@ def lcm_py_library(
if add_current_package_to_imports:
if "." not in imports:
imports = imports + ["."]

native.py_library(
py_library(
name = name,
srcs = outs + extra_srcs,
imports = imports,
Expand Down
6 changes: 2 additions & 4 deletions tools/workspace/lcm/package.BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# -*- python -*-
load(
"@drake//tools/skylark:drake_java.bzl",
"drake_java_binary",
)
load("@drake//tools/skylark:drake_java.bzl", "drake_java_binary")
load("@drake//tools/skylark:py.bzl", "py_library")
load("@drake//tools/workspace:generate_file.bzl", "generate_file")
load(
"@drake//tools/workspace:generate_export_header.bzl",
Expand Down
1 change: 1 addition & 0 deletions tools/workspace/meshcat_python/package.BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# -*- python -*-

load("@drake//tools/install:install.bzl", "install", "install_files")
load("@drake//tools/skylark:py.bzl", "py_binary", "py_library")

licenses(["notice"]) # MIT

Expand Down
1 change: 1 addition & 0 deletions tools/workspace/meshcat_python/repository.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Example:
meshcat_python_repository(name = "foo", mirrors = DEFAULT_MIRRORS)
BUILD:
load("//tools/skylark:py.bzl", "py_library")
py_library(
name = "foobar",
deps = ["@foo//:meshcat"],
Expand Down
1 change: 1 addition & 0 deletions tools/workspace/pybind11/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# -*- python -*-

load("//tools/skylark:py.bzl", "py_binary")
load("//tools/lint:lint.bzl", "add_lint_tests")
load(
"@drake//tools/skylark:pybind.bzl",
Expand Down
1 change: 1 addition & 0 deletions tools/workspace/pycodestyle/package.BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# -*- python -*-

load("@drake//tools/skylark:py.bzl", "py_binary")
load("@drake//tools/workspace:generate_file.bzl", "generate_file")

licenses(["notice"]) # MIT
Expand Down
2 changes: 2 additions & 0 deletions tools/workspace/pycps/package.BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# -*- python -*-

load("@drake//tools/skylark:py.bzl", "py_binary", "py_library")

licenses(["restricted"]) # LGPL-3.0+

genrule(
Expand Down
2 changes: 2 additions & 0 deletions tools/workspace/pypi.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ def pypi_archive(
)
foo.BUILD:
load("//tools/skylark:py.bzl", "py_library")
py_library(
name = "foo",
srcs = [
Expand All @@ -45,6 +46,7 @@ def pypi_archive(
)
BUILD:
load("//tools/skylark:py.bzl", "py_binary")
py_binary(
name = "foobar",
deps = ["@foo//:foo"],
Expand Down
2 changes: 2 additions & 0 deletions tools/workspace/semantic_version/package.BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# -*- python -*-

load("@drake//tools/skylark:py.bzl", "py_library")

licenses(["notice"]) # BSD-2-Clause

py_library(
Expand Down
Loading

0 comments on commit 487f01b

Please sign in to comment.