Skip to content
Merged
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
1c768ca
feat(pypi): enable pipstar by default on bzlmod
aignas Aug 30, 2025
10692ce
chore: cleanup bzlmod codebase after pipstar enabling
aignas Sep 7, 2025
6177306
Revert "chore: cleanup bzlmod codebase after pipstar enabling"
aignas Sep 8, 2025
b8bb5fa
enable pipstar in tests
aignas Sep 8, 2025
1194739
Merge branch 'main' into aignas.exp.bzlmod.enable.pipstar
aignas Sep 28, 2025
2ab8e3c
chore: also enable pipstar on WORKSPACE
aignas Sep 28, 2025
320b65f
pass a dummy list instead of passing dep_template
aignas Sep 28, 2025
8fc665e
a better included packages passing
aignas Sep 28, 2025
8ceeee6
actually turn the switch on for WORKSPACE
aignas Sep 28, 2025
881e6bf
fix the dep wiring in WORKSPACE
aignas Sep 28, 2025
a9e4e83
add a note
aignas Sep 28, 2025
e096244
fixup
aignas Sep 28, 2025
47b80c4
add extra docs to the changelog and adjust a bit
aignas Sep 30, 2025
162c2f4
also test what we suggest in CHANGELOG
aignas Sep 30, 2025
c8bd484
Apply suggestion from @gemini-code-assist[bot]
aignas Oct 1, 2025
e6e60ac
Update CHANGELOG.md
aignas Oct 1, 2025
a91a147
wip
aignas Oct 2, 2025
52d65dd
remove the CHANGELOG note
aignas Oct 2, 2025
e5916e7
use hub aliases repo if available: wip finish multi_pip_parse if needed
aignas Oct 2, 2025
af68cce
consolidate the config and group libraries
aignas Oct 4, 2025
a61e676
fixup
aignas Oct 4, 2025
e6f09b5
further cleanup to prepare for final review
aignas Oct 4, 2025
323cb13
extra tidyup and fixes
aignas Oct 4, 2025
5157614
deprecated is not an attr kwarg
aignas Oct 4, 2025
4b18416
fixup
aignas Oct 4, 2025
513c8bb
Merge branch 'main' into aignas.exp.bzlmod.enable.pipstar
aignas Oct 4, 2025
42fef58
clarify wording
aignas Oct 4, 2025
ff28b1b
comments
aignas Oct 5, 2025
a0e4b47
fixup! comments
aignas Oct 5, 2025
f308d07
add notes about vendoring
aignas Oct 5, 2025
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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,12 @@ END_UNRELEASED_TEMPLATE
* (bootstrap) For {obj}`--bootstrap_impl=system_python`, the sys.path order has
changed from `[app paths, stdlib, runtime site-packages]` to `[stdlib, app
paths, runtime site-packages]`.
* (pypi) `pipstar` flag has been flipped to be enabled by default, to turn it
off use `RULES_PYTHON_ENABLE_PIPSTAR=0` environment variable. If you do, please
add a comment to
[#2949](https://github.com/bazel-contrib/rules_python/issues/2949).
With this PR we are deprecating {obj}`pip.parse.experimental_target_platforms` and
{obj}`pip_repository.experimental_target_platforms`. It will be removed in the version.

{#v0-0-0-fixed}
### Fixed
Expand Down
13 changes: 9 additions & 4 deletions examples/pip_parse_vendored/requirements.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"""

load("@rules_python//python:pip.bzl", "pip_utils")
load("@rules_python//python/pip_install:pip_repository.bzl", "group_library", "whl_library")
load("@rules_python//python/pip_install:pip_repository.bzl", "whl_config_repository", "whl_library")

all_requirements = [
"@my_project_pip_deps_vendored_certifi//:pkg",
Expand Down Expand Up @@ -91,11 +91,15 @@ def install_deps(**whl_library_kwargs):
for requirement in group_requirements
}

group_repo = "my_project_pip_deps_vendored__groups"
group_library(
name = group_repo,
config_repo = "my_project_pip_deps_vendored__config"
whl_config_repository(
name = config_repo,
repo_prefix = "my_project_pip_deps_vendored_",
groups = all_requirement_groups,
whl_map = {
p: ""
for p in all_whl_requirements_by_package
},
)

# Install wheels which may be participants in a group
Expand All @@ -112,5 +116,6 @@ def install_deps(**whl_library_kwargs):
group_name = group_name,
group_deps = group_deps,
annotation = _get_annotation(requirement),
config_load = "@{}//:config.bzl".format(config_repo),
**whl_config
)
2 changes: 1 addition & 1 deletion python/pip_install/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ bzl_library(
name = "pip_repository_bzl",
srcs = ["pip_repository.bzl"],
deps = [
"//python/private/pypi:group_library_bzl",
"//python/private/pypi:package_annotation_bzl",
"//python/private/pypi:pip_repository_bzl",
"//python/private/pypi:whl_config_repository_bzl",
"//python/private/pypi:whl_library_bzl",
],
)
Expand Down
5 changes: 3 additions & 2 deletions python/pip_install/pip_repository.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@

""

load("//python/private/pypi:group_library.bzl", _group_library = "group_library")
load("//python/private/pypi:package_annotation.bzl", _package_annotation = "package_annotation")
load("//python/private/pypi:pip_repository.bzl", _pip_repository = "pip_repository")
load("//python/private/pypi:whl_config_repository.bzl", _whl_config_repository = "whl_config_repository")
load("//python/private/pypi:whl_library.bzl", _whl_library = "whl_library")

# Re-exports for backwards compatibility
group_library = _group_library
group_library = _whl_config_repository
pip_repository = _pip_repository
whl_library = _whl_library
whl_config_repository = _whl_config_repository
package_annotation = _package_annotation
2 changes: 1 addition & 1 deletion python/private/internal_config_repo.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ load("//python/private:text_util.bzl", "render")
load(":repo_utils.bzl", "repo_utils")

_ENABLE_PIPSTAR_ENVVAR_NAME = "RULES_PYTHON_ENABLE_PIPSTAR"
_ENABLE_PIPSTAR_DEFAULT = "0"
_ENABLE_PIPSTAR_DEFAULT = "1"
_ENABLE_DEPRECATION_WARNINGS_ENVVAR_NAME = "RULES_PYTHON_DEPRECATION_WARNINGS"
_ENABLE_DEPRECATION_WARNINGS_DEFAULT = "0"

Expand Down
9 changes: 9 additions & 0 deletions python/private/pypi/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,15 @@ bzl_library(
],
)

bzl_library(
name = "whl_config_repository_bzl",
srcs = ["whl_config_repository.bzl"],
deps = [
":generate_group_library_build_bazel_bzl",
"//python/private:text_util_bzl",
],
)

bzl_library(
name = "whl_config_setting_bzl",
srcs = ["whl_config_setting.bzl"],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

NOTE: This is internal `rules_python` API and if you would like to depend on it, please raise an issue
with your usecase. This may change in between rules_python versions without any notice.

@generated by rules_python pip.parse bzlmod extension.
"""

whl_map = %%WHL_MAP%%
packages = %%PACKAGES%%
19 changes: 8 additions & 11 deletions python/private/pypi/generate_whl_library_build_bazel.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ def generate_whl_library_build_bazel(
"requires",
"metadata_name",
"metadata_version",
"packages",
"include",
]
else:
Expand All @@ -82,17 +83,13 @@ def generate_whl_library_build_bazel(
"target_platforms",
"default_python_version",
]
dep_template = kwargs.get("dep_template")
loads.append(
"""load("{}", "{}")""".format(
dep_template.format(
name = "",
target = "config.bzl",
),
"whl_map",
),
)
kwargs["include"] = "whl_map"
packages_load = kwargs.pop("config_load")
if not kwargs.get("requires_dist"):
# no deps, we can leave the extra loads out
pass
else:
loads.append("""load("{}", "{}")""".format(packages_load, "packages"))
kwargs["include"] = "packages"

for arg in unsupported_args:
if kwargs.get(arg):
Expand Down
40 changes: 0 additions & 40 deletions python/private/pypi/group_library.bzl

This file was deleted.

1 change: 1 addition & 0 deletions python/private/pypi/hub_builder.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,7 @@ def _common_args(self, module_ctx, *, pip_attr):
# attrs.
whl_library_args = dict(
dep_template = "@{}//{{name}}:{{target}}".format(self.name),
config_load = "@{}//:config.bzl".format(self.name),
)
maybe_args = dict(
# The following values are safe to omit if they have false like values
Expand Down
4 changes: 2 additions & 2 deletions python/private/pypi/hub_repository.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def _impl(rctx):
"config.bzl",
rctx.attr._config_template,
substitutions = {
"%%WHL_MAP%%": render.dict(rctx.attr.whl_map, value_repr = lambda x: "None"),
"%%PACKAGES%%": render.dict(rctx.attr.whl_map, value_repr = lambda x: "None"),
},
)
rctx.template("requirements.bzl", rctx.attr._requirements_bzl_template, substitutions = {
Expand Down Expand Up @@ -100,7 +100,7 @@ in the pip.parse tag class.
""",
),
"_config_template": attr.label(
default = ":config.bzl.tmpl.bzlmod",
default = ":config.bzl.tmpl",
),
"_requirements_bzl_template": attr.label(
default = ":requirements.bzl.tmpl.bzlmod",
Expand Down
34 changes: 27 additions & 7 deletions python/private/pypi/pip_repository.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ def _pip_repository_impl(rctx):
imports = [
# NOTE: Maintain the order consistent with `buildifier`
'load("@rules_python//python:pip.bzl", "pip_utils")',
'load("@rules_python//python/pip_install:pip_repository.bzl", "group_library", "whl_library")',
'load("@rules_python//python/pip_install:pip_repository.bzl", "whl_config_repository", "whl_library")',
]

annotations = {}
Expand Down Expand Up @@ -193,7 +193,7 @@ def _pip_repository_impl(rctx):
aliases = render_pkg_aliases(
aliases = {
pkg: rctx.attr.name + "_" + pkg
for pkg in bzl_packages or []
for pkg in bzl_packages
},
extra_hub_aliases = rctx.attr.extra_hub_aliases,
requirement_cycles = requirement_cycles,
Expand All @@ -202,14 +202,31 @@ def _pip_repository_impl(rctx):
rctx.file(path, contents)

rctx.file("BUILD.bazel", _BUILD_FILE_CONTENTS)
if rctx.attr.use_hub_alias_dependencies:
rctx.template(
"config.bzl",
rctx.attr._config_template,
substitutions = {
"%%PACKAGES%%": render.dict({
pkg: None
for pkg in bzl_packages
}, value_repr = lambda x: "None"),
},
)
rctx.template("requirements.bzl", rctx.attr._template, substitutions = {
" # %%GROUP_LIBRARY%%": """\
group_repo = "{name}__groups"
group_library(
name = group_repo,
" # %%CONFIG_REPO%%": """\
config_repo = "{name}__config"
whl_config_repository(
name = config_repo,
repo_prefix = "{name}_",
groups = all_requirement_groups,
)""".format(name = rctx.attr.name) if not rctx.attr.use_hub_alias_dependencies else "",
whl_map = {{
p: ""
for p in all_whl_requirements_by_package
}},
)""".format(name = rctx.attr.name) if not rctx.attr.use_hub_alias_dependencies else """\
config_repo = "{name}"
""".format(name = rctx.attr.name),
"%%ALL_DATA_REQUIREMENTS%%": render.list([
macro_tmpl.format(p, "data")
for p in bzl_packages
Expand Down Expand Up @@ -249,6 +266,9 @@ generated using the `package_name` macro. For example usage, see [this WORKSPACE
file](https://github.com/bazel-contrib/rules_python/blob/main/examples/pip_repository_annotations/WORKSPACE).
""",
),
_config_template = attr.label(
default = ":config.bzl.tmpl",
),
_template = attr.label(
default = ":requirements.bzl.tmpl.workspace",
),
Expand Down
3 changes: 2 additions & 1 deletion python/private/pypi/requirements.bzl.tmpl.workspace
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def install_deps(**whl_library_kwargs):
for requirement in group_requirements
}

# %%GROUP_LIBRARY%%
# %%CONFIG_REPO%%

# Install wheels which may be participants in a group
whl_config = dict(_config)
Expand All @@ -68,5 +68,6 @@ def install_deps(**whl_library_kwargs):
group_name = group_name,
group_deps = group_deps,
annotation = _get_annotation(requirement),
config_load = "@{}//:config.bzl".format(config_repo),
**whl_config
)
46 changes: 46 additions & 0 deletions python/private/pypi/whl_config_repository.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
"""whl_config_library implementation for WORKSPACE setups."""

load("//python/private:text_util.bzl", "render")
load(":generate_group_library_build_bazel.bzl", "generate_group_library_build_bazel")

def _impl(rctx):
build_file_contents = generate_group_library_build_bazel(
repo_prefix = rctx.attr.repo_prefix,
groups = rctx.attr.groups,
)
rctx.file("_groups/BUILD.bazel", build_file_contents)
rctx.file("BUILD.bazel", "")
rctx.template(
"config.bzl",
rctx.attr._config_template,
substitutions = {
"%%PACKAGES%%": render.dict(rctx.attr.whl_map or {}, value_repr = lambda x: "None"),
},
)

whl_config_repository = repository_rule(
attrs = {
"groups": attr.string_list_dict(
doc = "A mapping of group names to requirements within that group.",
),
"repo_prefix": attr.string(
doc = "Prefix used for the whl_library created components of each group",
),
"whl_map": attr.string_dict(
doc = """\
The wheel map where values are json.encoded strings of the whl_map constructed
in the pip.parse tag class.
""",
),
"_config_template": attr.label(
default = ":config.bzl.tmpl",
),
},
doc = """
Create a package containing only wrapper py_library and whl_library rules for implementing dependency groups.
This is an implementation detail of dependency groups and should not be used alone.
PRIVATE USE ONLY, only used in WORKSPACE.
""",
implementation = _impl,
)
13 changes: 11 additions & 2 deletions python/private/pypi/whl_library.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,10 @@ def _whl_library_impl(rctx):
timeout = rctx.attr.timeout,
)

if rp_config.enable_pipstar:
# NOTE @aignas 2025-09-28: if someone has an old vendored file that does not have the
# dep_template set or the packages is not set either, we should still not break, best to
# disable pipstar for that particular case.
if rp_config.enable_pipstar and rctx.attr.config_load:
pypi_repo_utils.execute_checked(
rctx,
op = "whl_library.ExtractWheel({}, {})".format(rctx.attr.name, whl_path),
Expand Down Expand Up @@ -422,7 +425,10 @@ def _whl_library_impl(rctx):
build_file_contents = generate_whl_library_build_bazel(
name = whl_path.basename,
sdist_filename = sdist_filename,
dep_template = rctx.attr.dep_template or "@{}{{name}}//:{{target}}".format(rctx.attr.repo_prefix),
dep_template = rctx.attr.dep_template or "@{}{{name}}//:{{target}}".format(
rctx.attr.repo_prefix,
),
config_load = rctx.attr.config_load,
entry_points = entry_points,
metadata_name = metadata.name,
metadata_version = metadata.version,
Expand Down Expand Up @@ -572,6 +578,9 @@ whl_library_attrs = dict({
),
allow_files = True,
),
"config_load": attr.string(
doc = "The load location for configuration for pipstar.",
),
"dep_template": attr.string(
doc = """
The dep template to use for referencing the dependencies. It should have `{name}`
Expand Down
10 changes: 8 additions & 2 deletions python/private/pypi/whl_library_targets.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -274,12 +274,18 @@ def whl_library_targets(
if group_name and "//:" in dep_template:
# This is the legacy behaviour where the group library is outside the hub repo
label_tmpl = dep_template.format(
name = "_groups",
name = "_config",
target = normalize_name(group_name) + "_{}",
).replace(
"//:",
"//_groups:",
)
impl_vis = [dep_template.format(
name = "_groups",
name = "_config",
target = "__pkg__",
).replace(
"//:",
"//_groups:",
)]

native.alias(
Expand Down
Loading