Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: redirect entrypoints to py_console_script_binary #2063

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
# (Note, we cannot use `common --deleted_packages` because the bazel version command doesn't support it)
# To update these lines, execute
# `bazel run @rules_bazel_integration_test//tools:update_deleted_packages`
build --deleted_packages=examples/build_file_generation,examples/build_file_generation/random_number_generator,examples/bzlmod,examples/bzlmod_build_file_generation,examples/bzlmod_build_file_generation/other_module/other_module/pkg,examples/bzlmod_build_file_generation/runfiles,examples/bzlmod/entry_points,examples/bzlmod/entry_points/tests,examples/bzlmod/libs/my_lib,examples/bzlmod/other_module,examples/bzlmod/other_module/other_module/pkg,examples/bzlmod/patches,examples/bzlmod/py_proto_library,examples/bzlmod/py_proto_library/example.com/another_proto,examples/bzlmod/py_proto_library/example.com/proto,examples/bzlmod/runfiles,examples/bzlmod/tests,examples/bzlmod/tests/other_module,examples/bzlmod/whl_mods,examples/multi_python_versions/libs/my_lib,examples/multi_python_versions/requirements,examples/multi_python_versions/tests,examples/pip_parse,examples/pip_parse_vendored,examples/pip_repository_annotations,examples/py_proto_library,examples/py_proto_library/example.com/another_proto,examples/py_proto_library/example.com/proto,tests/integration/compile_pip_requirements,tests/integration/compile_pip_requirements_test_from_external_repo,tests/integration/custom_commands,tests/integration/ignore_root_user_error,tests/integration/ignore_root_user_error/submodule,tests/integration/pip_parse,tests/integration/pip_parse/empty,tests/integration/py_cc_toolchain_registered
query --deleted_packages=examples/build_file_generation,examples/build_file_generation/random_number_generator,examples/bzlmod,examples/bzlmod_build_file_generation,examples/bzlmod_build_file_generation/other_module/other_module/pkg,examples/bzlmod_build_file_generation/runfiles,examples/bzlmod/entry_points,examples/bzlmod/entry_points/tests,examples/bzlmod/libs/my_lib,examples/bzlmod/other_module,examples/bzlmod/other_module/other_module/pkg,examples/bzlmod/patches,examples/bzlmod/py_proto_library,examples/bzlmod/py_proto_library/example.com/another_proto,examples/bzlmod/py_proto_library/example.com/proto,examples/bzlmod/runfiles,examples/bzlmod/tests,examples/bzlmod/tests/other_module,examples/bzlmod/whl_mods,examples/multi_python_versions/libs/my_lib,examples/multi_python_versions/requirements,examples/multi_python_versions/tests,examples/pip_parse,examples/pip_parse_vendored,examples/pip_repository_annotations,examples/py_proto_library,examples/py_proto_library/example.com/another_proto,examples/py_proto_library/example.com/proto,tests/integration/compile_pip_requirements,tests/integration/compile_pip_requirements_test_from_external_repo,tests/integration/custom_commands,tests/integration/ignore_root_user_error,tests/integration/ignore_root_user_error/submodule,tests/integration/pip_parse,tests/integration/pip_parse/empty,tests/integration/py_cc_toolchain_registered
build --deleted_packages=examples/build_file_generation,examples/build_file_generation/random_number_generator,examples/bzlmod,examples/bzlmod/entry_points,examples/bzlmod/entry_points/tests,examples/bzlmod/libs/my_lib,examples/bzlmod/other_module,examples/bzlmod/other_module/other_module/pkg,examples/bzlmod/patches,examples/bzlmod/py_proto_library,examples/bzlmod/py_proto_library/example.com/another_proto,examples/bzlmod/py_proto_library/example.com/proto,examples/bzlmod/runfiles,examples/bzlmod/tests,examples/bzlmod/tests/other_module,examples/bzlmod/whl_mods,examples/bzlmod_build_file_generation,examples/bzlmod_build_file_generation/other_module/other_module/pkg,examples/bzlmod_build_file_generation/runfiles,examples/multi_python_versions/libs/my_lib,examples/multi_python_versions/requirements,examples/multi_python_versions/tests,examples/pip_parse,examples/pip_parse_vendored,examples/pip_repository_annotations,examples/py_proto_library,examples/py_proto_library/example.com/another_proto,examples/py_proto_library/example.com/proto,gazelle,gazelle/manifest,gazelle/manifest/generate,gazelle/manifest/hasher,gazelle/manifest/test,gazelle/modules_mapping,gazelle/python,gazelle/python/private,gazelle/pythonconfig,tests/integration/compile_pip_requirements,tests/integration/compile_pip_requirements_test_from_external_repo,tests/integration/custom_commands,tests/integration/ignore_root_user_error,tests/integration/ignore_root_user_error/submodule,tests/integration/pip_parse,tests/integration/pip_parse/empty,tests/integration/py_cc_toolchain_registered
query --deleted_packages=examples/build_file_generation,examples/build_file_generation/random_number_generator,examples/bzlmod,examples/bzlmod/entry_points,examples/bzlmod/entry_points/tests,examples/bzlmod/libs/my_lib,examples/bzlmod/other_module,examples/bzlmod/other_module/other_module/pkg,examples/bzlmod/patches,examples/bzlmod/py_proto_library,examples/bzlmod/py_proto_library/example.com/another_proto,examples/bzlmod/py_proto_library/example.com/proto,examples/bzlmod/runfiles,examples/bzlmod/tests,examples/bzlmod/tests/other_module,examples/bzlmod/whl_mods,examples/bzlmod_build_file_generation,examples/bzlmod_build_file_generation/other_module/other_module/pkg,examples/bzlmod_build_file_generation/runfiles,examples/multi_python_versions/libs/my_lib,examples/multi_python_versions/requirements,examples/multi_python_versions/tests,examples/pip_parse,examples/pip_parse_vendored,examples/pip_repository_annotations,examples/py_proto_library,examples/py_proto_library/example.com/another_proto,examples/py_proto_library/example.com/proto,gazelle,gazelle/manifest,gazelle/manifest/generate,gazelle/manifest/hasher,gazelle/manifest/test,gazelle/modules_mapping,gazelle/python,gazelle/python/private,gazelle/pythonconfig,tests/integration/compile_pip_requirements,tests/integration/compile_pip_requirements_test_from_external_repo,tests/integration/custom_commands,tests/integration/ignore_root_user_error,tests/integration/ignore_root_user_error/submodule,tests/integration/pip_parse,tests/integration/pip_parse/empty,tests/integration/py_cc_toolchain_registered

test --test_output=errors

Expand Down
2 changes: 1 addition & 1 deletion docs/sphinx/_includes/py_console_script_binary.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ as per Python [specification].
Generate a `py_binary` target for a particular console_script `entry_point`
from a PyPI package, e.g. for creating an executable `pylint` target use:
```starlark
load("@rules_python//python/entry_points:py_console_script_binary.bzl", "py_console_script_binary")
load("@rules_python//python/pip:py_console_script_binary.bzl", "py_console_script_binary")

py_console_script_binary(
name = "pylint",
Expand Down
2 changes: 1 addition & 1 deletion python/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ filegroup(
"//python/cc:distribution",
"//python/config_settings:distribution",
"//python/constraints:distribution",
"//python/entry_points:distribution",
"//python/extensions:distribution",
"//python/pip_install:distribution",
"//python/private:distribution",
Expand Down Expand Up @@ -103,6 +102,7 @@ bzl_library(
"//python/private/pypi:package_annotation_bzl",
"//python/private/pypi:pip_compile_bzl",
"//python/private/pypi:pip_repository_bzl",
"//python/private/pypi:py_console_script_binary_bzl",
"//python/private/pypi:whl_library_alias_bzl",
"//python/private/whl_filegroup:whl_filegroup_bzl",
],
Expand Down
17 changes: 4 additions & 13 deletions python/entry_points/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,17 @@
# See the License for the specific language governing permissions and
# limitations under the License.

load("@bazel_skylib//:bzl_library.bzl", "bzl_library")

exports_files(
[
"py_console_script_binary.bzl",
],
visibility = ["//docs:__subpackages__"],
)

bzl_library(
# Temporary compatibility alias
alias(
name = "py_console_script_binary_bzl",
srcs = [":py_console_script_binary.bzl"],
actual = "//python:pip_bzl",
deprecation = "Use //python:pip_bzl instead; this alias will be removed in a future release.",
visibility = ["//visibility:public"],
deps = [
"//python/private:py_console_script_binary_bzl",
],
)

filegroup(
name = "distribution",
srcs = glob(["**"]),
visibility = ["//python:__subpackages__"],
)
14 changes: 8 additions & 6 deletions python/entry_points/py_console_script_binary.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@
# limitations under the License.

"""
Creates an executable (a non-test binary) for console_script entry points.

```{include} /_includes/py_console_script_binary.md
```
Please use `py_console_script_binary` from `//python:pip_bzl` instead.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit, I think this should be pip.bzl instead of pip_bzl.

Maybe it would be great to write the full load statement to help users?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SGTM. Will FIXUP.

"""

load("//python/private:py_console_script_binary.bzl", _py_console_script_binary = "py_console_script_binary")
load("//python:pip.bzl", _py_console_script_binary = "py_console_script_binary")

def _compatibility_shim(**kwargs):
# buildifier: disable=print
print("Please use `py_console_script_binary` from `//python:pip_bzl` instead.")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I saw people using deprecation attribute in some cases instead of a print (this is in py_proto_library case). That may be less spammy, as this will cause one print invocation per usage of the rule, I think?

Maybe it would be useful to print a buildozer command for replacing the loads?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SGTM. Didn't know about it. Will FIXUP.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For macros, I think there's a doc string syntax that stardoc parses out into a "deprecation" doc text. I think it's either """DEPRECATED: blabla """ or """[DEPRECATED]: blalba""" ? Not entirely sure.

I'm pretty sure our docgen respects it when stardoc emits it.

_py_console_script_binary(**kwargs)

py_console_script_binary = _py_console_script_binary
py_console_script_binary = _compatibility_shim
3 changes: 3 additions & 0 deletions python/pip.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ load("//python/private/pypi:multi_pip_parse.bzl", _multi_pip_parse = "multi_pip_
load("//python/private/pypi:package_annotation.bzl", _package_annotation = "package_annotation")
load("//python/private/pypi:pip_compile.bzl", "pip_compile")
load("//python/private/pypi:pip_repository.bzl", "pip_repository")
load("//python/private/pypi:py_console_script_binary.bzl", _py_console_script_binary = "py_console_script_binary")
load("//python/private/pypi:whl_library_alias.bzl", _whl_library_alias = "whl_library_alias")
load("//python/private/whl_filegroup:whl_filegroup.bzl", _whl_filegroup = "whl_filegroup")

Expand All @@ -32,6 +33,8 @@ package_annotation = _package_annotation
pip_parse = pip_repository
whl_filegroup = _whl_filegroup

py_console_script_binary = _py_console_script_binary

# Extra utilities visible to rules_python users.
pip_utils = struct(
normalize_name = normalize_name,
Expand Down
33 changes: 0 additions & 33 deletions python/private/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@

load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
load("@bazel_skylib//rules:common_settings.bzl", "bool_setting")
load("//python:py_binary.bzl", "py_binary")
load("//python:py_library.bzl", "py_library")
load("//python:versions.bzl", "print_toolchains_checksums")
load(":py_exec_tools_toolchain.bzl", "current_interpreter_executable")
load(":stamp.bzl", "stamp_build_setting")
Expand Down Expand Up @@ -173,18 +171,6 @@ bzl_library(
visibility = ["//python/cc:__pkg__"],
)

bzl_library(
name = "py_console_script_binary_bzl",
srcs = [
"py_console_script_binary.bzl",
"py_console_script_gen.bzl",
],
visibility = ["//python/entry_points:__pkg__"],
deps = [
"//python:py_binary_bzl",
],
)

bzl_library(
name = "py_exec_tools_toolchain_bzl",
srcs = ["py_exec_tools_toolchain.bzl"],
Expand Down Expand Up @@ -405,25 +391,6 @@ bool_setting(

print_toolchains_checksums(name = "print_toolchains_checksums")

# Used for py_console_script_gen rule
py_binary(
name = "py_console_script_gen_py",
srcs = ["py_console_script_gen.py"],
main = "py_console_script_gen.py",
visibility = [
"//visibility:public",
],
)

py_library(
name = "py_console_script_gen_lib",
srcs = ["py_console_script_gen.py"],
imports = ["../.."],
visibility = [
"//tests/entry_points:__pkg__",
],
)

# The current toolchain's interpreter as an excutable, usable with
# executable=True attributes.
current_interpreter_executable(
Expand Down
32 changes: 32 additions & 0 deletions python/private/pypi/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
# limitations under the License.

load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
load("@rules_python//python:defs.bzl", "py_library")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please drop rules_python in the load statements in internal code.

load("//python:py_binary.bzl", "py_binary")
load("//python/private:bzlmod_enabled.bzl", "BZLMOD_ENABLED")

package(default_visibility = ["//:__subpackages__"])
Expand Down Expand Up @@ -227,6 +229,17 @@ bzl_library(
srcs = ["pip_repository_attrs.bzl"],
)

bzl_library(
name = "py_console_script_binary_bzl",
srcs = [
":py_console_script_binary.bzl",
":py_console_script_gen.bzl",
],
deps = [
"//python:defs_bzl",
],
)

bzl_library(
name = "render_pkg_aliases_bzl",
srcs = ["render_pkg_aliases.bzl"],
Expand Down Expand Up @@ -294,3 +307,22 @@ bzl_library(
srcs = ["whl_target_platforms.bzl"],
deps = [":parse_whl_name_bzl"],
)

# Used for py_console_script_gen rule
py_binary(
name = "py_console_script_gen_py",
srcs = ["py_console_script_gen.py"],
main = "py_console_script_gen.py",
visibility = [
"//visibility:public",
],
)

py_library(
name = "py_console_script_gen_lib",
srcs = ["py_console_script_gen.py"],
imports = ["../.."],
visibility = [
"//tests/pypi/py_console_script:__pkg__",
],
)
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ py_test(
main = "py_console_script_gen_test.py",
visibility = ["//visibility:private"],
deps = [
"//python/private:py_console_script_gen_lib",
"//python/private/pypi:py_console_script_gen_lib",
],
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import textwrap
import unittest

from python.private.py_console_script_gen import run
from python.private.pypi.py_console_script_gen import run


class RunTest(unittest.TestCase):
Expand Down