Skip to content

Commit d18adbb

Browse files
committed
chore(entry_point): remove all repository_rule entry_point code and docs
Fixes #3642 Stacked on #3734
1 parent deb78c3 commit d18adbb

10 files changed

Lines changed: 2 additions & 317 deletions

File tree

examples/pip_parse/BUILD.bazel

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,6 @@ py_test(
4545
deps = [":main"],
4646
)
4747

48-
# For pip dependencies which have entry points, the `entry_point` macro can be
49-
# used from the generated `pip_parse` repository to access a runnable binary.
50-
5148
py_console_script_binary(
5249
name = "yamllint",
5350
pkg = "@pypi//yamllint",

python/private/pypi/generate_whl_library_build_bazel.bzl

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ _RENDER = {
2323
"data_exclude": render.list,
2424
"dependencies": render.list,
2525
"dependencies_by_platform": lambda x: render.dict(x, value_repr = render.list),
26-
"entry_points": render.dict,
2726
"extras": render.list,
2827
"group_deps": render.list,
2928
"include": str,
@@ -100,18 +99,6 @@ def generate_whl_library_build_bazel(
10099
])
101100

102101
additional_content = []
103-
entry_points = kwargs.get("entry_points")
104-
if entry_points:
105-
entry_point_files = sorted({
106-
entry_point_script.replace("\\", "/"): True
107-
for entry_point_script in entry_points.values()
108-
}.keys())
109-
additional_content.append(
110-
"exports_files(\n" +
111-
" srcs = {},\n".format(render.list(entry_point_files)) +
112-
" visibility = [\"//visibility:public\"],\n" +
113-
")\n",
114-
)
115102
if annotation:
116103
kwargs["data"] = annotation.data
117104
kwargs["copy_files"] = annotation.copy_files

python/private/pypi/labels.bzl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,4 @@ PY_LIBRARY_PUBLIC_LABEL = "pkg"
2121
PY_LIBRARY_IMPL_LABEL = "_pkg"
2222
DATA_LABEL = "data"
2323
DIST_INFO_LABEL = "dist_info"
24-
WHEEL_ENTRY_POINT_PREFIX = "rules_python_wheel_entry_point"
2524
NODEPS_LABEL = "no_deps"

python/private/pypi/pip_repository.bzl

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -348,30 +348,6 @@ functionality for exposing [entry points][whl_ep] as `py_binary` targets as well
348348
349349
[whl_ep]: https://packaging.python.org/specifications/entry-points/
350350
351-
```starlark
352-
load("@pypi//:requirements.bzl", "entry_point")
353-
354-
alias(
355-
name = "pip-compile",
356-
actual = entry_point(
357-
pkg = "pip-tools",
358-
script = "pip-compile",
359-
),
360-
)
361-
```
362-
363-
Note that for packages whose name and script are the same, only the name of the package
364-
is needed when calling the `entry_point` macro.
365-
366-
```starlark
367-
load("@pip//:requirements.bzl", "entry_point")
368-
369-
alias(
370-
name = "flake8",
371-
actual = entry_point("flake8"),
372-
)
373-
```
374-
375351
:::{rubric} Vendoring the requirements.bzl file
376352
:heading-level: 3
377353
:::

python/private/pypi/whl_library.bzl

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

3434
_CPPFLAGS = "CPPFLAGS"
3535
_COMMAND_LINE_TOOLS_PATH_SLUG = "commandlinetools"
36-
_WHEEL_ENTRY_POINT_PREFIX = "rules_python_wheel_entry_point"
3736

3837
def _get_xcode_location_cflags(rctx, logger = None):
3938
"""Query the xcode sdk location to update cflags
@@ -443,38 +442,13 @@ def _whl_library_impl(rctx):
443442
)
444443
namespace_package_files = pypi_repo_utils.find_namespace_package_files(rctx, install_dir_path)
445444

446-
# NOTE @aignas 2024-06-22: this has to live on until we stop supporting
447-
# passing `twine` as a `:pkg` library via the `WORKSPACE` builds.
448-
#
449-
# See ../../packaging.bzl line 190
450-
entry_points = {}
451-
for item in metadata.entry_points:
452-
name = item.name
453-
module = item.module
454-
attribute = item.attribute
455-
456-
# There is an extreme edge-case with entry_points that end with `.py`
457-
# See: https://github.com/bazelbuild/bazel/blob/09c621e4cf5b968f4c6cdf905ab142d5961f9ddc/src/test/java/com/google/devtools/build/lib/rules/python/PyBinaryConfiguredTargetTest.java#L174
458-
entry_point_without_py = name[:-3] + "_py" if name.endswith(".py") else name
459-
entry_point_target_name = (
460-
_WHEEL_ENTRY_POINT_PREFIX + "_" + entry_point_without_py
461-
)
462-
entry_point_script_name = entry_point_target_name + ".py"
463-
464-
rctx.file(
465-
entry_point_script_name,
466-
_generate_entry_point_contents(module, attribute),
467-
)
468-
entry_points[entry_point_without_py] = entry_point_script_name
469-
470445
build_file_contents = generate_whl_library_build_bazel(
471446
name = whl_path.basename,
472447
sdist_filename = sdist_filename,
473448
dep_template = rctx.attr.dep_template or "@{}{{name}}//:{{target}}".format(
474449
rctx.attr.repo_prefix,
475450
),
476451
config_load = rctx.attr.config_load,
477-
entry_points = entry_points,
478452
metadata_name = metadata.name,
479453
metadata_version = metadata.version,
480454
requires_dist = metadata.requires_dist,
@@ -492,37 +466,12 @@ def _whl_library_impl(rctx):
492466
metadata = json.decode(rctx.read("metadata.json"))
493467
rctx.delete("metadata.json")
494468

495-
# NOTE @aignas 2024-06-22: this has to live on until we stop supporting
496-
# passing `twine` as a `:pkg` library via the `WORKSPACE` builds.
497-
#
498-
# See ../../packaging.bzl line 190
499-
entry_points = {}
500-
for item in metadata["entry_points"]:
501-
name = item["name"]
502-
module = item["module"]
503-
attribute = item["attribute"]
504-
505-
# There is an extreme edge-case with entry_points that end with `.py`
506-
# See: https://github.com/bazelbuild/bazel/blob/09c621e4cf5b968f4c6cdf905ab142d5961f9ddc/src/test/java/com/google/devtools/build/lib/rules/python/PyBinaryConfiguredTargetTest.java#L174
507-
entry_point_without_py = name[:-3] + "_py" if name.endswith(".py") else name
508-
entry_point_target_name = (
509-
_WHEEL_ENTRY_POINT_PREFIX + "_" + entry_point_without_py
510-
)
511-
entry_point_script_name = entry_point_target_name + ".py"
512-
513-
rctx.file(
514-
entry_point_script_name,
515-
_generate_entry_point_contents(module, attribute),
516-
)
517-
entry_points[entry_point_without_py] = entry_point_script_name
518-
519469
namespace_package_files = pypi_repo_utils.find_namespace_package_files(rctx, rctx.path("site-packages"))
520470

521471
build_file_contents = generate_whl_library_build_bazel(
522472
name = whl_path.basename,
523473
sdist_filename = sdist_filename,
524474
dep_template = rctx.attr.dep_template or "@{}{{name}}//:{{target}}".format(rctx.attr.repo_prefix),
525-
entry_points = entry_points,
526475
# TODO @aignas 2025-05-17: maybe have a build flag for this instead
527476
enable_implicit_namespace_pkgs = rctx.attr.enable_implicit_namespace_pkgs,
528477
# TODO @aignas 2025-04-14: load through the hub:
@@ -566,34 +515,6 @@ def _whl_library_impl(rctx):
566515

567516
return None
568517

569-
def _generate_entry_point_contents(
570-
module,
571-
attribute,
572-
shebang = "#!/usr/bin/env python3"):
573-
"""Generate the contents of an entry point script.
574-
575-
Args:
576-
module (str): The name of the module to use.
577-
attribute (str): The name of the attribute to call.
578-
shebang (str, optional): The shebang to use for the entry point python
579-
file.
580-
581-
Returns:
582-
str: A string of python code.
583-
"""
584-
contents = """\
585-
{shebang}
586-
import sys
587-
from {module} import {attribute}
588-
if __name__ == "__main__":
589-
sys.exit({attribute}())
590-
""".format(
591-
shebang = shebang,
592-
module = module,
593-
attribute = attribute,
594-
)
595-
return contents
596-
597518
# NOTE @aignas 2024-03-21: The usage of dict({}, **common) ensures that all args to `dict` are unique
598519
whl_library_attrs = dict({
599520
"annotation": attr.label(

python/private/pypi/whl_library_targets.bzl

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ load(
2626
"EXTRACTED_WHEEL_FILES",
2727
"PY_LIBRARY_IMPL_LABEL",
2828
"PY_LIBRARY_PUBLIC_LABEL",
29-
"WHEEL_ENTRY_POINT_PREFIX",
3029
"WHEEL_FILE_IMPL_LABEL",
3130
"WHEEL_FILE_PUBLIC_LABEL",
3231
)
@@ -120,7 +119,6 @@ def whl_library_targets(
120119
data = [],
121120
copy_files = {},
122121
copy_executables = {},
123-
entry_points = {},
124122
native = native,
125123
enable_implicit_namespace_pkgs = False,
126124
namespace_package_files = [],
@@ -165,8 +163,6 @@ def whl_library_targets(
165163
srcs_exclude: {type}`list[str]` The globs for srcs attribute exclusion
166164
in `py_library`.
167165
data: {type}`list[str]` A list of labels to include as part of the `data` attribute in `py_library`.
168-
entry_points: {type}`dict[str, str]` The mapping between the script
169-
name and the python file to use. DEPRECATED.
170166
enable_implicit_namespace_pkgs: {type}`boolean` generate __init__.py
171167
files for namespace pkgs.
172168
native: {type}`native` The native struct for overriding in tests.
@@ -237,20 +233,6 @@ def whl_library_targets(
237233
for d in dependencies_with_markers
238234
}
239235

240-
# TODO @aignas 2024-10-25: remove the entry_point generation once
241-
# `py_console_script_binary` is the only way to use entry points.
242-
for entry_point, entry_point_script_name in entry_points.items():
243-
rules.py_binary(
244-
name = "{}_{}".format(WHEEL_ENTRY_POINT_PREFIX, entry_point),
245-
# Ensure that this works on Windows as well - script may have Windows path separators.
246-
srcs = [entry_point_script_name.replace("\\", "/")],
247-
# This makes this directory a top-level in the python import
248-
# search path for anything that depends on this.
249-
imports = ["."],
250-
deps = [":" + PY_LIBRARY_PUBLIC_LABEL],
251-
visibility = ["//visibility:public"],
252-
)
253-
254236
# Ensure this list is normalized
255237
# Note: mapping used as set
256238
group_deps = {

python/private/pypi/whl_metadata.bzl

Lines changed: 2 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ _NAME = "Name: "
44
_PROVIDES_EXTRA = "Provides-Extra: "
55
_REQUIRES_DIST = "Requires-Dist: "
66
_VERSION = "Version: "
7-
_CONSOLE_SCRIPTS = "[console_scripts]"
87

98
def whl_metadata(*, install_dir, read_fn, logger):
109
"""Find and parse the METADATA file in the extracted whl contents dir.
@@ -24,13 +23,8 @@ def whl_metadata(*, install_dir, read_fn, logger):
2423
"""
2524
metadata_file = find_whl_metadata(install_dir = install_dir, logger = logger)
2625
contents = read_fn(metadata_file)
27-
entry_points_file = metadata_file.dirname.get_child("entry_points.txt")
28-
if entry_points_file.exists:
29-
entry_points_contents = read_fn(entry_points_file)
30-
else:
31-
entry_points_contents = ""
3226

33-
result = parse_whl_metadata(contents, entry_points_contents)
27+
result = parse_whl_metadata(contents)
3428

3529
if not (result.name and result.version):
3630
logger.fail("Failed to parse the wheel METADATA file:\n{}\n{}\n{}".format(
@@ -42,12 +36,11 @@ def whl_metadata(*, install_dir, read_fn, logger):
4236

4337
return result
4438

45-
def parse_whl_metadata(contents, entry_points_contents = ""):
39+
def parse_whl_metadata(contents):
4640
"""Parse .whl METADATA file
4741
4842
Args:
4943
contents: {type}`str` the contents of the file.
50-
entry_points_contents: {type}`str` the contents of the `entry_points.txt` file if it exists.
5144
5245
Returns:
5346
A struct with parsed values:
@@ -56,8 +49,6 @@ def parse_whl_metadata(contents, entry_points_contents = ""):
5649
* `requires_dist`: {type}`list[str]` the list of requirements.
5750
* `provides_extra`: {type}`list[str]` the list of extras that this package
5851
provides.
59-
* `entry_points`: {type}`list[struct]` the list of
60-
entry_point metadata.
6152
"""
6253
parsed = {
6354
"name": "",
@@ -89,7 +80,6 @@ def parse_whl_metadata(contents, entry_points_contents = ""):
8980
provides_extra = parsed["provides_extra"],
9081
requires_dist = parsed["requires_dist"],
9182
version = parsed["version"],
92-
entry_points = _parse_entry_points(entry_points_contents),
9383
)
9484

9585
def find_whl_metadata(*, install_dir, logger):
@@ -121,47 +111,3 @@ def find_whl_metadata(*, install_dir, logger):
121111
else:
122112
logger.fail("The '*.dist-info' directory could not be found in '{}'".format(install_dir.basename))
123113
return None
124-
125-
def _parse_entry_points(contents):
126-
"""parse the entry_points.txt file.
127-
128-
Args:
129-
contents: {type}`str` The contents of the file
130-
131-
Returns:
132-
A list of console_script entry point metadata.
133-
"""
134-
start = False
135-
ret = []
136-
for line in contents.split("\n"):
137-
line = line.rstrip()
138-
139-
if line == _CONSOLE_SCRIPTS:
140-
start = True
141-
continue
142-
143-
if not start:
144-
continue
145-
146-
if start and line.startswith("["):
147-
break
148-
149-
line, _, _comment = line.partition("#")
150-
line = line.strip()
151-
if not line:
152-
continue
153-
154-
name, _, tail = line.partition("=")
155-
156-
# importable.module:object.attr
157-
py_import, _, extras = tail.strip().partition(" ")
158-
module, _, attribute = py_import.partition(":")
159-
160-
ret.append(struct(
161-
name = name.strip(),
162-
module = module.strip(),
163-
attribute = attribute.strip(),
164-
extras = extras.replace(" ", ""),
165-
))
166-
167-
return ret

0 commit comments

Comments
 (0)