Skip to content

Commit 85f7b4e

Browse files
authored
Merge branch 'main' into stop-hacking-tree-sitter
2 parents fdbb53e + 51d9b98 commit 85f7b4e

27 files changed

+869
-2381
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
---
2+
name: "🏗️ Patch release or backport"
3+
about: Request a patch release or backport of a fix to a release.
4+
title: 'Patch release: MAJOR.MINOR.PATCH'
5+
labels: 'type: process'
6+
---
7+
8+
<!--
9+
Thank you for requesting a backport. Before submitting, please read:
10+
11+
* Backport policy: https://rules-python.readthedocs.io/en/latest/support.html#backports-and-patch-releases
12+
-->
13+
14+
**What version of `rules_python` do you want to patch?**
15+
16+
17+
**What pull requests do you want to backport?**
18+
19+
Please provide a list of pull request numbers.
20+
21+
- #
22+
- #

CHANGELOG.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@ END_UNRELEASED_TEMPLATE
7272
* (toolchain) Python 3.13 now references 3.13.6
7373
* (gazelle) Switched back to smacker/go-tree-sitter, fixing
7474
[#2630](https://github.com/bazel-contrib/rules_python/issues/2630)
75+
* (pypi) From now on the list of default platforms only includes `linux_x86_64`, `linux_aarch64`,
76+
`osx_x86_64`, `osx_aarch64` and `windows_x86_64`. If you are on other platforms, you need to
77+
use the `pip.default` to configure it yourself. If you are interested in graduating the
78+
platform, consider helping set us up CI for them and update the documentation.
7579
* (ci) We are now testing on Ubuntu 22.04 for RBE and non-RBE configurations.
7680
* (core) `#!/usr/bin/env bash` is now used as a shebang in the stage1 bootstrap template.
7781
* (gazelle:docs) The Gazelle docs have been migrated from {gh-path}`gazelle/README.md` to
@@ -93,6 +97,10 @@ END_UNRELEASED_TEMPLATE
9397
([#2503](https://github.com/bazel-contrib/rules_python/issues/2503)).
9498
* (pypi) The pipstar `defaults` configuration now supports any custom platform
9599
name.
100+
* (pypi) The selection of the whls has been changed and should no longer result
101+
in ambiguous select matches ({gh-issue}`2759`) and should be much more efficient
102+
when running `bazel query` due to fewer repositories being included
103+
({gh-issue}`2849`).
96104
* Multi-line python imports (e.g. with escaped newlines) are now correctly processed by Gazelle.
97105
* (toolchains) `local_runtime_repo` works with multiarch Debian with Python 3.8
98106
([#3099](https://github.com/bazel-contrib/rules_python/issues/3099)).
@@ -123,7 +131,8 @@ END_UNRELEASED_TEMPLATE
123131
([#3114](https://github.com/bazel-contrib/rules_python/pull/3114)).
124132
* (pypi) To configure the environment for `requirements.txt` evaluation, use the newly added
125133
developer preview of the `pip.default` tag class. Only `rules_python` and root modules can use
126-
this feature. You can also configure custom `config_settings` using `pip.default`.
134+
this feature. You can also configure custom `config_settings` using `pip.default`. It
135+
can also be used to set the global `netrc` or `auth_patterns` variables.
127136
* (pypi) PyPI dependencies now expose an `:extracted_whl_files` filegroup target
128137
of all the files extracted from the wheel. This can be used in lieu of
129138
{obj}`whl_filegroup` to avoid copying/extracting wheel multiple times to

MODULE.bazel

Lines changed: 49 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -74,16 +74,18 @@ pip = use_extension("//python/extensions:pip.bzl", "pip")
7474
env = {"platform_version": "0"},
7575
os_name = "linux",
7676
platform = "linux_{}".format(cpu),
77+
whl_abi_tags = [
78+
"abi3",
79+
"cp{major}{minor}",
80+
],
81+
whl_platform_tags = [
82+
"linux_{}".format(cpu),
83+
"manylinux_*_{}".format(cpu),
84+
],
7785
)
7886
for cpu in [
7987
"x86_64",
8088
"aarch64",
81-
# TODO @aignas 2025-05-19: only leave tier 0-1 cpus when stabilizing the
82-
# `pip.default` extension. i.e. drop the below values - users will have to
83-
# define themselves if they need them.
84-
"arm",
85-
"ppc",
86-
"s390x",
8789
]
8890
]
8991

@@ -99,26 +101,53 @@ pip = use_extension("//python/extensions:pip.bzl", "pip")
99101
env = {"platform_version": "14.0"},
100102
os_name = "osx",
101103
platform = "osx_{}".format(cpu),
104+
whl_abi_tags = [
105+
"abi3",
106+
"cp{major}{minor}",
107+
],
108+
whl_platform_tags = [
109+
"macosx_*_{}".format(suffix)
110+
for suffix in platform_tag_cpus
111+
],
102112
)
103-
for cpu in [
104-
"aarch64",
105-
"x86_64",
106-
]
113+
for cpu, platform_tag_cpus in {
114+
"aarch64": [
115+
"universal2",
116+
"arm64",
117+
],
118+
"x86_64": [
119+
"universal2",
120+
"x86_64",
121+
],
122+
}.items()
123+
]
124+
125+
[
126+
pip.default(
127+
arch_name = cpu,
128+
config_settings = [
129+
"@platforms//cpu:{}".format(cpu),
130+
"@platforms//os:windows",
131+
],
132+
env = {"platform_version": "0"},
133+
os_name = "windows",
134+
platform = "windows_{}".format(cpu),
135+
whl_abi_tags = [
136+
"abi3",
137+
"cp{major}{minor}",
138+
],
139+
whl_platform_tags = whl_platform_tags,
140+
)
141+
for cpu, whl_platform_tags in {
142+
"x86_64": ["win_amd64"],
143+
}.items()
107144
]
108145

109-
pip.default(
110-
arch_name = "x86_64",
111-
config_settings = [
112-
"@platforms//cpu:x86_64",
113-
"@platforms//os:windows",
114-
],
115-
env = {"platform_version": "0"},
116-
os_name = "windows",
117-
platform = "windows_x86_64",
118-
)
119146
pip.parse(
120147
# NOTE @aignas 2024-10-26: We have an integration test that depends on us
121148
# being able to build sdists for this hub, so explicitly set this to False.
149+
#
150+
# how do we test sdists? Maybe just worth adding a single sdist somewhere?
122151
download_only = False,
123152
experimental_index_url = "https://pypi.org/simple",
124153
hub_name = "rules_python_publish_deps",

docs/devguide.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,3 +116,35 @@ to have everything self-documented, we have a special target,
116116
`//private:requirements.update`, which uses `rules_multirun` to run all
117117
of the requirement-updating scripts in sequence in one go. This can be done once per release as
118118
we prepare for releases.
119+
120+
## Creating Backport PRs
121+
122+
The steps to create a backport PR are:
123+
124+
1. Create an issue for the patch release; use the [patch relase
125+
template][patch-release-issue].
126+
2. Create a fork of `rules_python`.
127+
3. Checkout the `release/X.Y` branch.
128+
4. Use `git cherry-pick -x` to cherry pick the desired fixes.
129+
5. Update the release's `CHANGELOG.md` file:
130+
* Add a Major.Minor.Patch section if one doesn't exist
131+
* Copy the changelog text from `main` to the release's changelog.
132+
6. Send a PR with the backport's changes.
133+
* The title should be `backport: PR#N to Major.Minor`
134+
* The body must preserve the original PR's number, commit hash, description,
135+
and authorship.
136+
Use the following format (`git cherry-pick` will use this format):
137+
```
138+
<original PR title>
139+
140+
<original PR body>
141+
(cherry picked from commit <commit hash>)
142+
-----
143+
Co-authored-by: <original PR author; separate lines for each>
144+
```
145+
* If the PR contains multiple backport commits, separate each's description
146+
with `-----`.
147+
7. Send a PR to update the `main` branch's `CHANGELOG.md` to reflect the
148+
changes done in the patched release.
149+
150+
[patch-release-issue]: https://github.com/bazelbuild/rules_python/issues/new?template=patch_release.md

docs/support.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,22 @@ the willingness of volunteers.
1414
If you want or need particular functionality backported, then the best way
1515
is to open a PR to demonstrate the feasibility of the backport.
1616

17+
### Backports and Patch Releases
18+
19+
Backports and patch releases are provided on a best-effort basis. Only fixes are
20+
backported. Features are not backported.
21+
22+
Backports can be done to older releases, but only if newer releases also have
23+
the fix backported. For example, if the current release is 1.5, in order to
24+
patch 1.4, version 1.5 must be patched first.
25+
26+
Backports can be requested by [creating an issue with the patch release
27+
template][patch-release-issue] or by sending a pull request performing the backport.
28+
See the dev guide for [how to create a backport PR][backport-pr].
29+
30+
[patch-release-issue]: https://github.com/bazelbuild/rules_python/issues/new?template=patch_release_request.md
31+
[backport-pr]: devguide.html#creating-backport-prs
32+
1733
## Supported Bazel Versions
1834

1935
The supported Bazel versions are:

examples/bzlmod/MODULE.bazel

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,23 @@ pip.whl_mods(
158158
)
159159
use_repo(pip, "whl_mods_hub")
160160

161+
# Because below we are using `windows_aarch64` platform, we have to define various
162+
# properties for it.
163+
pip.default(
164+
arch_name = "aarch64",
165+
config_settings = [
166+
"@platforms//os:windows",
167+
"@platforms//cpu:aarch64",
168+
],
169+
env = {
170+
"platform_version": "0",
171+
},
172+
os_name = "windows",
173+
platform = "windows_aarch64",
174+
whl_abi_tags = [], # default to all ABIs
175+
whl_platform_tags = ["win_amd64"],
176+
)
177+
161178
# To fetch pip dependencies, use pip.parse. We can pass in various options,
162179
# but typically we pass requirements and the Python version. The Python
163180
# version must have been configured by a corresponding `python.toolchain()`

gazelle/docs/installation_and_usage.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,16 @@ load("@rules_python_gazelle_plugin//modules_mapping:def.bzl", "modules_mapping")
8686
modules_mapping(
8787
name = "modules_map",
8888
wheels = all_whl_requirements,
89+
90+
# include_stub_packages: bool (default: False)
91+
# If set to True, this flag automatically includes any corresponding type stub packages
92+
# for the third-party libraries that are present and used. For example, if you have
93+
# `boto3` as a dependency, and this flag is enabled, the corresponding `boto3-stubs`
94+
# package will be automatically included in the BUILD file.
95+
# Enabling this feature helps ensure that type hints and stubs are readily available
96+
# for tools like type checkers and IDEs, improving the development experience and
97+
# reducing manual overhead in managing separate stub packages.
98+
include_stub_packages = True,
8999
)
90100

91101
# Gazelle python extension needs a manifest file mapping from
@@ -110,16 +120,6 @@ gazelle_python_manifest(
110120
# the integrity field is not added to the manifest which can help avoid
111121
# merge conflicts in large repos.
112122
requirements = "//:requirements_lock.txt",
113-
114-
# include_stub_packages: bool (default: False)
115-
# If set to True, this flag automatically includes any corresponding type stub packages
116-
# for the third-party libraries that are present and used. For example, if you have
117-
# `boto3` as a dependency, and this flag is enabled, the corresponding `boto3-stubs`
118-
# package will be automatically included in the BUILD file.
119-
# Enabling this feature helps ensure that type hints and stubs are readily available
120-
# for tools like type checkers and IDEs, improving the development experience and
121-
# reducing manual overhead in managing separate stub packages.
122-
include_stub_packages = True
123123
)
124124
```
125125

@@ -134,9 +134,9 @@ gazelle_binary(
134134
name = "gazelle_multilang",
135135
languages = [
136136
# List of language plugins.
137-
# If you want to generate py_proto_library targets PR #3057), then
137+
# If you want to generate py_proto_library targets (PR #3057), then
138138
# the proto language plugin _must_ come before the rules_python plugin.
139-
#"@bazel_gazelle//lanugage/proto",
139+
#"@bazel_gazelle//language/proto",
140140
"@rules_python_gazelle_plugin//python",
141141
],
142142
)

python/private/get_local_runtime_info.py

Lines changed: 37 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
_IS_DARWIN = sys.platform == "darwin"
2424

2525

26-
def _search_directories(get_config):
26+
def _search_directories(get_config, base_executable):
2727
"""Returns a list of library directories to search for shared libraries."""
2828
# There's several types of libraries with different names and a plethora
2929
# of settings, and many different config variables to check:
@@ -53,19 +53,23 @@ def _search_directories(get_config):
5353
if config_value and not config_value.endswith(multiarch):
5454
lib_dirs.append(os.path.join(config_value, multiarch))
5555

56-
if _IS_WINDOWS:
57-
# On Windows DLLs go in the same directory as the executable, while .lib
58-
# files live in the lib/ or libs/ subdirectory.
59-
lib_dirs.append(get_config("BINDIR"))
60-
lib_dirs.append(os.path.join(os.path.dirname(sys.executable)))
61-
lib_dirs.append(os.path.join(os.path.dirname(sys.executable), "lib"))
62-
lib_dirs.append(os.path.join(os.path.dirname(sys.executable), "libs"))
63-
elif not _IS_DARWIN:
64-
# On most systems the executable is in a bin/ directory and the libraries
65-
# are in a sibling lib/ directory.
66-
lib_dirs.append(
67-
os.path.join(os.path.dirname(os.path.dirname(sys.executable)), "lib")
68-
)
56+
if not _IS_DARWIN:
57+
for exec_dir in (
58+
os.path.dirname(base_executable) if base_executable else None,
59+
get_config("BINDIR"),
60+
):
61+
if not exec_dir:
62+
continue
63+
if _IS_WINDOWS:
64+
# On Windows DLLs go in the same directory as the executable, while .lib
65+
# files live in the lib/ or libs/ subdirectory.
66+
lib_dirs.append(exec_dir)
67+
lib_dirs.append(os.path.join(exec_dir, "lib"))
68+
lib_dirs.append(os.path.join(exec_dir, "libs"))
69+
else:
70+
# On most systems the executable is in a bin/ directory and the libraries
71+
# are in a sibling lib/ directory.
72+
lib_dirs.append(os.path.join(os.path.dirname(exec_dir), "lib"))
6973

7074
# Dedup and remove empty values, keeping the order.
7175
lib_dirs = [v for v in lib_dirs if v]
@@ -126,7 +130,7 @@ def _search_library_names(get_config):
126130
return {k: None for k in lib_names}.keys()
127131

128132

129-
def _get_python_library_info():
133+
def _get_python_library_info(base_executable):
130134
"""Returns a dictionary with the static and dynamic python libraries."""
131135
config_vars = sysconfig.get_config_vars()
132136

@@ -140,7 +144,7 @@ def _get_python_library_info():
140144
f"{sys.version_info.major}.{sys.version_info.minor}"
141145
)
142146

143-
search_directories = _search_directories(config_vars.get)
147+
search_directories = _search_directories(config_vars.get, base_executable)
144148
search_libnames = _search_library_names(config_vars.get)
145149

146150
def _add_if_exists(target, path):
@@ -187,13 +191,28 @@ def _add_if_exists(target, path):
187191
}
188192

189193

194+
def _get_base_executable():
195+
"""Returns the base executable path."""
196+
try:
197+
if sys._base_executable: # pylint: disable=protected-access
198+
return sys._base_executable # pylint: disable=protected-access
199+
except AttributeError:
200+
# Bug reports indicate sys._base_executable doesn't exist in some cases,
201+
# but it's not clear why.
202+
# See https://github.com/bazel-contrib/rules_python/issues/3172
203+
pass
204+
# The normal sys.executable is the next-best guess if sys._base_executable
205+
# is missing.
206+
return sys.executable
207+
208+
190209
data = {
191210
"major": sys.version_info.major,
192211
"minor": sys.version_info.minor,
193212
"micro": sys.version_info.micro,
194213
"include": sysconfig.get_path("include"),
195214
"implementation_name": sys.implementation.name,
196-
"base_executable": sys._base_executable,
215+
"base_executable": _get_base_executable(),
197216
}
198-
data.update(_get_python_library_info())
217+
data.update(_get_python_library_info(_get_base_executable()))
199218
print(json.dumps(data))

python/private/py_executable.bzl

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1578,7 +1578,11 @@ def _create_shared_native_deps_dso(
15781578
feature_configuration,
15791579
requested_features,
15801580
cc_toolchain):
1581-
linkstamps = py_internal.linking_context_linkstamps(cc_info.linking_context)
1581+
linkstamps = [
1582+
py_internal.linkstamp_file(linkstamp)
1583+
for linker_input in cc_info.linking_context.linker_inputs.to_list()
1584+
for linkstamp in linker_input.linkstamps
1585+
]
15821586

15831587
partially_disabled_thin_lto = (
15841588
cc_common.is_enabled(
@@ -1602,10 +1606,7 @@ def _create_shared_native_deps_dso(
16021606
for input in cc_info.linking_context.linker_inputs.to_list()
16031607
for flag in input.user_link_flags
16041608
],
1605-
linkstamps = [
1606-
py_internal.linkstamp_file(linkstamp)
1607-
for linkstamp in linkstamps.to_list()
1608-
],
1609+
linkstamps = linkstamps,
16091610
build_info_artifacts = _get_build_info(ctx, cc_toolchain) if linkstamps else [],
16101611
features = requested_features,
16111612
is_test_target_partially_disabled_thin_lto = is_test and partially_disabled_thin_lto,

0 commit comments

Comments
 (0)