Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion .bazelversion
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.3.1
4.0.0
10 changes: 5 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ filegroup(
"internal_setup.bzl",
"//python:distribution",
"//python/pip_install:distribution",
"//third_party/github.com/bazelbuild/bazel-skylib/lib:distribution",
"//tools:distribution",
],
visibility = ["//distro:__pkg__"],
Expand Down
1 change: 1 addition & 0 deletions docs/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ stardoc(
deps = [
":bazel_repo_tools",
":pip_install_bzl",
"//third_party/github.com/bazelbuild/bazel-skylib/lib:versions",
],
)

Expand Down
9 changes: 0 additions & 9 deletions examples/legacy_pip_import/WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
33 changes: 0 additions & 33 deletions examples/legacy_pip_import/helloworld/BUILD

This file was deleted.

29 changes: 0 additions & 29 deletions examples/legacy_pip_import/helloworld/helloworld.py

This file was deleted.

40 changes: 0 additions & 40 deletions examples/legacy_pip_import/helloworld/helloworld_test.py

This file was deleted.

1 change: 0 additions & 1 deletion examples/legacy_pip_import/helloworld/requirements.txt

This file was deleted.

10 changes: 10 additions & 0 deletions python/pip_install/repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for fixing it!

load("//third_party/github.com/bazelbuild/bazel-skylib/lib:versions.bzl", "versions")

_RULE_DEPS = [
(
"pypi__click",
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 4 additions & 0 deletions third_party/github.com/bazelbuild/bazel-skylib/README.md
Original file line number Diff line number Diff line change
@@ -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
22 changes: 22 additions & 0 deletions third_party/github.com/bazelbuild/bazel-skylib/lib/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
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__"],
)

filegroup(
name = "distribution",
srcs = glob(["**"]),
visibility = ["//:__pkg__"],
)

bzl_library(
name = "versions",
srcs = ["versions.bzl"],
)
128 changes: 128 additions & 0 deletions third_party/github.com/bazelbuild/bazel-skylib/lib/versions.bzl
Original file line number Diff line number Diff line change
@@ -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,
)
2 changes: 1 addition & 1 deletion version.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down