From f03259c3306ba94a71c2e53c47a2fa00d2342049 Mon Sep 17 00:00:00 2001 From: Ryan Northey Date: Thu, 9 Sep 2021 16:38:33 +0100 Subject: [PATCH] bazel: Switch `py_script` -> `rules_python.entry_point` Signed-off-by: Ryan Northey --- tools/base/BUILD | 4 --- tools/base/base_command.py | 13 --------- tools/base/envoy_python.bzl | 55 ------------------------------------- tools/distribution/BUILD | 39 +++++++++++++------------- 4 files changed, 19 insertions(+), 92 deletions(-) delete mode 100644 tools/base/base_command.py diff --git a/tools/base/BUILD b/tools/base/BUILD index 8de9977da9dcd..c1d243c119ed7 100644 --- a/tools/base/BUILD +++ b/tools/base/BUILD @@ -6,10 +6,6 @@ licenses(["notice"]) # Apache 2 envoy_package() -exports_files([ - "base_command.py", -]) - envoy_py_library( "tools.base.aio", deps = [ diff --git a/tools/base/base_command.py b/tools/base/base_command.py deleted file mode 100644 index 41cd5675da16f..0000000000000 --- a/tools/base/base_command.py +++ /dev/null @@ -1,13 +0,0 @@ -#!/usr/bin/env python3 - -import sys - -from __UPSTREAM_PACKAGE__ import main as upstream_main - - -def main(*args: str) -> int: - return upstream_main(*args) - - -if __name__ == "__main__": - sys.exit(main(*sys.argv[1:])) diff --git a/tools/base/envoy_python.bzl b/tools/base/envoy_python.bzl index 3af2b50323834..550ff901768de 100644 --- a/tools/base/envoy_python.bzl +++ b/tools/base/envoy_python.bzl @@ -71,58 +71,3 @@ def envoy_py_binary( if test: envoy_py_test(name, package, visibility, envoy_prefix = envoy_prefix) - -def envoy_py_script( - name, - entry_point, - deps = [], - data = [], - visibility = ["//visibility:public"], - envoy_prefix = "@envoy"): - """This generates a `py_binary` from an entry_point in a python package - - Currently, the actual entrypoint callable is hard-coded to `main`. - - For example, if you wish to make use of a `console_script` in an upstream - package that resolves as `envoy.code_format.python.command.main` from a - package named `envoy.code_format.python`, you can use this macro as - follows: - - ```skylark - - envoy_py_script( - name = "tools.code_format.python", - entry_point = "envoy.code_format.python.command", - deps = [requirement("envoy.code_format.python")], - ``` - - You will then be able to use the console script from bazel. - - Separate args to be passed to the console_script with `--`, eg: - - ```console - - $ bazel run //tools/code_format:python -- -h - ``` - - """ - py_file = "%s.py" % name.split(".")[-1] - output = "$(@D)/%s" % py_file - template_rule = "%s//tools/base:base_command.py" % envoy_prefix - template = "$(location %s)" % template_rule - - native.genrule( - name = "py_script_%s" % py_file, - cmd = "sed s/__UPSTREAM_PACKAGE__/%s/ %s > \"%s\"" % (entry_point, template, output), - tools = [template_rule], - outs = [py_file], - ) - - envoy_py_binary( - name = name, - deps = deps, - data = data, - visibility = visibility, - envoy_prefix = envoy_prefix, - test = False, - ) diff --git a/tools/distribution/BUILD b/tools/distribution/BUILD index 6b60dda875708..e00e257bdc4ea 100644 --- a/tools/distribution/BUILD +++ b/tools/distribution/BUILD @@ -1,6 +1,5 @@ load("//bazel:envoy_build_system.bzl", "envoy_package") -load("//tools/base:envoy_python.bzl", "envoy_py_script") -load("@base_pip3//:requirements.bzl", "requirement") +load("@base_pip3//:requirements.bzl", "entry_point") licenses(["notice"]) # Apache 2 @@ -10,26 +9,26 @@ exports_files([ "distrotest.sh", ]) -envoy_py_script( - name = "tools.distribution.release", - entry_point = "envoy.distribution.release", - deps = [ - requirement("envoy.distribution.release"), - ], +alias( + name = "release", + actual = entry_point( + pkg = "envoy.distribution.release", + script = "envoy.distribution.release", + ), ) -envoy_py_script( - name = "tools.distribution.sign", - entry_point = "envoy.gpg.sign", - deps = [ - requirement("envoy.gpg.sign"), - ], +alias( + name = "sign", + actual = entry_point( + pkg = "envoy.gpg.sign", + script = "envoy.gpg.sign", + ), ) -envoy_py_script( - name = "tools.distribution.verify", - entry_point = "envoy.distribution.verify", - deps = [ - requirement("envoy.distribution.verify"), - ], +alias( + name = "verify", + actual = entry_point( + pkg = "envoy.distribution.verify", + script = "envoy.distribution.verify", + ), )