Skip to content

Commit

Permalink
build: add support for pip3_import from rules_python.
Browse files Browse the repository at this point in the history
Provide an Envoy build system styled way of loading arbitrary pip3
packages as py_{library,binary} dependencies.

Part of envoyproxy#11085 (to fetch
PyYAML).

Risk level: Low (build system)
Testing: Manual validation that the test utility loads PyYAML at the
  correct version (different to my system version).

Signed-off-by: Harvey Tuch <[email protected]>
  • Loading branch information
htuch committed May 7, 2020
1 parent 10e7c9d commit bda0b62
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 4 deletions.
4 changes: 4 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ load("//bazel:repositories.bzl", "envoy_dependencies")

envoy_dependencies()

load("//bazel:repositories_extra.bzl", "envoy_dependencies_extra")

envoy_dependencies_extra()

load("//bazel:dependency_imports.bzl", "envoy_dependency_imports")

envoy_dependency_imports()
3 changes: 3 additions & 0 deletions bazel/dependency_imports.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ load("@envoy_build_tools//toolchains:rbe_toolchains_config.bzl", "rbe_toolchains
load("@bazel_gazelle//:deps.bzl", "gazelle_dependencies", "go_repository")
load("@build_bazel_rules_apple//apple:repositories.bzl", "apple_rules_dependencies")
load("@upb//bazel:repository_defs.bzl", upb_bazel_version_repository = "bazel_version_repository")
load("@config_validation//:requirements.bzl", config_validation_pip_install = "pip_install")

# go version for rules_go
GO_VERSION = "1.13.5"
Expand Down Expand Up @@ -38,3 +39,5 @@ def envoy_dependency_imports(go_version = GO_VERSION):
sum = "h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=",
version = "v0.3.0",
)

config_validation_pip_install()
4 changes: 2 additions & 2 deletions bazel/repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ _default_envoy_build_config = repository_rule(
},
)

# Python dependencies. If these become non-trivial, we might be better off using a virtualenv to
# wrap them, but for now we can treat them as first-class Bazel.
# Python dependencies.
def _python_deps():
# TODO(htuch): convert these to pip3_import.
_repository_impl(
name = "com_github_pallets_markupsafe",
build_file = "@envoy//bazel/external:markupsafe.BUILD",
Expand Down
16 changes: 16 additions & 0 deletions bazel/repositories_extra.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
load("@rules_python//python:repositories.bzl", "py_repositories")
load("@rules_python//python:pip.bzl", "pip3_import", "pip_repositories")

# Python dependencies.
def _python_deps():
py_repositories()
pip_repositories()

pip3_import(
name = "config_validation",
requirements = "//tools/config_validation:requirements.txt",
)

# Envoy deps that rely on a first stage of dependency loading in envoy_dependencies().
def envoy_dependencies_extra():
_python_deps()
7 changes: 5 additions & 2 deletions bazel/repository_locations.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -365,8 +365,11 @@ DEPENDENCY_REPOSITORIES = dict(
use_category = ["build"],
),
rules_python = dict(
sha256 = "aa96a691d3a8177f3215b14b0edc9641787abaaa30363a080165d06ab65e1161",
urls = ["https://github.com/bazelbuild/rules_python/releases/download/0.0.1/rules_python-0.0.1.tar.gz"],
sha256 = "76a8fd4e7eca2a3590f816958faa0d83c9b2ce9c32634c5c375bcccf161d3bb5",
strip_prefix = "rules_python-a0fbf98d4e3a232144df4d0d80b577c7a693b570",
# 2020-04-09
# TODO(htuch): revert back to a point releases when pip3_import appears.
urls = ["https://github.com/bazelbuild/rules_python/archive/a0fbf98d4e3a232144df4d0d80b577c7a693b570.tar.gz"],
use_category = ["build"],
),
six = dict(
Expand Down
10 changes: 10 additions & 0 deletions tools/config_validation/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
licenses(["notice"]) # Apache 2

load("@config_validation//:requirements.bzl", "requirement")

py_binary(
name = "validate_yaml_fragment",
srcs = ["validate_yaml_fragment.py"],
visibility = ["//visibility:public"],
deps = [requirement("PyYAML")],
)
1 change: 1 addition & 0 deletions tools/config_validation/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
PyYAML==5.3.1
3 changes: 3 additions & 0 deletions tools/config_validation/validate_yaml_fragment.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import yaml

print('YAML version is %s' % yaml.__version__)

0 comments on commit bda0b62

Please sign in to comment.