diff --git a/.bazelrc b/.bazelrc index bf13baf132..2ba5e56e1d 100644 --- a/.bazelrc +++ b/.bazelrc @@ -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 diff --git a/docs/sphinx/_includes/py_console_script_binary.md b/docs/sphinx/_includes/py_console_script_binary.md index 7373c8a7b2..2f4c6a36af 100644 --- a/docs/sphinx/_includes/py_console_script_binary.md +++ b/docs/sphinx/_includes/py_console_script_binary.md @@ -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", diff --git a/python/BUILD.bazel b/python/BUILD.bazel index e83b79c914..62bebc0c93 100644 --- a/python/BUILD.bazel +++ b/python/BUILD.bazel @@ -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", @@ -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", ], diff --git a/python/entry_points/BUILD.bazel b/python/entry_points/BUILD.bazel index 46dbd9298b..f0a8c2ed1d 100644 --- a/python/entry_points/BUILD.bazel +++ b/python/entry_points/BUILD.bazel @@ -12,8 +12,6 @@ # 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", @@ -21,17 +19,10 @@ exports_files( 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__"], ) diff --git a/python/entry_points/py_console_script_binary.bzl b/python/entry_points/py_console_script_binary.bzl index c61d44ae78..ee69e9d2ff 100644 --- a/python/entry_points/py_console_script_binary.bzl +++ b/python/entry_points/py_console_script_binary.bzl @@ -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. """ -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.") + _py_console_script_binary(**kwargs) -py_console_script_binary = _py_console_script_binary +py_console_script_binary = _compatibility_shim diff --git a/python/pip.bzl b/python/pip.bzl index a1a67200b1..9a1cca0c67 100644 --- a/python/pip.bzl +++ b/python/pip.bzl @@ -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") @@ -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, diff --git a/python/private/BUILD.bazel b/python/private/BUILD.bazel index c5da4e31e3..74f53155ff 100644 --- a/python/private/BUILD.bazel +++ b/python/private/BUILD.bazel @@ -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") @@ -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"], @@ -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( diff --git a/python/private/pypi/BUILD.bazel b/python/private/pypi/BUILD.bazel index 08fb7259ec..6cab0256fe 100644 --- a/python/private/pypi/BUILD.bazel +++ b/python/private/pypi/BUILD.bazel @@ -13,6 +13,8 @@ # limitations under the License. load("@bazel_skylib//:bzl_library.bzl", "bzl_library") +load("@rules_python//python:defs.bzl", "py_library") +load("//python:py_binary.bzl", "py_binary") load("//python/private:bzlmod_enabled.bzl", "BZLMOD_ENABLED") package(default_visibility = ["//:__subpackages__"]) @@ -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"], @@ -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__", + ], +) diff --git a/python/private/py_console_script_binary.bzl b/python/private/pypi/py_console_script_binary.bzl similarity index 100% rename from python/private/py_console_script_binary.bzl rename to python/private/pypi/py_console_script_binary.bzl diff --git a/python/private/py_console_script_gen.bzl b/python/private/pypi/py_console_script_gen.bzl similarity index 100% rename from python/private/py_console_script_gen.bzl rename to python/private/pypi/py_console_script_gen.bzl diff --git a/python/private/py_console_script_gen.py b/python/private/pypi/py_console_script_gen.py similarity index 100% rename from python/private/py_console_script_gen.py rename to python/private/pypi/py_console_script_gen.py diff --git a/tests/entry_points/BUILD.bazel b/tests/pypi/py_console_script/BUILD.bazel similarity index 95% rename from tests/entry_points/BUILD.bazel rename to tests/pypi/py_console_script/BUILD.bazel index c877462f54..a0e5d89895 100644 --- a/tests/entry_points/BUILD.bazel +++ b/tests/pypi/py_console_script/BUILD.bazel @@ -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", ], ) diff --git a/tests/entry_points/py_console_script_gen_test.py b/tests/pypi/py_console_script/py_console_script_gen_test.py similarity index 99% rename from tests/entry_points/py_console_script_gen_test.py rename to tests/pypi/py_console_script/py_console_script_gen_test.py index a5fceb67f9..00160ebfb6 100644 --- a/tests/entry_points/py_console_script_gen_test.py +++ b/tests/pypi/py_console_script/py_console_script_gen_test.py @@ -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): diff --git a/tests/entry_points/simple_macro.bzl b/tests/pypi/py_console_script/simple_macro.bzl similarity index 100% rename from tests/entry_points/simple_macro.bzl rename to tests/pypi/py_console_script/simple_macro.bzl