From a55128cda9b69c8d44e0c28311c24bfa178d327d Mon Sep 17 00:00:00 2001 From: Ivo List Date: Sat, 5 Oct 2024 09:39:06 +0200 Subject: [PATCH 01/16] Conditionally remove builtin PyInfo and other providers Use bazel_features to detect if PyInfo is still present in Bazel and stop using it, if it's not. Bazel throws an error while compiling bzl files if there is a reference to a top-level symbol that doesn't exist anymore. bazel_features provide a mechanism that detects presence of top-level symbols without throwing an exception. It either returns the symbol or None. bazel_features support not only Bazel 8, but also older versions of Bazel that have --incompatible_autoload_externally cherry-picked. If the flag is enabled with "@rules_python" or "-@rules_python" the provider is removed from Bazel. Remove also PyRuntimeInfo and PyCcLinkParamsProvider. --- MODULE.bazel | 2 +- internal_deps.bzl | 6 +++--- python/config_settings/transition.bzl | 4 ++-- python/private/BUILD.bazel | 5 ++++- python/private/common/attributes.bzl | 5 +++-- python/private/common/common.bzl | 8 ++++---- python/private/common/py_executable.bzl | 2 +- python/private/common/py_runtime_rule.bzl | 14 ++++++++------ python/private/py_info.bzl | 4 ++-- python/private/py_repositories.bzl | 6 ++++++ python/private/py_runtime_pair_rule.bzl | 8 +++++--- python/private/reexports.bzl | 6 ++++-- python/py_cc_link_params_info.bzl | 3 ++- python/py_info.bzl | 2 +- 14 files changed, 46 insertions(+), 29 deletions(-) diff --git a/MODULE.bazel b/MODULE.bazel index 58c7ae229b..9d539d1949 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -4,7 +4,7 @@ module( compatibility_level = 1, ) -bazel_dep(name = "bazel_features", version = "1.9.1") +bazel_dep(name = "bazel_features", version = "1.18.0") bazel_dep(name = "bazel_skylib", version = "1.6.1") bazel_dep(name = "rules_cc", version = "0.0.9") bazel_dep(name = "platforms", version = "0.0.4") diff --git a/internal_deps.bzl b/internal_deps.bzl index 56962cbd19..e75d782fc9 100644 --- a/internal_deps.bzl +++ b/internal_deps.bzl @@ -212,9 +212,9 @@ def rules_python_internal_deps(): http_archive( name = "bazel_features", - sha256 = "d7787da289a7fb497352211ad200ec9f698822a9e0757a4976fd9f713ff372b3", - strip_prefix = "bazel_features-1.9.1", - url = "https://github.com/bazel-contrib/bazel_features/releases/download/v1.9.1/bazel_features-v1.9.1.tar.gz", + sha256 = "b4b145c19e08fd48337f53c383db46398d0a810002907ff0c590762d926e05be", + strip_prefix = "bazel_features-1.18.0", + url = "https://github.com/bazel-contrib/bazel_features/releases/download/v1.18.0/bazel_features-v1.18.0.tar.gz", ) http_archive( diff --git a/python/config_settings/transition.bzl b/python/config_settings/transition.bzl index 7ac41f881f..a7646dcda3 100644 --- a/python/config_settings/transition.bzl +++ b/python/config_settings/transition.bzl @@ -101,12 +101,12 @@ def _transition_py_impl(ctx): ] if PyInfo in target: providers.append(target[PyInfo]) - if BuiltinPyInfo in target and PyInfo != BuiltinPyInfo: + if BuiltinPyInfo != None and BuiltinPyInfo in target and PyInfo != BuiltinPyInfo: providers.append(target[BuiltinPyInfo]) if PyRuntimeInfo in target: providers.append(target[PyRuntimeInfo]) - if BuiltinPyRuntimeInfo in target and PyRuntimeInfo != BuiltinPyRuntimeInfo: + if BuiltinPyRuntimeInfo != None and BuiltinPyRuntimeInfo in target and PyRuntimeInfo != BuiltinPyRuntimeInfo: providers.append(target[BuiltinPyRuntimeInfo]) return providers diff --git a/python/private/BUILD.bazel b/python/private/BUILD.bazel index f128742b2c..adaef4c1b0 100644 --- a/python/private/BUILD.bazel +++ b/python/private/BUILD.bazel @@ -341,7 +341,10 @@ bzl_library( visibility = [ "//:__subpackages__", ], - deps = [":bazel_tools_bzl"], + deps = [ + ":bazel_tools_bzl", + "@bazel_features//:features", + ], ) bzl_library( diff --git a/python/private/common/attributes.bzl b/python/private/common/attributes.bzl index 5e81f4698e..0299e85657 100644 --- a/python/private/common/attributes.bzl +++ b/python/private/common/attributes.bzl @@ -253,6 +253,8 @@ COMMON_ATTRS = union_attrs( allow_none = True, ) +_MaybeBuiltinPyInfo = [[BuiltinPyInfo]] if BuiltinPyInfo != None else [] + # Attributes common to rules accepting Python sources and deps. PY_SRCS_ATTRS = union_attrs( { @@ -260,8 +262,7 @@ PY_SRCS_ATTRS = union_attrs( providers = [ [PyInfo], [CcInfo], - [BuiltinPyInfo], - ], + ] + _MaybeBuiltinPyInfo, # TODO(b/228692666): Google-specific; remove these allowances once # the depot is cleaned up. allow_rules = DEPS_ATTR_ALLOW_RULES, diff --git a/python/private/common/common.bzl b/python/private/common/common.bzl index e4cc254654..99a632484d 100644 --- a/python/private/common/common.bzl +++ b/python/private/common/common.bzl @@ -280,7 +280,7 @@ def collect_imports(ctx, semantics): dep[BuiltinPyInfo].imports for dep in ctx.attr.deps if BuiltinPyInfo in dep - ]) + ] if BuiltinPyInfo != None else []) def collect_runfiles(ctx, files = depset()): """Collects the necessary files from the rule's context. @@ -374,7 +374,7 @@ def create_py_info(ctx, *, direct_sources, direct_pyc_files, imports): for target in ctx.attr.deps: # PyInfo may not be present e.g. cc_library rules. - if PyInfo in target or BuiltinPyInfo in target: + if PyInfo in target or (BuiltinPyInfo != None and BuiltinPyInfo in target): py_info.merge(_get_py_info(target)) else: # TODO(b/228692666): Remove this once non-PyInfo targets are no @@ -395,7 +395,7 @@ def create_py_info(ctx, *, direct_sources, direct_pyc_files, imports): for target in ctx.attr.data: # TODO(b/234730058): Remove checking for PyInfo in data once depot # cleaned up. - if PyInfo in target or BuiltinPyInfo in target: + if PyInfo in target or (BuiltinPyInfo != None and BuiltinPyInfo in target): info = _get_py_info(target) py_info.merge_uses_shared_libraries(info.uses_shared_libraries) else: @@ -410,7 +410,7 @@ def create_py_info(ctx, *, direct_sources, direct_pyc_files, imports): return py_info.build(), deps_transitive_sources, py_info.build_builtin_py_info() def _get_py_info(target): - return target[PyInfo] if PyInfo in target else target[BuiltinPyInfo] + return target[PyInfo] if PyInfo in target or BuiltinPyInfo == None else target[BuiltinPyInfo] def create_instrumented_files_info(ctx): return _coverage_common.instrumented_files_info( diff --git a/python/private/common/py_executable.bzl b/python/private/common/py_executable.bzl index 1d14344d4e..04c0cae3bb 100644 --- a/python/private/common/py_executable.bzl +++ b/python/private/common/py_executable.bzl @@ -855,7 +855,7 @@ def _create_providers( # builtin py_runtime rule or defined their own. We can't directly detect # the type of the provider object, but the rules_python PyRuntimeInfo # object has an extra attribute that the builtin one doesn't. - if hasattr(py_runtime_info, "interpreter_version_info"): + if hasattr(py_runtime_info, "interpreter_version_info") and BuiltinPyRuntimeInfo != None: providers.append(BuiltinPyRuntimeInfo( interpreter_path = py_runtime_info.interpreter_path, interpreter = py_runtime_info.interpreter, diff --git a/python/private/common/py_runtime_rule.bzl b/python/private/common/py_runtime_rule.bzl index b339425099..8ec860c3dd 100644 --- a/python/private/common/py_runtime_rule.bzl +++ b/python/private/common/py_runtime_rule.bzl @@ -125,18 +125,20 @@ def _py_runtime_impl(ctx): if not IS_BAZEL_7_OR_HIGHER: builtin_py_runtime_info_kwargs.pop("bootstrap_template") - return [ + providers = [ PyRuntimeInfo(**py_runtime_info_kwargs), - # Return the builtin provider for better compatibility. - # 1. There is a legacy code path in py_binary that - # checks for the provider when toolchains aren't used - # 2. It makes it easier to transition from builtins to rules_python - BuiltinPyRuntimeInfo(**builtin_py_runtime_info_kwargs), DefaultInfo( files = runtime_files, runfiles = runfiles, ), ] + if BuiltinPyRuntimeInfo != None: + # Return the builtin provider for better compatibility. + # 1. There is a legacy code path in py_binary that + # checks for the provider when toolchains aren't used + # 2. It makes it easier to transition from builtins to rules_python + providers.append(BuiltinPyRuntimeInfo(**builtin_py_runtime_info_kwargs)) + return providers # Bind to the name "py_runtime" to preserve the kind/rule_class it shows up # as elsewhere. diff --git a/python/private/py_info.bzl b/python/private/py_info.bzl index a3e40f2924..8ccddf8d06 100644 --- a/python/private/py_info.bzl +++ b/python/private/py_info.bzl @@ -118,7 +118,7 @@ This field is currently unused in Bazel and may go away in the future. ) # The "effective" PyInfo is what the canonical //python:py_info.bzl%PyInfo symbol refers to -_EffectivePyInfo = PyInfo if config.enable_pystar else BuiltinPyInfo +_EffectivePyInfo = PyInfo if config.enable_pystar or BuiltinPyInfo == None else BuiltinPyInfo def PyInfoBuilder(): # buildifier: disable=uninitialized @@ -201,7 +201,7 @@ def _PyInfoBuilder_merge_all(self, py_infos): def _PyInfoBuilder_merge_target(self, target): if PyInfo in target: self.merge(target[PyInfo]) - elif BuiltinPyInfo in target: + elif BuiltinPyInfo != None and BuiltinPyInfo in target: self.merge(target[BuiltinPyInfo]) return self diff --git a/python/private/py_repositories.bzl b/python/private/py_repositories.bzl index 8ddcb5d3a7..b2f4790578 100644 --- a/python/private/py_repositories.bzl +++ b/python/private/py_repositories.bzl @@ -46,4 +46,10 @@ def py_repositories(): sha256 = "2037875b9a4456dce4a79d112a8ae885bbc4aad968e6587dca6e64f3a0900cdf", strip_prefix = "rules_cc-0.0.9", ) + http_archive( + name = "bazel_features", + sha256 = "b4b145c19e08fd48337f53c383db46398d0a810002907ff0c590762d926e05be", + strip_prefix = "bazel_features-1.18.0", + url = "https://github.com/bazel-contrib/bazel_features/releases/download/v1.18.0/bazel_features-v1.18.0.tar.gz", + ) pypi_deps() diff --git a/python/private/py_runtime_pair_rule.bzl b/python/private/py_runtime_pair_rule.bzl index eb91413563..39f15bffb4 100644 --- a/python/private/py_runtime_pair_rule.bzl +++ b/python/private/py_runtime_pair_rule.bzl @@ -56,7 +56,7 @@ def _get_py_runtime_info(target): # py_binary (implemented in Java) performs a type check on the provider # value to verify it is an instance of the Java-implemented PyRuntimeInfo # class. - if IS_BAZEL_7_OR_HIGHER and PyRuntimeInfo in target: + if (IS_BAZEL_7_OR_HIGHER and PyRuntimeInfo in target) or BuiltinPyRuntimeInfo == None: return target[PyRuntimeInfo] else: return target[BuiltinPyRuntimeInfo] @@ -70,13 +70,15 @@ def _is_py2_disabled(ctx): return False return ctx.fragments.py.disable_py2 +_MaybeBuiltinPyRuntimeInfo = [[BuiltinPyRuntimeInfo]] if BuiltinPyRuntimeInfo != None else [] + py_runtime_pair = rule( implementation = _py_runtime_pair_impl, attrs = { # The two runtimes are used by the py_binary at runtime, and so need to # be built for the target platform. "py2_runtime": attr.label( - providers = [[PyRuntimeInfo], [BuiltinPyRuntimeInfo]], + providers = [[PyRuntimeInfo]] + _MaybeBuiltinPyRuntimeInfo, cfg = "target", doc = """\ The runtime to use for Python 2 targets. Must have `python_version` set to @@ -84,7 +86,7 @@ The runtime to use for Python 2 targets. Must have `python_version` set to """, ), "py3_runtime": attr.label( - providers = [[PyRuntimeInfo], [BuiltinPyRuntimeInfo]], + providers = [[PyRuntimeInfo]] + _MaybeBuiltinPyRuntimeInfo, cfg = "target", doc = """\ The runtime to use for Python 3 targets. Must have `python_version` set to diff --git a/python/private/reexports.bzl b/python/private/reexports.bzl index ea39ac9f35..1be2ec0279 100644 --- a/python/private/reexports.bzl +++ b/python/private/reexports.bzl @@ -30,11 +30,13 @@ inaccessible. So instead we access the builtin here and export it under a different name. Then we can load it from elsewhere. """ +load("@bazel_features//:features.bzl", "bazel_features") + # Don't use underscore prefix, since that would make the symbol local to this # file only. Use a non-conventional name to emphasize that this is not a public # symbol. # buildifier: disable=name-conventions -BuiltinPyInfo = PyInfo +BuiltinPyInfo = getattr(bazel_features.globals, "PyInfo", None) # buildifier: disable=name-conventions -BuiltinPyRuntimeInfo = PyRuntimeInfo +BuiltinPyRuntimeInfo = getattr(bazel_features.globals, "PyRuntimeInfo", None) diff --git a/python/py_cc_link_params_info.bzl b/python/py_cc_link_params_info.bzl index 42d8daf221..b231e6a64b 100644 --- a/python/py_cc_link_params_info.bzl +++ b/python/py_cc_link_params_info.bzl @@ -3,4 +3,5 @@ load("@rules_python_internal//:rules_python_config.bzl", "config") load("//python/private/common:providers.bzl", _starlark_PyCcLinkParamsProvider = "PyCcLinkParamsProvider") -PyCcLinkParamsInfo = _starlark_PyCcLinkParamsProvider if config.enable_pystar else PyCcLinkParamsProvider +_PyCcLinkParamsProvider = getattr(bazel_features.globals, "PyCcLinkParamsProvider", None) +PyCcLinkParamsInfo = _starlark_PyCcLinkParamsProvider if config.enable_pystar or _PyCcLinkParamsProvider == None else PyCcLinkParamsProvider diff --git a/python/py_info.bzl b/python/py_info.bzl index 52a66a87c2..5697f58419 100644 --- a/python/py_info.bzl +++ b/python/py_info.bzl @@ -18,4 +18,4 @@ load("@rules_python_internal//:rules_python_config.bzl", "config") load("//python/private:py_info.bzl", _starlark_PyInfo = "PyInfo") load("//python/private:reexports.bzl", "BuiltinPyInfo") -PyInfo = _starlark_PyInfo if config.enable_pystar else BuiltinPyInfo +PyInfo = _starlark_PyInfo if config.enable_pystar or BuiltinPyInfo == None else BuiltinPyInfo From 8bef688fcf37fd6a15397a2a7ab665e4e7730701 Mon Sep 17 00:00:00 2001 From: Ivo List Date: Sat, 5 Oct 2024 10:08:46 +0200 Subject: [PATCH 02/16] Disable name-conventions on PyCcLinkParamsProvider --- python/py_cc_link_params_info.bzl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/py_cc_link_params_info.bzl b/python/py_cc_link_params_info.bzl index b231e6a64b..27fd786268 100644 --- a/python/py_cc_link_params_info.bzl +++ b/python/py_cc_link_params_info.bzl @@ -3,5 +3,5 @@ load("@rules_python_internal//:rules_python_config.bzl", "config") load("//python/private/common:providers.bzl", _starlark_PyCcLinkParamsProvider = "PyCcLinkParamsProvider") -_PyCcLinkParamsProvider = getattr(bazel_features.globals, "PyCcLinkParamsProvider", None) +_PyCcLinkParamsProvider = getattr(bazel_features.globals, "PyCcLinkParamsProvider", None) # buildifier: disable=name-conventions PyCcLinkParamsInfo = _starlark_PyCcLinkParamsProvider if config.enable_pystar or _PyCcLinkParamsProvider == None else PyCcLinkParamsProvider From 7fbe583d5103e0f338435e9c74fd03c414f83805 Mon Sep 17 00:00:00 2001 From: Ivo List Date: Sat, 5 Oct 2024 10:27:15 +0200 Subject: [PATCH 03/16] Create repositories_deps that sets up bazel features --- WORKSPACE | 1 + python/repositories_deps.bzl | 6 ++++++ 2 files changed, 7 insertions(+) create mode 100644 python/repositories_deps.bzl diff --git a/WORKSPACE b/WORKSPACE index 02b3b6e926..3ba6fc93cb 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -18,6 +18,7 @@ workspace(name = "rules_python") # should not copy it to their WORKSPACE. load("//:internal_deps.bzl", "rules_python_internal_deps") +load("//python:py_repositories_deps.bzl", "py_repositories_rules_deps") rules_python_internal_deps() diff --git a/python/repositories_deps.bzl b/python/repositories_deps.bzl new file mode 100644 index 0000000000..1cc60e5bab --- /dev/null +++ b/python/repositories_deps.bzl @@ -0,0 +1,6 @@ +"""Sets up rules_python repository deps for WORKSPACE users""" + +load("@bazel_features//:deps.bzl", "bazel_features_deps") + +def py_repositories_deps(): + bazel_features_deps() From 9590e60ecea7d74fa1a1067f61d820b2b877cd5b Mon Sep 17 00:00:00 2001 From: Ivo List Date: Sat, 5 Oct 2024 10:27:30 +0200 Subject: [PATCH 04/16] Call reposiotries_deps in all WORKSPACE test/examples --- examples/build_file_generation/WORKSPACE | 4 ++++ examples/multi_python_versions/WORKSPACE | 4 ++++ examples/pip_parse/WORKSPACE | 4 ++++ examples/pip_parse_vendored/WORKSPACE | 4 ++++ examples/pip_repository_annotations/WORKSPACE | 4 ++++ examples/py_proto_library/WORKSPACE | 4 ++++ tests/integration/compile_pip_requirements/WORKSPACE | 4 ++++ .../WORKSPACE | 4 ++++ tests/integration/custom_commands/WORKSPACE | 4 ++++ tests/integration/ignore_root_user_error/WORKSPACE | 4 ++++ tests/integration/pip_parse/WORKSPACE | 4 ++++ tests/integration/py_cc_toolchain_registered/WORKSPACE | 6 ++++++ 12 files changed, 50 insertions(+) diff --git a/examples/build_file_generation/WORKSPACE b/examples/build_file_generation/WORKSPACE index 3f1fad8a8d..50426daaa7 100644 --- a/examples/build_file_generation/WORKSPACE +++ b/examples/build_file_generation/WORKSPACE @@ -76,6 +76,10 @@ load("@rules_python//python:repositories.bzl", "py_repositories", "python_regist # Perform general setup py_repositories() +load("@rules_python//python:repositories_deps.bzl", "py_repositories_deps") + +py_repositories_deps() + # We now register a hermetic Python interpreter rather than relying on a system-installed interpreter. # This toolchain will allow bazel to download a specific python version, and use that version # for compilation. diff --git a/examples/multi_python_versions/WORKSPACE b/examples/multi_python_versions/WORKSPACE index 4f731d95a8..705022b2ef 100644 --- a/examples/multi_python_versions/WORKSPACE +++ b/examples/multi_python_versions/WORKSPACE @@ -9,6 +9,10 @@ load("@rules_python//python:repositories.bzl", "py_repositories", "python_regist py_repositories() +load("@rules_python//python:repositories_deps.bzl", "py_repositories_deps") + +py_repositories_deps() + default_python_version = "3.9" python_register_multi_toolchains( diff --git a/examples/pip_parse/WORKSPACE b/examples/pip_parse/WORKSPACE index bb4714d941..b11313dc90 100644 --- a/examples/pip_parse/WORKSPACE +++ b/examples/pip_parse/WORKSPACE @@ -9,6 +9,10 @@ load("@rules_python//python:repositories.bzl", "py_repositories", "python_regist py_repositories() +load("@rules_python//python:repositories_deps.bzl", "py_repositories_deps") + +py_repositories_deps() + python_register_toolchains( name = "python_3_9", python_version = "3.9.13", diff --git a/examples/pip_parse_vendored/WORKSPACE b/examples/pip_parse_vendored/WORKSPACE index d7a11ea596..1981f93890 100644 --- a/examples/pip_parse_vendored/WORKSPACE +++ b/examples/pip_parse_vendored/WORKSPACE @@ -9,6 +9,10 @@ load("@rules_python//python:repositories.bzl", "py_repositories", "python_regist py_repositories() +load("@rules_python//python:repositories_deps.bzl", "py_repositories_deps") + +py_repositories_deps() + python_register_toolchains( name = "python39", python_version = "3.9", diff --git a/examples/pip_repository_annotations/WORKSPACE b/examples/pip_repository_annotations/WORKSPACE index 8540555084..1b325a0a49 100644 --- a/examples/pip_repository_annotations/WORKSPACE +++ b/examples/pip_repository_annotations/WORKSPACE @@ -9,6 +9,10 @@ load("@rules_python//python:repositories.bzl", "py_repositories", "python_regist py_repositories() +load("@rules_python//python:repositories_deps.bzl", "py_repositories_deps") + +py_repositories_deps() + python_register_toolchains( name = "python39", python_version = "3.9", diff --git a/examples/py_proto_library/WORKSPACE b/examples/py_proto_library/WORKSPACE index 81f189dbbf..3f1c146ddb 100644 --- a/examples/py_proto_library/WORKSPACE +++ b/examples/py_proto_library/WORKSPACE @@ -16,6 +16,10 @@ load("@rules_python//python:repositories.bzl", "py_repositories", "python_regist # We install the rules_python dependencies using the function below. py_repositories() +load("@rules_python//python:repositories_deps.bzl", "py_repositories_deps") + +py_repositories_deps() + python_register_toolchains( name = "python39", python_version = "3.9", diff --git a/tests/integration/compile_pip_requirements/WORKSPACE b/tests/integration/compile_pip_requirements/WORKSPACE index 0eeab2067c..3317cc4fb7 100644 --- a/tests/integration/compile_pip_requirements/WORKSPACE +++ b/tests/integration/compile_pip_requirements/WORKSPACE @@ -7,6 +7,10 @@ load("@rules_python//python:repositories.bzl", "py_repositories", "python_regist py_repositories() +load("@rules_python//python:repositories_deps.bzl", "py_repositories_deps") + +py_repositories_deps() + python_register_toolchains( name = "python39", python_version = "3.9", diff --git a/tests/integration/compile_pip_requirements_test_from_external_repo/WORKSPACE b/tests/integration/compile_pip_requirements_test_from_external_repo/WORKSPACE index 48caeb442f..e2dc4cafc5 100644 --- a/tests/integration/compile_pip_requirements_test_from_external_repo/WORKSPACE +++ b/tests/integration/compile_pip_requirements_test_from_external_repo/WORKSPACE @@ -7,6 +7,10 @@ load("@rules_python//python:repositories.bzl", "py_repositories", "python_regist py_repositories() +load("@rules_python//python:repositories_deps.bzl", "py_repositories_deps") + +py_repositories_deps() + python_register_toolchains( name = "python39", python_version = "3.9", diff --git a/tests/integration/custom_commands/WORKSPACE b/tests/integration/custom_commands/WORKSPACE index de908549c0..579da8accc 100644 --- a/tests/integration/custom_commands/WORKSPACE +++ b/tests/integration/custom_commands/WORKSPACE @@ -7,6 +7,10 @@ load("@rules_python//python:repositories.bzl", "py_repositories", "python_regist py_repositories() +load("@rules_python//python:repositories_deps.bzl", "py_repositories_deps") + +py_repositories_deps() + python_register_toolchains( name = "python_3_11", python_version = "3.11", diff --git a/tests/integration/ignore_root_user_error/WORKSPACE b/tests/integration/ignore_root_user_error/WORKSPACE index c21b01e1bc..93b53f3bd9 100644 --- a/tests/integration/ignore_root_user_error/WORKSPACE +++ b/tests/integration/ignore_root_user_error/WORKSPACE @@ -7,6 +7,10 @@ load("@rules_python//python:repositories.bzl", "py_repositories", "python_regist py_repositories() +load("@rules_python//python:repositories_deps.bzl", "py_repositories_deps") + +py_repositories_deps() + python_register_toolchains( name = "python39", ignore_root_user_error = True, diff --git a/tests/integration/pip_parse/WORKSPACE b/tests/integration/pip_parse/WORKSPACE index db0cd0c7c8..fb273e0371 100644 --- a/tests/integration/pip_parse/WORKSPACE +++ b/tests/integration/pip_parse/WORKSPACE @@ -7,6 +7,10 @@ load("@rules_python//python:repositories.bzl", "py_repositories", "python_regist py_repositories() +load("@rules_python//python:repositories_deps.bzl", "py_repositories_deps") + +py_repositories_deps() + # This call is included in `py_repositories` and we are calling # `pip_install_dependencies` only to ensure that we are not breaking really old # code. diff --git a/tests/integration/py_cc_toolchain_registered/WORKSPACE b/tests/integration/py_cc_toolchain_registered/WORKSPACE index de908549c0..c1f8da254b 100644 --- a/tests/integration/py_cc_toolchain_registered/WORKSPACE +++ b/tests/integration/py_cc_toolchain_registered/WORKSPACE @@ -7,6 +7,12 @@ load("@rules_python//python:repositories.bzl", "py_repositories", "python_regist py_repositories() +load("@rules_python//python:repositories_deps.bzl", "py_repositories_deps") + +py_repositories_deps() + +py_repositories_deps() + python_register_toolchains( name = "python_3_11", python_version = "3.11", From 0c4162400711acfe60101c8a57d04763c638c486 Mon Sep 17 00:00:00 2001 From: Ivo List Date: Sat, 5 Oct 2024 10:49:24 +0200 Subject: [PATCH 05/16] Update lock file --- examples/bzlmod/MODULE.bazel.lock | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/examples/bzlmod/MODULE.bazel.lock b/examples/bzlmod/MODULE.bazel.lock index 604aef17c6..2746f20ca0 100644 --- a/examples/bzlmod/MODULE.bazel.lock +++ b/examples/bzlmod/MODULE.bazel.lock @@ -10,14 +10,13 @@ "https://bcr.bazel.build/modules/apple_support/1.5.0/MODULE.bazel": "50341a62efbc483e8a2a6aec30994a58749bd7b885e18dd96aa8c33031e558ef", "https://bcr.bazel.build/modules/apple_support/1.5.0/source.json": "eb98a7627c0bc486b57f598ad8da50f6625d974c8f723e9ea71bd39f709c9862", "https://bcr.bazel.build/modules/bazel_features/1.11.0/MODULE.bazel": "f9382337dd5a474c3b7d334c2f83e50b6eaedc284253334cf823044a26de03e8", - "https://bcr.bazel.build/modules/bazel_features/1.11.0/source.json": "c9320aa53cd1c441d24bd6b716da087ad7e4ff0d9742a9884587596edfe53015", - "https://bcr.bazel.build/modules/bazel_features/1.9.1/MODULE.bazel": "8f679097876a9b609ad1f60249c49d68bfab783dd9be012faf9d82547b14815a", + "https://bcr.bazel.build/modules/bazel_features/1.18.0/MODULE.bazel": "1be0ae2557ab3a72a57aeb31b29be347bcdc5d2b1eb1e70f39e3851a7e97041a", + "https://bcr.bazel.build/modules/bazel_features/1.18.0/source.json": "cde886d88c8164b50b9b97dba7c0a64ca24d257b72ca3a2fcb06bee1fdb47ee4", "https://bcr.bazel.build/modules/bazel_skylib/1.0.3/MODULE.bazel": "bcb0fd896384802d1ad283b4e4eb4d718eebd8cb820b0a2c3a347fb971afd9d8", "https://bcr.bazel.build/modules/bazel_skylib/1.2.0/MODULE.bazel": "44fe84260e454ed94ad326352a698422dbe372b21a1ac9f3eab76eb531223686", "https://bcr.bazel.build/modules/bazel_skylib/1.2.1/MODULE.bazel": "f35baf9da0efe45fa3da1696ae906eea3d615ad41e2e3def4aeb4e8bc0ef9a7a", "https://bcr.bazel.build/modules/bazel_skylib/1.3.0/MODULE.bazel": "20228b92868bf5cfc41bda7afc8a8ba2a543201851de39d990ec957b513579c5", "https://bcr.bazel.build/modules/bazel_skylib/1.4.1/MODULE.bazel": "a0dcb779424be33100dcae821e9e27e4f2901d9dfd5333efe5ac6a8d7ab75e1d", - "https://bcr.bazel.build/modules/bazel_skylib/1.5.0/MODULE.bazel": "32880f5e2945ce6a03d1fbd588e9198c0a959bb42297b2cfaf1685b7bc32e138", "https://bcr.bazel.build/modules/bazel_skylib/1.6.1/MODULE.bazel": "8fdee2dbaace6c252131c00e1de4b165dc65af02ea278476187765e1a617b917", "https://bcr.bazel.build/modules/bazel_skylib/1.6.1/source.json": "082ed5f9837901fada8c68c2f3ddc958bb22b6d654f71dd73f3df30d45d4b749", "https://bcr.bazel.build/modules/buildozer/7.1.2/MODULE.bazel": "2e8dd40ede9c454042645fd8d8d0cd1527966aa5c919de86661e62953cd73d84", @@ -1231,7 +1230,7 @@ }, "@@rules_python~//python/extensions:pip.bzl%pip": { "general": { - "bzlTransitiveDigest": "W8FWi7aL0uqh7djg6csTMzkL1RB6WGRgfO/MOcbqYZI=", + "bzlTransitiveDigest": "V5/A3wVb+XNcASpqTHoh6Z6Z+R/HKhIhJmjAj2UComY=", "usagesDigest": "MChlcSw99EuW3K7OOoMcXQIdcJnEh6YmfyjJm+9mxIg=", "recordedFileInputs": { "@@other_module~//requirements_lock_3_11.txt": "a7d0061366569043d5efcf80e34a32c732679367cb3c831c4cdc606adc36d314", @@ -6140,7 +6139,7 @@ }, "@@rules_python~//python/private/pypi:pip.bzl%pip_internal": { "general": { - "bzlTransitiveDigest": "9aEp4XU4yVL6sJqODxio5iSCoqf37Ro3o+Mt1izDnq8=", + "bzlTransitiveDigest": "zISCcWz4Z1a0lts3XL4XkZIqXIths46zHs69auV0Blc=", "usagesDigest": "Y8ihY+R57BAFhalrVLVdJFrpwlbsiKz9JPJ99ljF7HA=", "recordedFileInputs": { "@@rules_python~//tools/publish/requirements.txt": "031e35d03dde03ae6305fe4b3d1f58ad7bdad857379752deede0f93649991b8a", From 21be9f6b9e11a1308a1066c2888e72e2a6f92930 Mon Sep 17 00:00:00 2001 From: Ivo List Date: Sat, 5 Oct 2024 10:49:38 +0200 Subject: [PATCH 06/16] Set up gazelle WORKSPACE --- gazelle/WORKSPACE | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/gazelle/WORKSPACE b/gazelle/WORKSPACE index d9f0645071..0ad6937f49 100644 --- a/gazelle/WORKSPACE +++ b/gazelle/WORKSPACE @@ -38,6 +38,10 @@ load("@rules_python//python:repositories.bzl", "py_repositories") py_repositories() +load("@rules_python//python:repositories_deps.bzl", "py_repositories_deps") + +py_repositories_deps() + load("//:deps.bzl", _py_gazelle_deps = "gazelle_deps") # gazelle:repository_macro deps.bzl%go_deps From 4aec1cbc0196bd651e7e829cab76d8ac80533147 Mon Sep 17 00:00:00 2001 From: Ivo List Date: Sat, 5 Oct 2024 10:49:46 +0200 Subject: [PATCH 07/16] Fix WORKSPACE file --- WORKSPACE | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/WORKSPACE b/WORKSPACE index 3ba6fc93cb..f4e8853136 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -18,10 +18,13 @@ workspace(name = "rules_python") # should not copy it to their WORKSPACE. load("//:internal_deps.bzl", "rules_python_internal_deps") -load("//python:py_repositories_deps.bzl", "py_repositories_rules_deps") rules_python_internal_deps() +load("//python:repositories_deps.bzl", "py_repositories_deps") + +py_repositories_deps() + load("@rules_jvm_external//:repositories.bzl", "rules_jvm_external_deps") rules_jvm_external_deps() From fc09cf69614816f65755421e881ea88900530f08 Mon Sep 17 00:00:00 2001 From: Ivo List Date: Sat, 5 Oct 2024 10:54:37 +0200 Subject: [PATCH 08/16] Add missing bazel_features bzl_library dependency --- python/BUILD.bazel | 1 + 1 file changed, 1 insertion(+) diff --git a/python/BUILD.bazel b/python/BUILD.bazel index 53fb812af6..565c986bd0 100644 --- a/python/BUILD.bazel +++ b/python/BUILD.bazel @@ -135,6 +135,7 @@ bzl_library( srcs = ["py_cc_link_params_info.bzl"], deps = [ "//python/private/common:providers_bzl", + "@bazel_features//:features", "@rules_python_internal//:rules_python_config_bzl", ], ) From 060d87e5b616f2597025ef2b8015b9e2f42d397a Mon Sep 17 00:00:00 2001 From: Ivo List Date: Sat, 5 Oct 2024 10:59:30 +0200 Subject: [PATCH 09/16] Add missing bazel_features load --- python/py_cc_link_params_info.bzl | 1 + 1 file changed, 1 insertion(+) diff --git a/python/py_cc_link_params_info.bzl b/python/py_cc_link_params_info.bzl index 27fd786268..009f45043e 100644 --- a/python/py_cc_link_params_info.bzl +++ b/python/py_cc_link_params_info.bzl @@ -1,5 +1,6 @@ """Public entry point for PyCcLinkParamsInfo.""" +load("@bazel_features//:features.bzl", "bazel_features") load("@rules_python_internal//:rules_python_config.bzl", "config") load("//python/private/common:providers.bzl", _starlark_PyCcLinkParamsProvider = "PyCcLinkParamsProvider") From 2393c5aa4000ebc670f9e6bb61ec74d4ba6854a5 Mon Sep 17 00:00:00 2001 From: Richard Levasseur Date: Mon, 7 Oct 2024 16:50:48 -0700 Subject: [PATCH 10/16] use rules_python_internal to get globals; fix a couple missed spots --- WORKSPACE | 6 +++--- python/private/common/py_runtime_rule.bzl | 2 +- python/private/internal_config_repo.bzl | 15 +++++++++++++++ python/private/py_info.bzl | 2 +- python/private/reexports.bzl | 11 +++++------ python/py_cc_link_params_info.bzl | 9 ++++++--- tests/base_rules/py_executable_base_tests.bzl | 10 +++++----- 7 files changed, 36 insertions(+), 19 deletions(-) diff --git a/WORKSPACE b/WORKSPACE index f4e8853136..77bdb41423 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -21,9 +21,9 @@ load("//:internal_deps.bzl", "rules_python_internal_deps") rules_python_internal_deps() -load("//python:repositories_deps.bzl", "py_repositories_deps") - -py_repositories_deps() +##load("//python:repositories_deps.bzl", "py_repositories_deps") +## +##py_repositories_deps() load("@rules_jvm_external//:repositories.bzl", "rules_jvm_external_deps") diff --git a/python/private/common/py_runtime_rule.bzl b/python/private/common/py_runtime_rule.bzl index 8ec860c3dd..0206402e09 100644 --- a/python/private/common/py_runtime_rule.bzl +++ b/python/private/common/py_runtime_rule.bzl @@ -132,7 +132,7 @@ def _py_runtime_impl(ctx): runfiles = runfiles, ), ] - if BuiltinPyRuntimeInfo != None: + if BuiltinPyRuntimeInfo != None and BuiltinPyRuntimeInfo != PyRuntimeInfo: # Return the builtin provider for better compatibility. # 1. There is a legacy code path in py_binary that # checks for the provider when toolchains aren't used diff --git a/python/private/internal_config_repo.bzl b/python/private/internal_config_repo.bzl index c37bc351cc..e2fa8f6af1 100644 --- a/python/private/internal_config_repo.bzl +++ b/python/private/internal_config_repo.bzl @@ -24,6 +24,9 @@ _ENABLE_PYSTAR_DEFAULT = "1" _CONFIG_TEMPLATE = """\ config = struct( enable_pystar = {enable_pystar}, + BuiltinPyInfo = getattr(getattr(native, "legacy_globals", None), "PyInfo", {builtin_py_info_symbol}), + BuiltinPyRuntimeInfo = getattr(getattr(native, "legacy_globals", None), "PyRuntimeInfo", {builtin_py_runtime_info_symbol}), + BuiltinPyCcLinkParamsProvider = getattr(getattr(native, "legacy_globals", None), "PyCcLinkParamsProvider", {builtin_py_cc_link_params_provider}), ) """ @@ -65,8 +68,20 @@ def _internal_config_repo_impl(rctx): else: enable_pystar = False + if native.bazel_version.startswith("8."): + builtin_py_info_symbol = "None" + builtin_py_runtime_info_symbol = "None" + builtin_py_cc_link_params_provider = "None" + else: + builtin_py_info_symbol = "PyInfo" + builtin_py_runtime_info_symbol = "PyRuntimeInfo" + builtin_py_cc_link_params_provider = "PyCcLinkParamsProvider" + rctx.file("rules_python_config.bzl", _CONFIG_TEMPLATE.format( enable_pystar = enable_pystar, + builtin_py_info_symbol = builtin_py_info_symbol, + builtin_py_runtime_info_symbol = builtin_py_runtime_info_symbol, + builtin_py_cc_link_params_provider = builtin_py_cc_link_params_provider, )) if enable_pystar: diff --git a/python/private/py_info.bzl b/python/private/py_info.bzl index 8ccddf8d06..d73113a0df 100644 --- a/python/private/py_info.bzl +++ b/python/private/py_info.bzl @@ -118,7 +118,7 @@ This field is currently unused in Bazel and may go away in the future. ) # The "effective" PyInfo is what the canonical //python:py_info.bzl%PyInfo symbol refers to -_EffectivePyInfo = PyInfo if config.enable_pystar or BuiltinPyInfo == None else BuiltinPyInfo +_EffectivePyInfo = PyInfo if (config.enable_pystar or BuiltinPyInfo == None) else BuiltinPyInfo def PyInfoBuilder(): # buildifier: disable=uninitialized diff --git a/python/private/reexports.bzl b/python/private/reexports.bzl index 1be2ec0279..e9d2ded33e 100644 --- a/python/private/reexports.bzl +++ b/python/private/reexports.bzl @@ -30,13 +30,12 @@ inaccessible. So instead we access the builtin here and export it under a different name. Then we can load it from elsewhere. """ -load("@bazel_features//:features.bzl", "bazel_features") +load("@rules_python_internal//:rules_python_config.bzl", "config") -# Don't use underscore prefix, since that would make the symbol local to this -# file only. Use a non-conventional name to emphasize that this is not a public -# symbol. +# NOTE: May be None (Bazel 8 autoloading rules_python) # buildifier: disable=name-conventions -BuiltinPyInfo = getattr(bazel_features.globals, "PyInfo", None) +BuiltinPyInfo = config.BuiltinPyInfo +# NOTE: May be None (Bazel 8 autoloading rules_python) # buildifier: disable=name-conventions -BuiltinPyRuntimeInfo = getattr(bazel_features.globals, "PyRuntimeInfo", None) +BuiltinPyRuntimeInfo = config.BuiltinPyRuntimeInfo diff --git a/python/py_cc_link_params_info.bzl b/python/py_cc_link_params_info.bzl index 009f45043e..badcaf363e 100644 --- a/python/py_cc_link_params_info.bzl +++ b/python/py_cc_link_params_info.bzl @@ -1,8 +1,11 @@ """Public entry point for PyCcLinkParamsInfo.""" -load("@bazel_features//:features.bzl", "bazel_features") load("@rules_python_internal//:rules_python_config.bzl", "config") load("//python/private/common:providers.bzl", _starlark_PyCcLinkParamsProvider = "PyCcLinkParamsProvider") -_PyCcLinkParamsProvider = getattr(bazel_features.globals, "PyCcLinkParamsProvider", None) # buildifier: disable=name-conventions -PyCcLinkParamsInfo = _starlark_PyCcLinkParamsProvider if config.enable_pystar or _PyCcLinkParamsProvider == None else PyCcLinkParamsProvider +PyCcLinkParamsInfo = ( + _starlark_PyCcLinkParamsProvider if ( + config.enable_pystar or config.BuiltinPyCcLinkParamsProvider == None + ) else config.BuiltinPyCcLinkParamsProvider +) +print(native.legacy_globals) diff --git a/tests/base_rules/py_executable_base_tests.bzl b/tests/base_rules/py_executable_base_tests.bzl index 873349f289..07c7d672a3 100644 --- a/tests/base_rules/py_executable_base_tests.bzl +++ b/tests/base_rules/py_executable_base_tests.bzl @@ -19,14 +19,13 @@ load("@rules_testing//lib:analysis_test.bzl", "analysis_test") load("@rules_testing//lib:truth.bzl", "matching") load("@rules_testing//lib:util.bzl", rt_util = "util") load("//python:py_executable_info.bzl", "PyExecutableInfo") +load("//python/private:reexports.bzl", "BuiltinPyRuntimeInfo") load("//python/private:util.bzl", "IS_BAZEL_7_OR_HIGHER") # buildifier: disable=bzl-visibility load("//tests/base_rules:base_tests.bzl", "create_base_tests") load("//tests/base_rules:util.bzl", "WINDOWS_ATTR", pt_util = "util") load("//tests/support:py_executable_info_subject.bzl", "PyExecutableInfoSubject") load("//tests/support:support.bzl", "CC_TOOLCHAIN", "CROSSTOOL_TOP", "LINUX_X86_64", "WINDOWS_X86_64") -_BuiltinPyRuntimeInfo = PyRuntimeInfo - _tests = [] def _test_basic_windows(name, config): @@ -359,9 +358,10 @@ def _test_py_runtime_info_provided_impl(env, target): # Make sure that the rules_python loaded symbol is provided. env.expect.that_target(target).has_provider(RulesPythonPyRuntimeInfo) - # For compatibility during the transition, the builtin PyRuntimeInfo should - # also be provided. - env.expect.that_target(target).has_provider(_BuiltinPyRuntimeInfo) + if BuiltinPyRuntimeInfo != None: + # For compatibility during the transition, the builtin PyRuntimeInfo should + # also be provided. + env.expect.that_target(target).has_provider(BuiltinPyRuntimeInfo) _tests.append(_test_py_runtime_info_provided) From 3830f7467c61d9896d05152c665d3ca6888c5e6d Mon Sep 17 00:00:00 2001 From: Richard Levasseur Date: Mon, 7 Oct 2024 18:29:50 -0700 Subject: [PATCH 11/16] remove py_repositories_deps --- WORKSPACE | 4 ---- examples/build_file_generation/WORKSPACE | 4 ---- examples/multi_python_versions/WORKSPACE | 4 ---- examples/pip_parse/WORKSPACE | 4 ---- examples/pip_parse_vendored/WORKSPACE | 4 ---- examples/pip_repository_annotations/WORKSPACE | 4 ---- examples/py_proto_library/WORKSPACE | 4 ---- gazelle/WORKSPACE | 4 ---- python/repositories_deps.bzl | 6 ------ tests/integration/compile_pip_requirements/WORKSPACE | 4 ---- .../WORKSPACE | 4 ---- tests/integration/custom_commands/WORKSPACE | 4 ---- tests/integration/ignore_root_user_error/WORKSPACE | 4 ---- tests/integration/pip_parse/WORKSPACE | 4 ---- tests/integration/py_cc_toolchain_registered/WORKSPACE | 6 ------ 15 files changed, 64 deletions(-) delete mode 100644 python/repositories_deps.bzl diff --git a/WORKSPACE b/WORKSPACE index 77bdb41423..02b3b6e926 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -21,10 +21,6 @@ load("//:internal_deps.bzl", "rules_python_internal_deps") rules_python_internal_deps() -##load("//python:repositories_deps.bzl", "py_repositories_deps") -## -##py_repositories_deps() - load("@rules_jvm_external//:repositories.bzl", "rules_jvm_external_deps") rules_jvm_external_deps() diff --git a/examples/build_file_generation/WORKSPACE b/examples/build_file_generation/WORKSPACE index 50426daaa7..3f1fad8a8d 100644 --- a/examples/build_file_generation/WORKSPACE +++ b/examples/build_file_generation/WORKSPACE @@ -76,10 +76,6 @@ load("@rules_python//python:repositories.bzl", "py_repositories", "python_regist # Perform general setup py_repositories() -load("@rules_python//python:repositories_deps.bzl", "py_repositories_deps") - -py_repositories_deps() - # We now register a hermetic Python interpreter rather than relying on a system-installed interpreter. # This toolchain will allow bazel to download a specific python version, and use that version # for compilation. diff --git a/examples/multi_python_versions/WORKSPACE b/examples/multi_python_versions/WORKSPACE index 705022b2ef..4f731d95a8 100644 --- a/examples/multi_python_versions/WORKSPACE +++ b/examples/multi_python_versions/WORKSPACE @@ -9,10 +9,6 @@ load("@rules_python//python:repositories.bzl", "py_repositories", "python_regist py_repositories() -load("@rules_python//python:repositories_deps.bzl", "py_repositories_deps") - -py_repositories_deps() - default_python_version = "3.9" python_register_multi_toolchains( diff --git a/examples/pip_parse/WORKSPACE b/examples/pip_parse/WORKSPACE index b11313dc90..bb4714d941 100644 --- a/examples/pip_parse/WORKSPACE +++ b/examples/pip_parse/WORKSPACE @@ -9,10 +9,6 @@ load("@rules_python//python:repositories.bzl", "py_repositories", "python_regist py_repositories() -load("@rules_python//python:repositories_deps.bzl", "py_repositories_deps") - -py_repositories_deps() - python_register_toolchains( name = "python_3_9", python_version = "3.9.13", diff --git a/examples/pip_parse_vendored/WORKSPACE b/examples/pip_parse_vendored/WORKSPACE index 1981f93890..d7a11ea596 100644 --- a/examples/pip_parse_vendored/WORKSPACE +++ b/examples/pip_parse_vendored/WORKSPACE @@ -9,10 +9,6 @@ load("@rules_python//python:repositories.bzl", "py_repositories", "python_regist py_repositories() -load("@rules_python//python:repositories_deps.bzl", "py_repositories_deps") - -py_repositories_deps() - python_register_toolchains( name = "python39", python_version = "3.9", diff --git a/examples/pip_repository_annotations/WORKSPACE b/examples/pip_repository_annotations/WORKSPACE index 1b325a0a49..8540555084 100644 --- a/examples/pip_repository_annotations/WORKSPACE +++ b/examples/pip_repository_annotations/WORKSPACE @@ -9,10 +9,6 @@ load("@rules_python//python:repositories.bzl", "py_repositories", "python_regist py_repositories() -load("@rules_python//python:repositories_deps.bzl", "py_repositories_deps") - -py_repositories_deps() - python_register_toolchains( name = "python39", python_version = "3.9", diff --git a/examples/py_proto_library/WORKSPACE b/examples/py_proto_library/WORKSPACE index 3f1c146ddb..81f189dbbf 100644 --- a/examples/py_proto_library/WORKSPACE +++ b/examples/py_proto_library/WORKSPACE @@ -16,10 +16,6 @@ load("@rules_python//python:repositories.bzl", "py_repositories", "python_regist # We install the rules_python dependencies using the function below. py_repositories() -load("@rules_python//python:repositories_deps.bzl", "py_repositories_deps") - -py_repositories_deps() - python_register_toolchains( name = "python39", python_version = "3.9", diff --git a/gazelle/WORKSPACE b/gazelle/WORKSPACE index 0ad6937f49..d9f0645071 100644 --- a/gazelle/WORKSPACE +++ b/gazelle/WORKSPACE @@ -38,10 +38,6 @@ load("@rules_python//python:repositories.bzl", "py_repositories") py_repositories() -load("@rules_python//python:repositories_deps.bzl", "py_repositories_deps") - -py_repositories_deps() - load("//:deps.bzl", _py_gazelle_deps = "gazelle_deps") # gazelle:repository_macro deps.bzl%go_deps diff --git a/python/repositories_deps.bzl b/python/repositories_deps.bzl deleted file mode 100644 index 1cc60e5bab..0000000000 --- a/python/repositories_deps.bzl +++ /dev/null @@ -1,6 +0,0 @@ -"""Sets up rules_python repository deps for WORKSPACE users""" - -load("@bazel_features//:deps.bzl", "bazel_features_deps") - -def py_repositories_deps(): - bazel_features_deps() diff --git a/tests/integration/compile_pip_requirements/WORKSPACE b/tests/integration/compile_pip_requirements/WORKSPACE index 3317cc4fb7..0eeab2067c 100644 --- a/tests/integration/compile_pip_requirements/WORKSPACE +++ b/tests/integration/compile_pip_requirements/WORKSPACE @@ -7,10 +7,6 @@ load("@rules_python//python:repositories.bzl", "py_repositories", "python_regist py_repositories() -load("@rules_python//python:repositories_deps.bzl", "py_repositories_deps") - -py_repositories_deps() - python_register_toolchains( name = "python39", python_version = "3.9", diff --git a/tests/integration/compile_pip_requirements_test_from_external_repo/WORKSPACE b/tests/integration/compile_pip_requirements_test_from_external_repo/WORKSPACE index e2dc4cafc5..48caeb442f 100644 --- a/tests/integration/compile_pip_requirements_test_from_external_repo/WORKSPACE +++ b/tests/integration/compile_pip_requirements_test_from_external_repo/WORKSPACE @@ -7,10 +7,6 @@ load("@rules_python//python:repositories.bzl", "py_repositories", "python_regist py_repositories() -load("@rules_python//python:repositories_deps.bzl", "py_repositories_deps") - -py_repositories_deps() - python_register_toolchains( name = "python39", python_version = "3.9", diff --git a/tests/integration/custom_commands/WORKSPACE b/tests/integration/custom_commands/WORKSPACE index 579da8accc..de908549c0 100644 --- a/tests/integration/custom_commands/WORKSPACE +++ b/tests/integration/custom_commands/WORKSPACE @@ -7,10 +7,6 @@ load("@rules_python//python:repositories.bzl", "py_repositories", "python_regist py_repositories() -load("@rules_python//python:repositories_deps.bzl", "py_repositories_deps") - -py_repositories_deps() - python_register_toolchains( name = "python_3_11", python_version = "3.11", diff --git a/tests/integration/ignore_root_user_error/WORKSPACE b/tests/integration/ignore_root_user_error/WORKSPACE index 93b53f3bd9..c21b01e1bc 100644 --- a/tests/integration/ignore_root_user_error/WORKSPACE +++ b/tests/integration/ignore_root_user_error/WORKSPACE @@ -7,10 +7,6 @@ load("@rules_python//python:repositories.bzl", "py_repositories", "python_regist py_repositories() -load("@rules_python//python:repositories_deps.bzl", "py_repositories_deps") - -py_repositories_deps() - python_register_toolchains( name = "python39", ignore_root_user_error = True, diff --git a/tests/integration/pip_parse/WORKSPACE b/tests/integration/pip_parse/WORKSPACE index fb273e0371..db0cd0c7c8 100644 --- a/tests/integration/pip_parse/WORKSPACE +++ b/tests/integration/pip_parse/WORKSPACE @@ -7,10 +7,6 @@ load("@rules_python//python:repositories.bzl", "py_repositories", "python_regist py_repositories() -load("@rules_python//python:repositories_deps.bzl", "py_repositories_deps") - -py_repositories_deps() - # This call is included in `py_repositories` and we are calling # `pip_install_dependencies` only to ensure that we are not breaking really old # code. diff --git a/tests/integration/py_cc_toolchain_registered/WORKSPACE b/tests/integration/py_cc_toolchain_registered/WORKSPACE index c1f8da254b..de908549c0 100644 --- a/tests/integration/py_cc_toolchain_registered/WORKSPACE +++ b/tests/integration/py_cc_toolchain_registered/WORKSPACE @@ -7,12 +7,6 @@ load("@rules_python//python:repositories.bzl", "py_repositories", "python_regist py_repositories() -load("@rules_python//python:repositories_deps.bzl", "py_repositories_deps") - -py_repositories_deps() - -py_repositories_deps() - python_register_toolchains( name = "python_3_11", python_version = "3.11", From dbdf16fb49356cc4a51fa392514097fe09af9ad0 Mon Sep 17 00:00:00 2001 From: Richard Levasseur Date: Mon, 7 Oct 2024 18:33:52 -0700 Subject: [PATCH 12/16] cleanup bzl_library deps, remove print --- python/BUILD.bazel | 1 - python/private/BUILD.bazel | 2 +- python/py_cc_link_params_info.bzl | 1 - 3 files changed, 1 insertion(+), 3 deletions(-) diff --git a/python/BUILD.bazel b/python/BUILD.bazel index 565c986bd0..53fb812af6 100644 --- a/python/BUILD.bazel +++ b/python/BUILD.bazel @@ -135,7 +135,6 @@ bzl_library( srcs = ["py_cc_link_params_info.bzl"], deps = [ "//python/private/common:providers_bzl", - "@bazel_features//:features", "@rules_python_internal//:rules_python_config_bzl", ], ) diff --git a/python/private/BUILD.bazel b/python/private/BUILD.bazel index adaef4c1b0..f9a7132631 100644 --- a/python/private/BUILD.bazel +++ b/python/private/BUILD.bazel @@ -343,7 +343,7 @@ bzl_library( ], deps = [ ":bazel_tools_bzl", - "@bazel_features//:features", + "@rules_python_internal//:rules_python_config_bzl", ], ) diff --git a/python/py_cc_link_params_info.bzl b/python/py_cc_link_params_info.bzl index badcaf363e..b0ad0a79d2 100644 --- a/python/py_cc_link_params_info.bzl +++ b/python/py_cc_link_params_info.bzl @@ -8,4 +8,3 @@ PyCcLinkParamsInfo = ( config.enable_pystar or config.BuiltinPyCcLinkParamsProvider == None ) else config.BuiltinPyCcLinkParamsProvider ) -print(native.legacy_globals) From 12a465bd10ca87d5d0bf85fbb1a4e5e939190654 Mon Sep 17 00:00:00 2001 From: Richard Levasseur Date: Mon, 7 Oct 2024 18:35:09 -0700 Subject: [PATCH 13/16] fixup: disable buildifier warning --- tests/base_rules/py_executable_base_tests.bzl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/base_rules/py_executable_base_tests.bzl b/tests/base_rules/py_executable_base_tests.bzl index 07c7d672a3..3cc6dfb702 100644 --- a/tests/base_rules/py_executable_base_tests.bzl +++ b/tests/base_rules/py_executable_base_tests.bzl @@ -19,7 +19,7 @@ load("@rules_testing//lib:analysis_test.bzl", "analysis_test") load("@rules_testing//lib:truth.bzl", "matching") load("@rules_testing//lib:util.bzl", rt_util = "util") load("//python:py_executable_info.bzl", "PyExecutableInfo") -load("//python/private:reexports.bzl", "BuiltinPyRuntimeInfo") +load("//python/private:reexports.bzl", "BuiltinPyRuntimeInfo") # buildifier: disable=bzl-visibility load("//python/private:util.bzl", "IS_BAZEL_7_OR_HIGHER") # buildifier: disable=bzl-visibility load("//tests/base_rules:base_tests.bzl", "create_base_tests") load("//tests/base_rules:util.bzl", "WINDOWS_ATTR", pt_util = "util") From 852da78354a6cc76dae2b66b977a8d20be08fa20 Mon Sep 17 00:00:00 2001 From: Richard Levasseur Date: Mon, 7 Oct 2024 19:39:59 -0700 Subject: [PATCH 14/16] fix cases where builtin py info is none --- python/private/common/py_executable.bzl | 3 ++- python/private/common/py_library.bzl | 6 ++++-- python/private/py_info.bzl | 3 +++ tests/base_rules/py_info/py_info_tests.bzl | 3 ++- 4 files changed, 11 insertions(+), 4 deletions(-) diff --git a/python/private/common/py_executable.bzl b/python/private/common/py_executable.bzl index 04c0cae3bb..cfd9961606 100644 --- a/python/private/common/py_executable.bzl +++ b/python/private/common/py_executable.bzl @@ -890,7 +890,8 @@ def _create_providers( ) providers.append(py_info) - providers.append(builtin_py_info) + if builtin_py_info: + providers.append(builtin_py_info) providers.append(create_output_group_info(py_info.transitive_sources, output_groups)) extra_providers = semantics.get_extra_providers( diff --git a/python/private/common/py_library.bzl b/python/private/common/py_library.bzl index 4423986e1b..078626e063 100644 --- a/python/private/common/py_library.bzl +++ b/python/private/common/py_library.bzl @@ -98,14 +98,16 @@ def py_library_impl(ctx, *, semantics): dependency_transitive_python_sources = deps_transitive_sources, ) - return [ + providers = [ DefaultInfo(files = default_outputs, runfiles = runfiles), py_info, - builtins_py_info, create_instrumented_files_info(ctx), PyCcLinkParamsProvider(cc_info = cc_info), create_output_group_info(py_info.transitive_sources, extra_groups = {}), ] + if builtins_py_info: + providers.append(builtins_py_info) + return providers _DEFAULT_PY_LIBRARY_DOC = """ A library of Python code that can be depended upon. diff --git a/python/private/py_info.bzl b/python/private/py_info.bzl index d73113a0df..787e7a6cd4 100644 --- a/python/private/py_info.bzl +++ b/python/private/py_info.bzl @@ -229,6 +229,9 @@ def _PyInfoBuilder_build(self): ) def _PyInfoBuilder_build_builtin_py_info(self): + if BuiltinPyInfo == None: + return None + return BuiltinPyInfo( has_py2_only_sources = self._has_py2_only_sources[0], has_py3_only_sources = self._has_py3_only_sources[0], diff --git a/tests/base_rules/py_info/py_info_tests.bzl b/tests/base_rules/py_info/py_info_tests.bzl index b64263f6ba..cf8ffdc3eb 100644 --- a/tests/base_rules/py_info/py_info_tests.bzl +++ b/tests/base_rules/py_info/py_info_tests.bzl @@ -179,7 +179,8 @@ def _test_py_info_builder_impl(env, targets): ]) check(builder.build()) - check(builder.build_builtin_py_info()) + if BuiltinPyInfo != None: + check(builder.build_builtin_py_info()) builder.set_has_py2_only_sources(False) builder.set_has_py3_only_sources(False) From ef094521f79f69d69cee0fa6a079b2579bd7cf53 Mon Sep 17 00:00:00 2001 From: Richard Levasseur Date: Mon, 7 Oct 2024 20:23:01 -0700 Subject: [PATCH 15/16] revert adding bazel_features dep --- MODULE.bazel | 2 +- internal_deps.bzl | 6 +++--- python/private/py_repositories.bzl | 6 ------ 3 files changed, 4 insertions(+), 10 deletions(-) diff --git a/MODULE.bazel b/MODULE.bazel index 9d539d1949..58c7ae229b 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -4,7 +4,7 @@ module( compatibility_level = 1, ) -bazel_dep(name = "bazel_features", version = "1.18.0") +bazel_dep(name = "bazel_features", version = "1.9.1") bazel_dep(name = "bazel_skylib", version = "1.6.1") bazel_dep(name = "rules_cc", version = "0.0.9") bazel_dep(name = "platforms", version = "0.0.4") diff --git a/internal_deps.bzl b/internal_deps.bzl index e75d782fc9..56962cbd19 100644 --- a/internal_deps.bzl +++ b/internal_deps.bzl @@ -212,9 +212,9 @@ def rules_python_internal_deps(): http_archive( name = "bazel_features", - sha256 = "b4b145c19e08fd48337f53c383db46398d0a810002907ff0c590762d926e05be", - strip_prefix = "bazel_features-1.18.0", - url = "https://github.com/bazel-contrib/bazel_features/releases/download/v1.18.0/bazel_features-v1.18.0.tar.gz", + sha256 = "d7787da289a7fb497352211ad200ec9f698822a9e0757a4976fd9f713ff372b3", + strip_prefix = "bazel_features-1.9.1", + url = "https://github.com/bazel-contrib/bazel_features/releases/download/v1.9.1/bazel_features-v1.9.1.tar.gz", ) http_archive( diff --git a/python/private/py_repositories.bzl b/python/private/py_repositories.bzl index a1ada7cbed..ff8a6389ba 100644 --- a/python/private/py_repositories.bzl +++ b/python/private/py_repositories.bzl @@ -59,10 +59,4 @@ def py_repositories(): sha256 = "2037875b9a4456dce4a79d112a8ae885bbc4aad968e6587dca6e64f3a0900cdf", strip_prefix = "rules_cc-0.0.9", ) - http_archive( - name = "bazel_features", - sha256 = "b4b145c19e08fd48337f53c383db46398d0a810002907ff0c590762d926e05be", - strip_prefix = "bazel_features-1.18.0", - url = "https://github.com/bazel-contrib/bazel_features/releases/download/v1.18.0/bazel_features-v1.18.0.tar.gz", - ) pypi_deps() From f139c51d06f773716e6c67ab0ad81842c3dc6fbd Mon Sep 17 00:00:00 2001 From: Richard Levasseur Date: Tue, 8 Oct 2024 10:49:09 -0700 Subject: [PATCH 16/16] update module lockfile --- examples/bzlmod/MODULE.bazel.lock | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/examples/bzlmod/MODULE.bazel.lock b/examples/bzlmod/MODULE.bazel.lock index 8aff89ec17..11e63af6e9 100644 --- a/examples/bzlmod/MODULE.bazel.lock +++ b/examples/bzlmod/MODULE.bazel.lock @@ -10,13 +10,14 @@ "https://bcr.bazel.build/modules/apple_support/1.5.0/MODULE.bazel": "50341a62efbc483e8a2a6aec30994a58749bd7b885e18dd96aa8c33031e558ef", "https://bcr.bazel.build/modules/apple_support/1.5.0/source.json": "eb98a7627c0bc486b57f598ad8da50f6625d974c8f723e9ea71bd39f709c9862", "https://bcr.bazel.build/modules/bazel_features/1.11.0/MODULE.bazel": "f9382337dd5a474c3b7d334c2f83e50b6eaedc284253334cf823044a26de03e8", - "https://bcr.bazel.build/modules/bazel_features/1.18.0/MODULE.bazel": "1be0ae2557ab3a72a57aeb31b29be347bcdc5d2b1eb1e70f39e3851a7e97041a", - "https://bcr.bazel.build/modules/bazel_features/1.18.0/source.json": "cde886d88c8164b50b9b97dba7c0a64ca24d257b72ca3a2fcb06bee1fdb47ee4", + "https://bcr.bazel.build/modules/bazel_features/1.11.0/source.json": "c9320aa53cd1c441d24bd6b716da087ad7e4ff0d9742a9884587596edfe53015", + "https://bcr.bazel.build/modules/bazel_features/1.9.1/MODULE.bazel": "8f679097876a9b609ad1f60249c49d68bfab783dd9be012faf9d82547b14815a", "https://bcr.bazel.build/modules/bazel_skylib/1.0.3/MODULE.bazel": "bcb0fd896384802d1ad283b4e4eb4d718eebd8cb820b0a2c3a347fb971afd9d8", "https://bcr.bazel.build/modules/bazel_skylib/1.2.0/MODULE.bazel": "44fe84260e454ed94ad326352a698422dbe372b21a1ac9f3eab76eb531223686", "https://bcr.bazel.build/modules/bazel_skylib/1.2.1/MODULE.bazel": "f35baf9da0efe45fa3da1696ae906eea3d615ad41e2e3def4aeb4e8bc0ef9a7a", "https://bcr.bazel.build/modules/bazel_skylib/1.3.0/MODULE.bazel": "20228b92868bf5cfc41bda7afc8a8ba2a543201851de39d990ec957b513579c5", "https://bcr.bazel.build/modules/bazel_skylib/1.4.1/MODULE.bazel": "a0dcb779424be33100dcae821e9e27e4f2901d9dfd5333efe5ac6a8d7ab75e1d", + "https://bcr.bazel.build/modules/bazel_skylib/1.5.0/MODULE.bazel": "32880f5e2945ce6a03d1fbd588e9198c0a959bb42297b2cfaf1685b7bc32e138", "https://bcr.bazel.build/modules/bazel_skylib/1.6.1/MODULE.bazel": "8fdee2dbaace6c252131c00e1de4b165dc65af02ea278476187765e1a617b917", "https://bcr.bazel.build/modules/bazel_skylib/1.6.1/source.json": "082ed5f9837901fada8c68c2f3ddc958bb22b6d654f71dd73f3df30d45d4b749", "https://bcr.bazel.build/modules/buildozer/7.1.2/MODULE.bazel": "2e8dd40ede9c454042645fd8d8d0cd1527966aa5c919de86661e62953cd73d84", @@ -1230,7 +1231,7 @@ }, "@@rules_python~//python/extensions:pip.bzl%pip": { "general": { - "bzlTransitiveDigest": "4lUj1TkJdZDIeU5gj4x+CPLc/YPIPmllR6JcmB2b0wY=", + "bzlTransitiveDigest": "SY5Kzq6Z7CG9q0dbCVrOHK8FFnVC6YTXBqGE4ZfNNbo=", "usagesDigest": "MChlcSw99EuW3K7OOoMcXQIdcJnEh6YmfyjJm+9mxIg=", "recordedFileInputs": { "@@other_module~//requirements_lock_3_11.txt": "a7d0061366569043d5efcf80e34a32c732679367cb3c831c4cdc606adc36d314", @@ -6137,7 +6138,7 @@ }, "@@rules_python~//python/private/pypi:pip.bzl%pip_internal": { "general": { - "bzlTransitiveDigest": "tnRMaTW/8XjBqR/9zHkS6YVvAGjmBTbJSuZHQOASLE0=", + "bzlTransitiveDigest": "BLXk2JiegzzGfis5XuIaAVMg5WUUhmsofn99NgeBDEQ=", "usagesDigest": "Y8ihY+R57BAFhalrVLVdJFrpwlbsiKz9JPJ99ljF7HA=", "recordedFileInputs": { "@@rules_python~//tools/publish/requirements.txt": "031e35d03dde03ae6305fe4b3d1f58ad7bdad857379752deede0f93649991b8a",