tensorflow/third_party/py/python_init_pip.bzl
Yun Peng bfc4d2d2e4 Update pip dependency reference from @pypi_XXX//:pkg to @pypi//XXX.
The `@pypi_<name>` references are deprecated and their repo names are
an implementation detail of how an underlying library is downloaded.
The modern, supported, way is to go through the hub (`@pypi`). This
also makes the code compatible with both workspace and bzlmod.

PiperOrigin-RevId: 812915387
2025-09-29 13:31:45 -07:00

43 lines
1.3 KiB
Python

"""Hermetic Python initialization. Consult the WORKSPACE on how to use it."""
load("@python_version_repo//:py_version.bzl", "REQUIREMENTS_WITH_LOCAL_WHEELS")
load("@rules_python//python:pip.bzl", "package_annotation", "pip_parse")
load(
"//third_party/py:python_init_toolchains.bzl",
"get_toolchain_name_per_python_version",
)
def python_init_pip():
numpy_annotations = {
"numpy": package_annotation(
additive_build_content = """\
cc_library(
name = "numpy_headers_2",
hdrs = glob(["site-packages/numpy/_core/include/**/*.h"]),
strip_include_prefix="site-packages/numpy/_core/include/",
)
cc_library(
name = "numpy_headers_1",
hdrs = glob(["site-packages/numpy/core/include/**/*.h"]),
strip_include_prefix="site-packages/numpy/core/include/",
)
cc_library(
name = "numpy_headers",
deps = [":numpy_headers_2", ":numpy_headers_1"],
)
""",
),
}
pip_parse(
name = "pypi",
annotations = numpy_annotations,
python_interpreter_target = "@{}_host//:python".format(
get_toolchain_name_per_python_version("python"),
),
extra_hub_aliases = {
"numpy": ["numpy_headers"],
},
requirements_lock = REQUIREMENTS_WITH_LOCAL_WHEELS,
)