Skip to content

Commit c6f5efc

Browse files
committed
fixup the cleanup that I thought I could do after bazel-contrib#1987
1 parent 0e038da commit c6f5efc

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

python/private/pypi/whl_library.bzl

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ load(":whl_target_platforms.bzl", "whl_target_platforms")
2929

3030
_CPPFLAGS = "CPPFLAGS"
3131
_COMMAND_LINE_TOOLS_PATH_SLUG = "commandlinetools"
32+
_WHEEL_ENTRY_POINT_PREFIX = "rules_python_wheel_entry_point"
3233

3334
def _construct_pypath(rctx):
3435
"""Helper function to construct a PYTHONPATH.
@@ -349,6 +350,30 @@ def _whl_library_impl(rctx):
349350
metadata = json.decode(rctx.read("metadata.json"))
350351
rctx.delete("metadata.json")
351352

353+
# NOTE @aignas 2024-06-22: this has to live on until we stop supporting
354+
# passing `twine` as a `:pkg` library via the `WORKSPACE` builds.
355+
#
356+
# See ../../packaging.bzl line 190
357+
entry_points = {}
358+
for item in metadata["entry_points"]:
359+
name = item["name"]
360+
module = item["module"]
361+
attribute = item["attribute"]
362+
363+
# There is an extreme edge-case with entry_points that end with `.py`
364+
# See: https://github.com/bazelbuild/bazel/blob/09c621e4cf5b968f4c6cdf905ab142d5961f9ddc/src/test/java/com/google/devtools/build/lib/rules/python/PyBinaryConfiguredTargetTest.java#L174
365+
entry_point_without_py = name[:-3] + "_py" if name.endswith(".py") else name
366+
entry_point_target_name = (
367+
_WHEEL_ENTRY_POINT_PREFIX + "_" + entry_point_without_py
368+
)
369+
entry_point_script_name = entry_point_target_name + ".py"
370+
371+
rctx.file(
372+
entry_point_script_name,
373+
_generate_entry_point_contents(module, attribute),
374+
)
375+
entry_points[entry_point_without_py] = entry_point_script_name
376+
352377
build_file_contents = generate_whl_library_build_bazel(
353378
dep_template = rctx.attr.dep_template or "@{}{{name}}//:{{target}}".format(rctx.attr.repo_prefix),
354379
whl_name = whl_path.basename,

0 commit comments

Comments
 (0)