From 0903d492668536e85b6a19d02aff8775d6030646 Mon Sep 17 00:00:00 2001 From: UebelAndre Date: Sun, 5 Sep 2021 17:28:30 -0700 Subject: [PATCH 1/6] Updated min tested Bazel version to 4.0.0 --- .bazelversion | 2 +- version.bzl | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.bazelversion b/.bazelversion index bea438e9ad..fcdb2e109f 100644 --- a/.bazelversion +++ b/.bazelversion @@ -1 +1 @@ -3.3.1 +4.0.0 diff --git a/version.bzl b/version.bzl index f63feab732..37f458a3e3 100644 --- a/version.bzl +++ b/version.bzl @@ -20,7 +20,7 @@ version = "0.4.0" # This version should be updated together with the version of the Bazel # in .bazelversion. # TODO(alexeagle): assert this is the case in a test -BAZEL_VERSION = "3.3.1" +BAZEL_VERSION = "4.0.0" # Versions of Bazel which users should be able to use. # Ensures we don't break backwards-compatibility, From 7c936b74938fec2fed98da05bb0f1fb9402390a6 Mon Sep 17 00:00:00 2001 From: Alex Eagle Date: Wed, 15 Sep 2021 20:30:05 -0700 Subject: [PATCH 2/6] feat: assert that Bazel is at least 4.0.0 LTS Since we only test against bazel 4.0 now, and will start using features that require it, this gives users an obvious error message that they need to update. --- .gitignore | 10 +- docs/BUILD | 1 + python/pip_install/repositories.bzl | 10 ++ .../bazelbuild/bazel-skylib/README.md | 4 + .../bazelbuild/bazel-skylib/lib/BUILD.bazel | 16 +++ .../bazelbuild/bazel-skylib/lib/versions.bzl | 128 ++++++++++++++++++ 6 files changed, 164 insertions(+), 5 deletions(-) create mode 100644 third_party/github.com/bazelbuild/bazel-skylib/README.md create mode 100644 third_party/github.com/bazelbuild/bazel-skylib/lib/BUILD.bazel create mode 100644 third_party/github.com/bazelbuild/bazel-skylib/lib/versions.bzl diff --git a/.gitignore b/.gitignore index cc8decd9a1..e3bb55e078 100644 --- a/.gitignore +++ b/.gitignore @@ -32,11 +32,11 @@ *~ # Bazel directories -bazel-* -bazel-bin -bazel-genfiles -bazel-out -bazel-testlogs +/bazel-* +/bazel-bin +/bazel-genfiles +/bazel-out +/bazel-testlogs # vim swap files *.swp diff --git a/docs/BUILD b/docs/BUILD index c02a6505d4..9552e4304d 100644 --- a/docs/BUILD +++ b/docs/BUILD @@ -80,6 +80,7 @@ stardoc( deps = [ ":bazel_repo_tools", ":pip_install_bzl", + "//third_party/github.com/bazelbuild/bazel-skylib/lib:versions", ], ) diff --git a/python/pip_install/repositories.bzl b/python/pip_install/repositories.bzl index 5c6675268a..a2ed84d9e8 100644 --- a/python/pip_install/repositories.bzl +++ b/python/pip_install/repositories.bzl @@ -3,6 +3,9 @@ load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe") +# Avoid a load from @bazel_skylib repository as users don't necessarily have it installed +load("//third_party/github.com/bazelbuild/bazel-skylib/lib:versions.bzl", "versions") + _RULE_DEPS = [ ( "pypi__click", @@ -63,6 +66,13 @@ def pip_install_dependencies(): (However we call it from pip_install, making it optional for users to do so.) """ + + # We only support Bazel LTS and rolling releases. + # Give the user an obvious error to upgrade rather than some obscure missing symbol later. + # It's not guaranteed that users call this function, but it's used by all the pip fetch + # repository rules so it's likely that most users get the right error. + versions.check("4.0.0") + for (name, url, sha256) in _RULE_DEPS: maybe( http_archive, diff --git a/third_party/github.com/bazelbuild/bazel-skylib/README.md b/third_party/github.com/bazelbuild/bazel-skylib/README.md new file mode 100644 index 0000000000..5ed93ff6d1 --- /dev/null +++ b/third_party/github.com/bazelbuild/bazel-skylib/README.md @@ -0,0 +1,4 @@ +# vendored copy of skylib + +This exists so that users of rules_python don't have to install bazel-skylib +copied from https://github.com/bazelbuild/bazel-skylib/blob/1.0.3 \ No newline at end of file diff --git a/third_party/github.com/bazelbuild/bazel-skylib/lib/BUILD.bazel b/third_party/github.com/bazelbuild/bazel-skylib/lib/BUILD.bazel new file mode 100644 index 0000000000..7b5254414e --- /dev/null +++ b/third_party/github.com/bazelbuild/bazel-skylib/lib/BUILD.bazel @@ -0,0 +1,16 @@ +load("@bazel_skylib//:bzl_library.bzl", "bzl_library") + +licenses(["notice"]) + +package(default_visibility = ["//visibility:public"]) + +# export bzl files for the documentation +exports_files( + glob(["*.bzl"]), + visibility = ["//:__subpackages__"], +) + +bzl_library( + name = "versions", + srcs = ["versions.bzl"], +) diff --git a/third_party/github.com/bazelbuild/bazel-skylib/lib/versions.bzl b/third_party/github.com/bazelbuild/bazel-skylib/lib/versions.bzl new file mode 100644 index 0000000000..0209a6fae6 --- /dev/null +++ b/third_party/github.com/bazelbuild/bazel-skylib/lib/versions.bzl @@ -0,0 +1,128 @@ +# Copyright 2018 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""Skylib module containing functions for checking Bazel versions.""" + +def _get_bazel_version(): + """Returns the current Bazel version""" + + return native.bazel_version + +def _extract_version_number(bazel_version): + """Extracts the semantic version number from a version string + + Args: + bazel_version: the version string that begins with the semantic version + e.g. "1.2.3rc1 abc1234" where "abc1234" is a commit hash. + + Returns: + The semantic version string, like "1.2.3". + """ + for i in range(len(bazel_version)): + c = bazel_version[i] + if not (c.isdigit() or c == "."): + return bazel_version[:i] + return bazel_version + +# Parse the bazel version string from `native.bazel_version`. +# e.g. +# "0.10.0rc1 abc123d" => (0, 10, 0) +# "0.3.0" => (0, 3, 0) +def _parse_bazel_version(bazel_version): + """Parses a version string into a 3-tuple of ints + + int tuples can be compared directly using binary operators (<, >). + + Args: + bazel_version: the Bazel version string + + Returns: + An int 3-tuple of a (major, minor, patch) version. + """ + + version = _extract_version_number(bazel_version) + return tuple([int(n) for n in version.split(".")]) + +def _is_at_most(threshold, version): + """Check that a version is lower or equals to a threshold. + + Args: + threshold: the maximum version string + version: the version string to be compared to the threshold + + Returns: + True if version <= threshold. + """ + return _parse_bazel_version(version) <= _parse_bazel_version(threshold) + +def _is_at_least(threshold, version): + """Check that a version is higher or equals to a threshold. + + Args: + threshold: the minimum version string + version: the version string to be compared to the threshold + + Returns: + True if version >= threshold. + """ + + return _parse_bazel_version(version) >= _parse_bazel_version(threshold) + +def _check_bazel_version(minimum_bazel_version, maximum_bazel_version = None, bazel_version = None): + """Check that the version of Bazel is valid within the specified range. + + Args: + minimum_bazel_version: minimum version of Bazel expected + maximum_bazel_version: maximum version of Bazel expected + bazel_version: the version of Bazel to check. Used for testing, defaults to native.bazel_version + """ + if not bazel_version: + if "bazel_version" not in dir(native): + fail("Current Bazel version is lower than 0.2.1; expected at least {}".format( + minimum_bazel_version, + )) + elif not native.bazel_version: + # Using a non-release version, assume it is good. + return + else: + bazel_version = native.bazel_version + + if not _is_at_least( + threshold = minimum_bazel_version, + version = bazel_version, + ): + fail("Current Bazel version is {}; expected at least {}".format( + bazel_version, + minimum_bazel_version, + )) + + if maximum_bazel_version: + if not _is_at_most( + threshold = maximum_bazel_version, + version = bazel_version, + ): + fail("Current Bazel version is {}; expected at most {}".format( + bazel_version, + maximum_bazel_version, + )) + + pass + +versions = struct( + get = _get_bazel_version, + parse = _parse_bazel_version, + check = _check_bazel_version, + is_at_most = _is_at_most, + is_at_least = _is_at_least, +) From 26261183c007840b2abe53ad2d3ef807dce2bcd2 Mon Sep 17 00:00:00 2001 From: Henry Fuller Date: Sat, 18 Sep 2021 12:47:39 -0700 Subject: [PATCH 3/6] Add third_party bzl files to integration test rules_python distro --- BUILD | 1 + examples/legacy_pip_import/helloworld/BUILD | 1 - .../bazelbuild/bazel-skylib/lib/{BUILD.bazel => BUILD} | 9 ++++----- 3 files changed, 5 insertions(+), 6 deletions(-) rename third_party/github.com/bazelbuild/bazel-skylib/lib/{BUILD.bazel => BUILD} (62%) diff --git a/BUILD b/BUILD index ad7569b447..4108672ca7 100644 --- a/BUILD +++ b/BUILD @@ -30,6 +30,7 @@ filegroup( "//python:distribution", "//python/pip_install:distribution", "//tools:distribution", + "//third_party/github.com/bazelbuild/bazel-skylib/lib:distribution" ], visibility = ["//distro:__pkg__"], ) diff --git a/examples/legacy_pip_import/helloworld/BUILD b/examples/legacy_pip_import/helloworld/BUILD index e9f259c48f..426213495e 100644 --- a/examples/legacy_pip_import/helloworld/BUILD +++ b/examples/legacy_pip_import/helloworld/BUILD @@ -28,6 +28,5 @@ py_library( py_test( name = "helloworld_test", srcs = ["helloworld_test.py"], - python_version = "PY2", deps = [":helloworld"], ) diff --git a/third_party/github.com/bazelbuild/bazel-skylib/lib/BUILD.bazel b/third_party/github.com/bazelbuild/bazel-skylib/lib/BUILD similarity index 62% rename from third_party/github.com/bazelbuild/bazel-skylib/lib/BUILD.bazel rename to third_party/github.com/bazelbuild/bazel-skylib/lib/BUILD index 7b5254414e..04bc96d6f1 100644 --- a/third_party/github.com/bazelbuild/bazel-skylib/lib/BUILD.bazel +++ b/third_party/github.com/bazelbuild/bazel-skylib/lib/BUILD @@ -1,5 +1,3 @@ -load("@bazel_skylib//:bzl_library.bzl", "bzl_library") - licenses(["notice"]) package(default_visibility = ["//visibility:public"]) @@ -10,7 +8,8 @@ exports_files( visibility = ["//:__subpackages__"], ) -bzl_library( - name = "versions", - srcs = ["versions.bzl"], +filegroup( + name = "distribution", + srcs = glob(["**"]), + visibility = ["//:__pkg__"], ) From 155d024591d3e72e90a95161c9a037fd0e508639 Mon Sep 17 00:00:00 2001 From: Henry Fuller Date: Sat, 18 Sep 2021 13:03:46 -0700 Subject: [PATCH 4/6] fix docs by adding bzl_library back to vendored skylib --- BUILD | 2 +- third_party/github.com/bazelbuild/bazel-skylib/lib/BUILD | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/BUILD b/BUILD index 4108672ca7..7b50303ab6 100644 --- a/BUILD +++ b/BUILD @@ -30,7 +30,7 @@ filegroup( "//python:distribution", "//python/pip_install:distribution", "//tools:distribution", - "//third_party/github.com/bazelbuild/bazel-skylib/lib:distribution" + "//third_party/github.com/bazelbuild/bazel-skylib/lib:distribution", ], visibility = ["//distro:__pkg__"], ) diff --git a/third_party/github.com/bazelbuild/bazel-skylib/lib/BUILD b/third_party/github.com/bazelbuild/bazel-skylib/lib/BUILD index 04bc96d6f1..9560aed406 100644 --- a/third_party/github.com/bazelbuild/bazel-skylib/lib/BUILD +++ b/third_party/github.com/bazelbuild/bazel-skylib/lib/BUILD @@ -1,3 +1,5 @@ +load("@bazel_skylib//:bzl_library.bzl", "bzl_library") + licenses(["notice"]) package(default_visibility = ["//visibility:public"]) @@ -13,3 +15,8 @@ filegroup( srcs = glob(["**"]), visibility = ["//:__pkg__"], ) + +bzl_library( + name = "versions", + srcs = ["versions.bzl"], +) From 05d445d8395929cb507922675e0c87a0db51305f Mon Sep 17 00:00:00 2001 From: Henry Fuller Date: Sat, 18 Sep 2021 13:08:49 -0700 Subject: [PATCH 5/6] re-buildifier --- BUILD | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BUILD b/BUILD index 7b50303ab6..f548715ba6 100644 --- a/BUILD +++ b/BUILD @@ -29,8 +29,8 @@ filegroup( "internal_setup.bzl", "//python:distribution", "//python/pip_install:distribution", - "//tools:distribution", "//third_party/github.com/bazelbuild/bazel-skylib/lib:distribution", + "//tools:distribution", ], visibility = ["//distro:__pkg__"], ) From 96a71cd5da1a1602b6835a761e93a5c86fcc1fa8 Mon Sep 17 00:00:00 2001 From: Henry Fuller Date: Mon, 27 Sep 2021 19:22:40 -0700 Subject: [PATCH 6/6] remove helloworld test that relies on python2 --- examples/legacy_pip_import/WORKSPACE | 9 ----- examples/legacy_pip_import/helloworld/BUILD | 32 --------------- .../helloworld/helloworld.py | 29 -------------- .../helloworld/helloworld_test.py | 40 ------------------- .../helloworld/requirements.txt | 1 - 5 files changed, 111 deletions(-) delete mode 100644 examples/legacy_pip_import/helloworld/BUILD delete mode 100644 examples/legacy_pip_import/helloworld/helloworld.py delete mode 100644 examples/legacy_pip_import/helloworld/helloworld_test.py delete mode 100644 examples/legacy_pip_import/helloworld/requirements.txt diff --git a/examples/legacy_pip_import/WORKSPACE b/examples/legacy_pip_import/WORKSPACE index bd540c3903..6777fb775f 100644 --- a/examples/legacy_pip_import/WORKSPACE +++ b/examples/legacy_pip_import/WORKSPACE @@ -12,15 +12,6 @@ load("@rules_python//python/legacy_pip_import:pip.bzl", "pip_import", "pip_repos pip_repositories() -pip_import( - name = "helloworld_deps", - requirements = "//helloworld:requirements.txt", -) - -load("@helloworld_deps//:requirements.bzl", _helloworld_install = "pip_install") - -_helloworld_install() - pip_import( name = "boto_deps", requirements = "//boto:requirements.txt", diff --git a/examples/legacy_pip_import/helloworld/BUILD b/examples/legacy_pip_import/helloworld/BUILD deleted file mode 100644 index 426213495e..0000000000 --- a/examples/legacy_pip_import/helloworld/BUILD +++ /dev/null @@ -1,32 +0,0 @@ -# Copyright 2017 The Bazel Authors. All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -load("@helloworld_deps//:requirements.bzl", "requirement") -load("@rules_python//python:defs.bzl", "py_library", "py_test") - -package(default_visibility = ["//visibility:public"]) - -licenses(["notice"]) # Apache 2.0 - -py_library( - name = "helloworld", - srcs = ["helloworld.py"], - deps = [requirement("futures")], -) - -py_test( - name = "helloworld_test", - srcs = ["helloworld_test.py"], - deps = [":helloworld"], -) diff --git a/examples/legacy_pip_import/helloworld/helloworld.py b/examples/legacy_pip_import/helloworld/helloworld.py deleted file mode 100644 index b629e80f28..0000000000 --- a/examples/legacy_pip_import/helloworld/helloworld.py +++ /dev/null @@ -1,29 +0,0 @@ -# Copyright 2017 The Bazel Authors. All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -from concurrent import futures - - -class HelloWorld(object): - def __init__(self): - self._threadpool = futures.ThreadPoolExecutor(max_workers=5) - - def SayHello(self): - print("Hello World") - - def SayHelloAsync(self): - self._threadpool.submit(self.SayHello) - - def Stop(self): - self._threadpool.shutdown(wait = True) diff --git a/examples/legacy_pip_import/helloworld/helloworld_test.py b/examples/legacy_pip_import/helloworld/helloworld_test.py deleted file mode 100644 index da6ac77a03..0000000000 --- a/examples/legacy_pip_import/helloworld/helloworld_test.py +++ /dev/null @@ -1,40 +0,0 @@ -# Copyright 2017 The Bazel Authors. All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import helloworld -import unittest - - -class HelloWorldTest(unittest.TestCase): - - def test_helloworld(self): - hw = helloworld.HelloWorld() - hw.SayHello() - - def test_helloworld_async(self): - hw = helloworld.HelloWorld() - hw.SayHelloAsync() - hw.Stop() - - def test_helloworld_multiple(self): - hw = helloworld.HelloWorld() - hw.SayHelloAsync() - hw.SayHelloAsync() - hw.SayHelloAsync() - hw.SayHelloAsync() - hw.Stop() - - -if __name__ == '__main__': - unittest.main() diff --git a/examples/legacy_pip_import/helloworld/requirements.txt b/examples/legacy_pip_import/helloworld/requirements.txt deleted file mode 100644 index 372420dc2a..0000000000 --- a/examples/legacy_pip_import/helloworld/requirements.txt +++ /dev/null @@ -1 +0,0 @@ -futures>=3.1