Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor TF wheel build rule, common python rules and flag names. #19409

Merged
merged 1 commit into from
Nov 19, 2024
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
10 changes: 5 additions & 5 deletions third_party/py/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions third_party/tsl/opensource_only.files
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
10 changes: 5 additions & 5 deletions third_party/tsl/third_party/py/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.cc_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:
Expand Down Expand Up @@ -45,16 +45,16 @@ _unpacked_wheel = rule(
cfg = "exec",
executable = True,
),
"deps": attr.label_list(providers = [CcInfo]),
"cc_deps": attr.label_list(providers = [CcInfo]),
},
)

def wheel_library(name, wheel, deps = [], wheel_deps = []):
def py_import(name, wheel, deps = [], cc_deps = []):
unpacked_wheel_name = name + "_unpacked_wheel"
_unpacked_wheel(
name = unpacked_wheel_name,
wheel_rule_outputs = wheel,
deps = wheel_deps,
cc_deps = cc_deps,
)
native.py_library(
name = name,
Expand All @@ -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.
cc_deps: dependencies that will be copied in the folder
with the unpacked wheel content.
""" # buildifier: disable=no-effect
Original file line number Diff line number Diff line change
Expand Up @@ -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-show-log-path",
help="Path to file with auditwheel show results, mandatory",
required=True,
)
return parser.parse_args()

Expand Down Expand Up @@ -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)
)
Expand All @@ -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,
)
Loading