Skip to content
Merged
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
7 changes: 2 additions & 5 deletions docs/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
load("@bazel_skylib//rules:build_test.bzl", "build_test")
load("@dev_pip//:requirements.bzl", "requirement")
load("//python/private:bzlmod_enabled.bzl", "BZLMOD_ENABLED") # buildifier: disable=bzl-visibility
load("//python/private:util.bzl", "IS_BAZEL_7_OR_HIGHER") # buildifier: disable=bzl-visibility
load("//python/uv:lock.bzl", "lock") # buildifier: disable=bzl-visibility
load("//sphinxdocs:readthedocs.bzl", "readthedocs_install")
load("//sphinxdocs:sphinx.bzl", "sphinx_build_binary", "sphinx_docs")
Expand Down Expand Up @@ -107,6 +106,7 @@ sphinx_stardocs(
"//python/cc:py_cc_toolchain_bzl",
"//python/cc:py_cc_toolchain_info_bzl",
"//python/entry_points:py_console_script_binary_bzl",
"//python/extensions:python_bzl",
"//python/local_toolchains:repos_bzl",
"//python/private:attr_builders_bzl",
"//python/private:builders_util_bzl",
Expand All @@ -128,12 +128,9 @@ sphinx_stardocs(
"//python/uv:uv_toolchain_bzl",
"//python/uv:uv_toolchain_info_bzl",
] + ([
# Bazel 6 + Stardoc isn't able to parse something about the python bzlmod extension
"//python/extensions:python_bzl",
] if IS_BAZEL_7_OR_HIGHER else []) + ([
# This depends on @pythons_hub, which is only created under bzlmod,
"//python/extensions:pip_bzl",
] if IS_BAZEL_7_OR_HIGHER and BZLMOD_ENABLED else []),
] if BZLMOD_ENABLED else []),
prefix = "api/rules_python/",
tags = ["docs"],
target_compatible_with = _TARGET_COMPATIBLE_WITH,
Expand Down
18 changes: 4 additions & 14 deletions examples/bzlmod/other_module/MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,10 @@ module(
# This module is using the same version of rules_python
# that the parent module uses.
bazel_dep(name = "rules_python", version = "")

# The story behind this commented out override:
# This override is necessary to generate/update the requirements file
# for this module. This is because running it via the outer
# module doesn't work -- the `requirements.update` target can't find
# the correct file to update.
# Running in the submodule itself works, but submodules using overrides
# is considered an error until Bazel 6.3, which prevents the outer module
# from depending on this module.
# So until 6.3 and higher is the minimum, we leave this commented out.
# local_path_override(
# module_name = "rules_python",
# path = "../../..",
# )
local_path_override(
module_name = "rules_python",
path = "../../..",
)

PYTHON_NAME_39 = "python_3_9"

Expand Down
17 changes: 0 additions & 17 deletions python/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,6 @@ bzl_library(
bzl_library(
name = "features_bzl",
srcs = ["features.bzl"],
deps = [
"@rules_python_internal//:rules_python_config_bzl",
],
)

bzl_library(
Expand Down Expand Up @@ -130,8 +127,6 @@ bzl_library(
deps = [
"//python/private:py_binary_macro_bzl",
"//python/private:register_extension_info_bzl",
"//python/private:util_bzl",
"@rules_python_internal//:rules_python_config_bzl",
],
)

Expand All @@ -140,7 +135,6 @@ bzl_library(
srcs = ["py_cc_link_params_info.bzl"],
deps = [
"//python/private:py_cc_link_params_info_bzl",
"@rules_python_internal//:rules_python_config_bzl",
],
)

Expand Down Expand Up @@ -173,8 +167,6 @@ bzl_library(
srcs = ["py_info.bzl"],
deps = [
"//python/private:py_info_bzl",
"//python/private:reexports_bzl",
"@rules_python_internal//:rules_python_config_bzl",
],
)

Expand All @@ -184,8 +176,6 @@ bzl_library(
deps = [
"//python/private:py_library_macro_bzl",
"//python/private:register_extension_info_bzl",
"//python/private:util_bzl",
"@rules_python_internal//:rules_python_config_bzl",
],
)

Expand All @@ -194,17 +184,14 @@ bzl_library(
srcs = ["py_runtime.bzl"],
deps = [
"//python/private:py_runtime_macro_bzl",
"//python/private:util_bzl",
],
)

bzl_library(
name = "py_runtime_pair_bzl",
srcs = ["py_runtime_pair.bzl"],
deps = [
"//python/private:bazel_tools_bzl",
"//python/private:py_runtime_pair_macro_bzl",
"//python/private:util_bzl",
],
)

Expand All @@ -213,8 +200,6 @@ bzl_library(
srcs = ["py_runtime_info.bzl"],
deps = [
"//python/private:py_runtime_info_bzl",
"//python/private:reexports_bzl",
"@rules_python_internal//:rules_python_config_bzl",
],
)

Expand All @@ -224,8 +209,6 @@ bzl_library(
deps = [
"//python/private:py_test_macro_bzl",
"//python/private:register_extension_info_bzl",
"//python/private:util_bzl",
"@rules_python_internal//:rules_python_config_bzl",
],
)

Expand Down
4 changes: 1 addition & 3 deletions python/features.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
# limitations under the License.
"""Allows detecting of rules_python features that aren't easily detected."""

load("@rules_python_internal//:rules_python_config.bzl", "config")

# This is a magic string expanded by `git archive`, as set by `.gitattributes`
# See https://git-scm.com/docs/git-archive/2.29.0#Documentation/git-archive.txt-export-subst
_VERSION_PRIVATE = "$Format:%(describe:tags=true)$"
Expand Down Expand Up @@ -73,6 +71,6 @@ features = struct(
headers_abi3 = True,
precompile = True,
py_info_venv_symlinks = True,
uses_builtin_rules = not config.enable_pystar,
uses_builtin_rules = False,
version = _VERSION_PRIVATE if "$Format" not in _VERSION_PRIVATE else "",
)
12 changes: 0 additions & 12 deletions python/private/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -194,12 +194,6 @@ bzl_library(
srcs = ["full_version.bzl"],
)

bzl_library(
name = "glob_excludes_bzl",
srcs = ["glob_excludes.bzl"],
deps = [":util_bzl"],
)

bzl_library(
name = "internal_config_repo_bzl",
srcs = ["internal_config_repo.bzl"],
Expand Down Expand Up @@ -264,7 +258,6 @@ bzl_library(
":pythons_hub_bzl",
":repo_utils_bzl",
":toolchains_repo_bzl",
":util_bzl",
":version_bzl",
"@bazel_features//:features",
],
Expand Down Expand Up @@ -440,8 +433,6 @@ bzl_library(
deps = [
":builders_bzl",
":reexports_bzl",
":util_bzl",
"@rules_python_internal//:rules_python_config_bzl",
],
)

Expand Down Expand Up @@ -506,7 +497,6 @@ bzl_library(
bzl_library(
name = "py_runtime_info_bzl",
srcs = ["py_runtime_info.bzl"],
deps = [":util_bzl"],
)

bzl_library(
Expand Down Expand Up @@ -538,7 +528,6 @@ bzl_library(
":py_runtime_info_bzl",
":reexports_bzl",
":rule_builders_bzl",
":util_bzl",
"@bazel_skylib//lib:dicts",
"@bazel_skylib//lib:paths",
"@bazel_skylib//rules:common_settings",
Expand Down Expand Up @@ -688,7 +677,6 @@ bzl_library(
],
deps = [
"@bazel_skylib//lib:types",
"@rules_python_internal//:rules_python_config_bzl",
],
)

Expand Down
32 changes: 0 additions & 32 deletions python/private/glob_excludes.bzl

This file was deleted.

3 changes: 1 addition & 2 deletions python/private/hermetic_runtime_repo_setup.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ load("@rules_cc//cc:cc_library.bzl", "cc_library")
load("//python:py_runtime.bzl", "py_runtime")
load("//python:py_runtime_pair.bzl", "py_runtime_pair")
load("//python/cc:py_cc_toolchain.bzl", "py_cc_toolchain")
load(":glob_excludes.bzl", "glob_excludes")
load(":py_exec_tools_toolchain.bzl", "py_exec_tools_toolchain")
load(":version.bzl", "version")

Expand Down Expand Up @@ -82,7 +81,7 @@ def define_hermetic_runtime_toolchain_impl(
"lib/python{major}.{minor}*/**/tests/**".format(**version_dict),
# During pyc creation, temp files named *.pyc.NNN are created
"**/__pycache__/*.pyc.*",
] + glob_excludes.version_dependent_exclusions() + extra_files_glob_exclude,
] + extra_files_glob_exclude,
),
)
cc_import(
Expand Down
33 changes: 5 additions & 28 deletions python/private/internal_config_repo.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,12 @@ load(":repo_utils.bzl", "repo_utils")

_ENABLE_PIPSTAR_ENVVAR_NAME = "RULES_PYTHON_ENABLE_PIPSTAR"
_ENABLE_PIPSTAR_DEFAULT = "0"
_ENABLE_PYSTAR_ENVVAR_NAME = "RULES_PYTHON_ENABLE_PYSTAR"
_ENABLE_PYSTAR_DEFAULT = "1"
_ENABLE_DEPRECATION_WARNINGS_ENVVAR_NAME = "RULES_PYTHON_DEPRECATION_WARNINGS"
_ENABLE_DEPRECATION_WARNINGS_DEFAULT = "0"

_CONFIG_TEMPLATE = """
config = struct(
enable_pystar = {enable_pystar},
enable_pystar = True,
enable_pipstar = {enable_pipstar},
enable_deprecation_warnings = {enable_deprecation_warnings},
BuiltinPyInfo = getattr(getattr(native, "legacy_globals", None), "PyInfo", {builtin_py_info_symbol}),
Expand Down Expand Up @@ -88,15 +86,6 @@ _TRANSITION_SETTINGS_DEBUG_TEMPLATE = """
"""

def _internal_config_repo_impl(rctx):
pystar_requested = _bool_from_environ(rctx, _ENABLE_PYSTAR_ENVVAR_NAME, _ENABLE_PYSTAR_DEFAULT)

# Bazel 7+ (dev and later) has native.starlark_doc_extract, and thus the
# py_internal global, which are necessary for the pystar implementation.
if pystar_requested and hasattr(native, "starlark_doc_extract"):
enable_pystar = pystar_requested
else:
enable_pystar = False

if not native.bazel_version or int(native.bazel_version.split(".")[0]) >= 8:
builtin_py_info_symbol = "None"
builtin_py_runtime_info_symbol = "None"
Expand All @@ -107,31 +96,19 @@ def _internal_config_repo_impl(rctx):
builtin_py_cc_link_params_provider = "PyCcLinkParamsProvider"

rctx.file("rules_python_config.bzl", _CONFIG_TEMPLATE.format(
enable_pystar = enable_pystar,
enable_pipstar = _bool_from_environ(rctx, _ENABLE_PIPSTAR_ENVVAR_NAME, _ENABLE_PIPSTAR_DEFAULT),
enable_deprecation_warnings = _bool_from_environ(rctx, _ENABLE_DEPRECATION_WARNINGS_ENVVAR_NAME, _ENABLE_DEPRECATION_WARNINGS_DEFAULT),
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:
shim_content = _PY_INTERNAL_SHIM
py_internal_dep = '"@rules_python//tools/build_defs/python/private:py_internal_renamed_bzl"'
else:
shim_content = "py_internal_impl = None\n"
py_internal_dep = ""

# Bazel 5 doesn't support repository visibility, so just use public
# as a stand-in
if native.bazel_version.startswith("5."):
visibility = "//visibility:public"
else:
visibility = "@rules_python//:__subpackages__"
shim_content = _PY_INTERNAL_SHIM
py_internal_dep = '"@rules_python//tools/build_defs/python/private:py_internal_renamed_bzl"'

rctx.file("BUILD", ROOT_BUILD_TEMPLATE.format(
py_internal_dep = py_internal_dep,
visibility = visibility,
visibility = "@rules_python//:__subpackages__",
))
rctx.file("py_internal.bzl", shim_content)

Expand All @@ -155,7 +132,7 @@ def _internal_config_repo_impl(rctx):
internal_config_repo = repository_rule(
implementation = _internal_config_repo_impl,
configure = True,
environ = [_ENABLE_PYSTAR_ENVVAR_NAME],
environ = [_ENABLE_PIPSTAR_ENVVAR_NAME],
attrs = {
"transition_setting_generators": attr.string_list_dict(),
"transition_settings": attr.string_list(),
Expand Down
6 changes: 3 additions & 3 deletions python/private/local_runtime_repo.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def _symlink_first_library(rctx, logger, libraries):
else:
linked = "lib/{}".format(origin.basename)
logger.debug("Symlinking {} to {}".format(origin, linked))
repo_utils.watch(rctx, origin)
rctx.watch(origin)
rctx.symlink(origin, linked)
break

Expand Down Expand Up @@ -142,7 +142,7 @@ def _local_runtime_repo_impl(rctx):
# path is an error. Silently skip, since includes are only necessary
# if C extensions are built.
if include_path.exists and include_path.is_dir:
repo_utils.watch_tree(rctx, include_path)
rctx.watch_tree(include_path)
else:
pass

Expand Down Expand Up @@ -268,7 +268,7 @@ def _resolve_interpreter_path(rctx):
resolved_path = result.binary
describe_failure = result.describe_failure
else:
repo_utils.watch(rctx, rctx.attr.interpreter_path)
rctx.watch(rctx.attr.interpreter_path)
resolved_path = rctx.path(rctx.attr.interpreter_path)
if not resolved_path.exists:
describe_failure = lambda: "Path not found: {}".format(repr(rctx.attr.interpreter_path))
Expand Down
3 changes: 1 addition & 2 deletions python/private/py_cc_link_params_info.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,14 @@
"""Providers for Python rules."""

load("@rules_cc//cc/common:cc_info.bzl", "CcInfo")
load(":util.bzl", "define_bazel_6_provider")

def _PyCcLinkParamsInfo_init(cc_info):
return {
"cc_info": CcInfo(linking_context = cc_info.linking_context),
}

# buildifier: disable=name-conventions
PyCcLinkParamsInfo, _unused_raw_py_cc_link_params_provider_ctor = define_bazel_6_provider(
PyCcLinkParamsInfo, _unused_raw_py_cc_link_params_provider_ctor = provider(
doc = ("Python-wrapper to forward {obj}`CcInfo.linking_context`. This is to " +
"allow Python targets to propagate C++ linking information, but " +
"without the Python target appearing to be a valid C++ rule dependency"),
Expand Down
Loading
Loading