From 2ceaa7b55b8bc0a2c96789c02fb9515f134a03eb Mon Sep 17 00:00:00 2001 From: xla authors Date: Fri, 15 Nov 2024 16:00:33 -0800 Subject: [PATCH] Refactor rule and flag names. PiperOrigin-RevId: 697025766 --- third_party/py/BUILD | 10 ++--- third_party/tsl/opensource_only.files | 4 +- third_party/tsl/third_party/py/BUILD | 10 ++--- ...python_wheel_library.bzl => py_import.bzl} | 16 ++++++-- ...ance.py => verify_manylinux_compliance.py} | 39 +++++++------------ 5 files changed, 39 insertions(+), 40 deletions(-) rename third_party/tsl/third_party/py/{python_wheel_library.bzl => py_import.bzl} (81%) rename third_party/tsl/third_party/py/{verify_wheel_compliance.py => verify_manylinux_compliance.py} (73%) diff --git a/third_party/py/BUILD b/third_party/py/BUILD index d93894416c402..7250861f26bfa 100644 --- a/third_party/py/BUILD +++ b/third_party/py/BUILD @@ -53,20 +53,20 @@ config_setting( }, ) -# Flag indicating if the target requires wheel compliance verification. +# Flag indicating if the target requires manylinux compliance verification. bool_flag( - name = "wheel_compliance", + name = "verify_manylinux", # TODO(ybaturina): Enable the flag by default when hermetic C++ toolchain is ready. build_setting_default = False, visibility = ["//visibility:public"], ) py_binary( - name = "verify_wheel_compliance_py", + name = "verify_manylinux_compliance", srcs = [ - "verify_wheel_compliance.py", + "verify_manylinux_compliance.py", ], - main = "verify_wheel_compliance.py", + main = "verify_manylinux_compliance.py", visibility = ["//visibility:public"], deps = [ "@pypi_auditwheel//:pkg", diff --git a/third_party/tsl/opensource_only.files b/third_party/tsl/opensource_only.files index 054cb96cb7b28..c4ca83f628cee 100644 --- a/third_party/tsl/opensource_only.files +++ b/third_party/tsl/opensource_only.files @@ -102,14 +102,14 @@ third_party/py/BUILD: third_party/py/ml_dtypes/BUILD: third_party/py/ml_dtypes/LICENSE: third_party/py/numpy/BUILD: +third_party/py/py_import.bzl: third_party/py/python_configure.bzl: third_party/py/python_init_pip.bzl: third_party/py/python_init_repositories.bzl: third_party/py/python_init_rules.bzl: third_party/py/python_init_toolchains.bzl: third_party/py/python_repo.bzl: -third_party/py/python_wheel_library.bzl: -third_party/py/verify_wheel_compliance.py: +third_party/py/verify_manylinux_compliance.py: third_party/pybind11.BUILD: third_party/pybind11_bazel/BUILD: third_party/python_runtime/BUILD: diff --git a/third_party/tsl/third_party/py/BUILD b/third_party/tsl/third_party/py/BUILD index d93894416c402..7250861f26bfa 100644 --- a/third_party/tsl/third_party/py/BUILD +++ b/third_party/tsl/third_party/py/BUILD @@ -53,20 +53,20 @@ config_setting( }, ) -# Flag indicating if the target requires wheel compliance verification. +# Flag indicating if the target requires manylinux compliance verification. bool_flag( - name = "wheel_compliance", + name = "verify_manylinux", # TODO(ybaturina): Enable the flag by default when hermetic C++ toolchain is ready. build_setting_default = False, visibility = ["//visibility:public"], ) py_binary( - name = "verify_wheel_compliance_py", + name = "verify_manylinux_compliance", srcs = [ - "verify_wheel_compliance.py", + "verify_manylinux_compliance.py", ], - main = "verify_wheel_compliance.py", + main = "verify_manylinux_compliance.py", visibility = ["//visibility:public"], deps = [ "@pypi_auditwheel//:pkg", diff --git a/third_party/tsl/third_party/py/python_wheel_library.bzl b/third_party/tsl/third_party/py/py_import.bzl similarity index 81% rename from third_party/tsl/third_party/py/python_wheel_library.bzl rename to third_party/tsl/third_party/py/py_import.bzl index ebff521625773..9918cd8f6b8aa 100644 --- a/third_party/tsl/third_party/py/python_wheel_library.bzl +++ b/third_party/tsl/third_party/py/py_import.bzl @@ -3,7 +3,7 @@ def _unpacked_wheel_impl(ctx): output_dir = ctx.actions.declare_directory(ctx.label.name) libs = [] - for dep in ctx.attr.deps: + for dep in ctx.attr.сс_deps: linker_inputs = dep[CcInfo].linking_context.linker_inputs.to_list() for linker_input in linker_inputs: if linker_input.libraries and linker_input.libraries[0].dynamic_library: @@ -45,16 +45,16 @@ _unpacked_wheel = rule( cfg = "exec", executable = True, ), - "deps": attr.label_list(providers = [CcInfo]), + "сс_deps": attr.label_list(providers = [CcInfo]), }, ) -def wheel_library(name, wheel, deps = [], wheel_deps = []): +def py_import(name, wheel, deps = [], сс_deps = []): unpacked_wheel_name = name + "_unpacked_wheel" _unpacked_wheel( name = unpacked_wheel_name, wheel_rule_outputs = wheel, - deps = wheel_deps, + deps = сс_deps, ) native.py_library( name = name, @@ -63,3 +63,11 @@ def wheel_library(name, wheel, deps = [], wheel_deps = []): deps = deps, visibility = ["//visibility:public"], ) + +"""Unpacks the wheel and uses its content as a py_library. +Args: + wheel: wheel file to unpack. + deps: dependencies of the py_library. + сс_deps: dependencies that will be copied in the folder + with the unpacked wheel content. +""" diff --git a/third_party/tsl/third_party/py/verify_wheel_compliance.py b/third_party/tsl/third_party/py/verify_manylinux_compliance.py similarity index 73% rename from third_party/tsl/third_party/py/verify_wheel_compliance.py rename to third_party/tsl/third_party/py/verify_manylinux_compliance.py index 34c3bd81fb356..c6f61ed5dbf38 100644 --- a/third_party/tsl/third_party/py/verify_wheel_compliance.py +++ b/third_party/tsl/third_party/py/verify_manylinux_compliance.py @@ -32,9 +32,9 @@ def parse_args() -> argparse.Namespace: "--compliance-tag", help="ManyLinux compliance tag", required=False ) parser.add_argument( - "--compliance-verification-log-path", - help="Path to file with compliance verification results", - required=False, + "--auditwheel-showlog-path", + help="Path to file with auditwheel show results, mandatory", + required=True, ) return parser.parse_args() @@ -67,41 +67,32 @@ def get_auditwheel_output(wheel_path: str) -> None: return stringio.getvalue() -def verify_wheel_compliance( +def verify_manylinux_compliance( auditwheel_log: str, compliance_tag: str, - verification_log_path: str, + auditwheel_show_log_path: str, ) -> None: - """Verify wheel compliance. + """Verify manylinux compliance. Args: auditwheel_log: "auditwheel show" execution results compliance_tag: manyLinux compliance tag - verification_log_path: path to file with compliance verification results + auditwheel_show_log_path: path to file with auditwheel show results Raises: RuntimeError: if the wheel is not manyLinux compliant. """ + with open(auditwheel_show_log_path, "w") as auditwheel_show_log: + auditwheel_show_log.write(auditwheel_log) + if not compliance_tag: + return regex = 'following platform tag: "{}"'.format(compliance_tag) - if re.search(regex, auditwheel_log): - with open(verification_log_path, "w") as verification_log: - verification_log.write( - "The wheel is {tag} compliant:\n{log}".format( - tag=compliance_tag, log=auditwheel_log - ) - ) - else: - with open(verification_log_path, "w") as verification_log: - verification_log.write( - "The wheel is not {tag} compliant:\n{log}".format( - tag=compliance_tag, log=auditwheel_log - ) - ) + if not re.search(regex, auditwheel_log): raise RuntimeError( ( "The wheel is not compliant with tag {tag}." + " If you want to disable this check, please provide" - + " `--@tsl//third_party/py:wheel_compliance=false`." + + " `--@tsl//third_party/py:verify_manylinux=false`." + "\n{result}" ).format(tag=compliance_tag, result=auditwheel_log) ) @@ -110,8 +101,8 @@ def verify_wheel_compliance( if __name__ == "__main__": args = parse_args() auditwheel_output = get_auditwheel_output(args.wheel_path) - verify_wheel_compliance( + verify_manylinux_compliance( auditwheel_output, args.compliance_tag, - args.compliance_verification_log_path, + args.auditwheel_show_log_path, )