Added targets for data and dist-info to pip generated targets (#519)
diff --git a/python/pip_install/extract_wheels/lib/bazel.py b/python/pip_install/extract_wheels/lib/bazel.py index ca1a8bb..0dbc560 100644 --- a/python/pip_install/extract_wheels/lib/bazel.py +++ b/python/pip_install/extract_wheels/lib/bazel.py
@@ -10,6 +10,8 @@ WHEEL_FILE_LABEL = "whl" PY_LIBRARY_LABEL = "pkg" +DATA_LABEL = "data" +DIST_INFO_LABEL = "dist_info" def generate_build_file_contents( @@ -33,14 +35,24 @@ return textwrap.dedent( """\ + load("@rules_python//python:defs.bzl", "py_library") + package(default_visibility = ["//visibility:public"]) - load("@rules_python//python:defs.bzl", "py_library") + filegroup( + name = "{dist_info_label}", + srcs = glob(["*.dist-info/**"], allow_empty = True), + ) filegroup( - name="{whl_file_label}", - srcs=glob(["*.whl"], allow_empty = True), - data=[{whl_file_deps}] + name = "{data_label}", + srcs = glob(["*.data/**"], allow_empty = True), + ) + + filegroup( + name = "{whl_file_label}", + srcs = glob(["*.whl"], allow_empty = True), + data = [{whl_file_deps}], ) py_library( @@ -58,6 +70,8 @@ data_exclude=json.dumps(data_exclude), whl_file_label=WHEEL_FILE_LABEL, whl_file_deps=",".join(whl_file_deps), + data_label=DATA_LABEL, + dist_info_label=DIST_INFO_LABEL, ) ) @@ -92,7 +106,13 @@ return "{repo}//pypi__" + name_key def whl_requirement(name): - return requirement(name) + ":whl" + return requirement(name) + ":{whl_file_label}" + + def data_requirement(name): + return requirement(name) + ":{data_label}" + + def dist_info_requirement(name): + return requirement(name) + ":{dist_info_label}" def install_deps(): fail("install_deps() only works if you are creating an incremental repo. Did you mean to use pip_parse()?") @@ -100,6 +120,9 @@ repo=repo_name, requirement_labels=requirement_labels, whl_requirement_labels=whl_requirement_labels, + whl_file_label=WHEEL_FILE_LABEL, + data_label=DATA_LABEL, + dist_info_label=DIST_INFO_LABEL, ) )
diff --git a/python/pip_install/parse_requirements_to_bzl/__init__.py b/python/pip_install/parse_requirements_to_bzl/__init__.py index f27e2a2..a77dd85 100644 --- a/python/pip_install/parse_requirements_to_bzl/__init__.py +++ b/python/pip_install/parse_requirements_to_bzl/__init__.py
@@ -84,10 +84,16 @@ return name.replace("-", "_").replace(".", "_").lower() def requirement(name): - return "@{repo_prefix}" + _clean_name(name) + "//:pkg" + return "@{repo_prefix}" + _clean_name(name) + "//:{py_library_label}" def whl_requirement(name): - return "@{repo_prefix}" + _clean_name(name) + "//:whl" + return "@{repo_prefix}" + _clean_name(name) + "//:{wheel_file_label}" + + def data_requirement(name): + return requirement(name) + ":{data_label}" + + def dist_info_requirement(name): + return requirement(name) + ":{dist_info_label}" def install_deps(): for name, requirement in _packages: @@ -102,6 +108,10 @@ repo_names_and_reqs=repo_names_and_reqs, args=args, repo_prefix=repo_prefix, + py_library_label=bazel.PY_LIBRARY_LABEL, + wheel_file_label=bazel.WHEEL_FILE_LABEL, + data_label=bazel.DATA_LABEL, + dist_info_label=bazel.DIST_INFO_LABEL, ) )