Skip to content
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
33 changes: 28 additions & 5 deletions python/pip_install/extract_wheels/lib/bazel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -33,14 +35,24 @@ def generate_build_file_contents(

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 = "{data_label}",
srcs = glob(["*.data/**"], allow_empty = True),
)

filegroup(
name="{whl_file_label}",
srcs=glob(["*.whl"], allow_empty = True),
data=[{whl_file_deps}]
name = "{whl_file_label}",
srcs = glob(["*.whl"], allow_empty = True),
data = [{whl_file_deps}],
)

py_library(
Expand All @@ -58,6 +70,8 @@ def generate_build_file_contents(
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,
)
)

Expand Down Expand Up @@ -92,14 +106,23 @@ def requirement(name):
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()?")
""".format(
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,
)
)

Expand Down
14 changes: 12 additions & 2 deletions python/pip_install/parse_requirements_to_bzl/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,16 @@ def _clean_name(name):
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:
Expand All @@ -102,6 +108,10 @@ def install_deps():
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,
)
)

Expand Down