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

Enable buildifier presubmit check #245

Merged
merged 8 commits into from
Oct 23, 2019
Merged
Show file tree
Hide file tree
Changes from 5 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
3 changes: 3 additions & 0 deletions .bazelci/presubmit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
# TODO(#144): When Bazel 0.29 is released, the docgen workflow will work, and
# we can go back to using `...` for build_targets.
---
buildifier:
version: latest
warnings: "all"
all_targets: &all_targets
build_targets:
- "//examples/..."
Expand Down
5 changes: 4 additions & 1 deletion BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ package(default_visibility = ["//visibility:public"])

licenses(["notice"]) # Apache 2.0

exports_files(["LICENSE", "version.bzl"])
exports_files([
"LICENSE",
"version.bzl",
])

filegroup(
name = "distribution",
Expand Down
10 changes: 7 additions & 3 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,25 @@ load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

http_archive(
name = "bazel_federation",
url = "https://github.com/bazelbuild/bazel-federation/releases/download/0.0.1/bazel_federation-0.0.1.tar.gz",
sha256 = "506dfbfd74ade486ac077113f48d16835fdf6e343e1d4741552b450cfc2efb53",
url = "https://github.com/bazelbuild/bazel-federation/releases/download/0.0.1/bazel_federation-0.0.1.tar.gz",
)

load("@bazel_federation//:repositories.bzl", "rules_python_deps")

rules_python_deps()

load("@bazel_federation//setup:rules_python.bzl", "rules_python_setup")
rules_python_setup(use_pip=True)
load("@bazel_federation//setup:rules_python.bzl", "rules_python_setup")

rules_python_setup(use_pip = True)

# Everything below this line is used only for developing rules_python. Users
# should not copy it to their WORKSPACE.

load("//:internal_deps.bzl", "rules_python_internal_deps")

rules_python_internal_deps()

load("//:internal_setup.bzl", "rules_python_internal_setup")

rules_python_internal_setup()
2 changes: 1 addition & 1 deletion distro/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ package(
default_visibility = ["//visibility:private"],
)

load("@rules_python//:version.bzl", "version")
load("@rules_pkg//:pkg.bzl", "pkg_tar")
load("@rules_pkg//releasing:defs.bzl", "print_rel_notes")
load("@rules_python//:version.bzl", "version")

# Build the artifact to put on the github release page.
pkg_tar(
Expand Down
8 changes: 4 additions & 4 deletions docs/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ load("@io_bazel_skydoc//stardoc:stardoc.bzl", "stardoc")
bzl_library(
name = "bazel_python_tools",
srcs = [
"@bazel_tools//tools/python:private/defs.bzl",
"@bazel_tools//tools/python:srcs_version.bzl",
"@bazel_tools//tools/python:toolchain.bzl",
"@bazel_tools//tools/python:utils.bzl",
"@bazel_tools//tools/python:private/defs.bzl",
],
)

Expand All @@ -49,8 +49,8 @@ bzl_library(

stardoc(
name = "core-docs",
input = "//python:defs.bzl",
out = "python.md",
input = "//python:defs.bzl",
deps = [":defs"],
)

Expand All @@ -60,12 +60,12 @@ stardoc(

stardoc(
name = "pip-docs",
input = "//python:pip.bzl",
out = "pip.md",
input = "//python:pip.bzl",
)

stardoc(
name = "whl-docs",
input = "//python:whl.bzl",
out = "whl.md",
input = "//python:whl.bzl",
)
2 changes: 1 addition & 1 deletion examples/extras/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ load("//python:defs.bzl", "py_test")
py_test(
name = "extras_test",
srcs = ["extras_test.py"],
python_version = "PY2",
deps = [
requirement("google-cloud-language"),
# Make sure that we can resolve the "extra" dependency
requirement("googleapis-common-protos[grpc]"),
],
python_version = "PY2",
)
2 changes: 1 addition & 1 deletion examples/helloworld/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ py_library(
py_test(
name = "helloworld_test",
srcs = ["helloworld_test.py"],
deps = [":helloworld"],
python_version = "PY2",
deps = [":helloworld"],
)
38 changes: 19 additions & 19 deletions experimental/examples/wheel/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ package(default_visibility = ["//visibility:public"])

licenses(["notice"]) # Apache 2.0

load("//python:defs.bzl", "py_library", "py_test")
load("//experimental/python:wheel.bzl", "py_package", "py_wheel")
load("//python:defs.bzl", "py_library", "py_test")

py_library(
name = "main",
Expand Down Expand Up @@ -91,54 +91,54 @@ py_wheel(
# Package data. We're building "custom_package_root-0.0.1-py3-none-any.whl"
distribution = "example_custom_package_root",
python_tag = "py3",
strip_path_prefixes = [
"experimental",
],
version = "0.0.1",
deps = [
":example_pkg"
":example_pkg",
],
strip_path_prefixes = [
"experimental"
]
)

py_wheel(
name = "custom_package_root_multi_prefix",
# Package data. We're building "custom_custom_package_root_multi_prefix-0.0.1-py3-none-any.whl"
distribution = "example_custom_package_root_multi_prefix",
python_tag = "py3",
strip_path_prefixes = [
"experimental/examples/wheel/lib",
"experimental/examples/wheel",
],
version = "0.0.1",
deps = [
":example_pkg"
":example_pkg",
],
strip_path_prefixes = [
"experimental/examples/wheel/lib",
"experimental/examples/wheel"
]
)

py_wheel(
name = "custom_package_root_multi_prefix_reverse_order",
# Package data. We're building "custom_custom_package_root_multi_prefix_reverse_order-0.0.1-py3-none-any.whl"
distribution = "example_custom_package_root_multi_prefix_reverse_order",
python_tag = "py3",
strip_path_prefixes = [
"experimental/examples/wheel",
"experimental/examples/wheel/lib", # this is not effective, because the first prefix takes priority
],
version = "0.0.1",
deps = [
":example_pkg"
":example_pkg",
],
strip_path_prefixes = [
"experimental/examples/wheel" ,
"experimental/examples/wheel/lib" # this is not effective, because the first prefix takes priority
]
)

py_test(
name = "wheel_test",
srcs = ["wheel_test.py"],
data = [
":custom_package_root",
":custom_package_root_multi_prefix",
":custom_package_root_multi_prefix_reverse_order",
":customized",
":minimal_with_py_library",
":minimal_with_py_package",
":custom_package_root",
":custom_package_root_multi_prefix",
":custom_package_root_multi_prefix_reverse_order"
]
],
)
80 changes: 41 additions & 39 deletions experimental/python/wheel.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,16 @@ def _path_inside_wheel(input_file):
# input_file.short_path is sometimes relative ("../${repository_root}/foobar")
# which is not a valid path within a zip file. Fix that.
short_path = input_file.short_path
if short_path.startswith('..') and len(short_path) >= 3:
if short_path.startswith("..") and len(short_path) >= 3:
# Path separator. '/' on linux.
separator = short_path[2]

# Consume '../' part.
short_path = short_path[3:]

# Find position of next '/' and consume everything up to that character.
pos = short_path.find(separator)
short_path = short_path[pos+1:]
short_path = short_path[pos + 1:]
return short_path

def _input_file_to_arg(input_file):
Expand Down Expand Up @@ -67,7 +69,6 @@ belong to given set of Python packages.
This rule is intended to be used as data dependency to py_wheel rule
""",
attrs = {
"deps": attr.label_list(),
"packages": attr.string_list(
mandatory = False,
allow_empty = True,
Expand All @@ -76,6 +77,7 @@ List of Python packages to include in the distribution.
Sub-packages are automatically included.
""",
),
"deps": attr.label_list(),
},
)

Expand Down Expand Up @@ -197,18 +199,21 @@ py_wheel(
</code>
""",
attrs = {
"deps": attr.label_list(
"abi": attr.string(
default = "none",
doc = "Python ABI tag. 'none' for pure-Python wheels.",
),
# Other attributes
"author": attr.string(default = ""),
"author_email": attr.string(default = ""),
"classifiers": attr.string_list(),
# Entry points
"console_scripts": attr.string_dict(
doc = """\
Targets to be included in the distribution.

The targets to package are usually `py_library` rules or filesets (for packaging data files).

Note it's usually better to package `py_library` targets and use
`console_scripts` attribute to specify entry points than to package
`py_binary` rules. `py_binary` targets would wrap a executable script that
tries to locate `.runfiles` directory which is not packaged in the wheel.
console_script entry points, e.g. 'experimental.examples.wheel.main:main'.
""",
),
"description_file": attr.label(allow_single_file = True),
# Attributes defining the distribution
brandjon marked this conversation as resolved.
Show resolved Hide resolved
"distribution": attr.string(
mandatory = True,
Expand All @@ -219,46 +224,43 @@ This should match the project name onm PyPI. It's also the name that is used
to refer to the package in other packages' dependencies.
""",
),
"version": attr.string(
mandatory = True,
doc = "Version number of the package",
),
"python_tag": attr.string(
default = "py3",
doc = "Supported Python major version. 'py2' or 'py3'",
values = ["py2", "py3"],
),
"abi": attr.string(
default = "none",
doc = "Python ABI tag. 'none' for pure-Python wheels.",
"extra_requires": attr.string_list_dict(
doc = "List of optional requirements for this package",
),
"homepage": attr.string(default = ""),
"license": attr.string(default = ""),
# TODO(pstradomski): Support non-pure wheels
"platform": attr.string(
default = "any",
doc = "Supported platforms. 'any' for pure-Python wheel.",
),
# Other attributes
"author": attr.string(default = ""),
"author_email": attr.string(default = ""),
"homepage": attr.string(default = ""),
"license": attr.string(default = ""),
"classifiers": attr.string_list(),
"description_file": attr.label(allow_single_file = True),
"strip_path_prefixes": attr.string_list(
default = [],
doc = "path prefixes to strip from files added to the generated package",
"python_tag": attr.string(
default = "py3",
doc = "Supported Python major version. 'py2' or 'py3'",
values = ["py2", "py3"],
),
# Requirements
"requires": attr.string_list(
doc = "List of requirements for this package",
),
"extra_requires": attr.string_list_dict(
doc = "List of optional requirements for this package",
"strip_path_prefixes": attr.string_list(
default = [],
doc = "path prefixes to strip from files added to the generated package",
),
# Entry points
"console_scripts": attr.string_dict(
"version": attr.string(
mandatory = True,
doc = "Version number of the package",
),
"deps": attr.label_list(
doc = """\
console_script entry points, e.g. 'experimental.examples.wheel.main:main'.
Targets to be included in the distribution.

The targets to package are usually `py_library` rules or filesets (for packaging data files).

Note it's usually better to package `py_library` targets and use
`console_scripts` attribute to specify entry points than to package
`py_binary` rules. `py_binary` targets would wrap a executable script that
tries to locate `.runfiles` directory which is not packaged in the wheel.
""",
),
# Implementation details.
Expand Down
8 changes: 5 additions & 3 deletions internal_deps.bzl
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
"""Dependencies that are needed for rules_python tests and tools."""

load("@bazel_federation//:repositories.bzl", "bazel_stardoc", "rules_pkg")
load("@bazel_federation//:third_party_repositories.bzl", "futures_2_whl", "futures_3_whl", "google_cloud_language_whl", "grpc_whl", "mock_whl", "subpar")
load("@rules_python//python:pip.bzl", "pip_import")


def rules_python_internal_deps():
"""Fetches all required dependencies for rules_python tests and tools."""
bazel_stardoc()

subpar()
Expand All @@ -21,15 +23,15 @@ def rules_python_internal_deps():
# For packaging and distribution
rules_pkg()


def piptool():
"""Fetches all required dependencies for pip."""
pip_import(
name = "piptool_deps",
requirements = "@rules_python//python:requirements.txt",
)


def examples():
"""Fetches all required dependencies for rules_python examples."""
pip_import(
name = "examples_helloworld",
requirements = "@rules_python//examples/helloworld:requirements.txt",
Expand Down
Loading