Skip to content

Commit b397905

Browse files
authored
Merge branch 'main' into doc.misc.improvements
2 parents c76e100 + 6038ac4 commit b397905

File tree

18 files changed

+288
-117
lines changed

18 files changed

+288
-117
lines changed

CHANGELOG.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,24 @@ END_UNRELEASED_TEMPLATE
144144
### Removed
145145
* Nothing removed.
146146

147+
{#1-5-2}
148+
## [1.5.2] - 2025-08-11
149+
150+
[1.5.2]: https://github.com/bazel-contrib/rules_python/releases/tag/1.5.2
151+
152+
{#v1-5-2-changed}
153+
### Changed
154+
* (deps) (bzlmod) Upgraded to `bazel-skylib` version
155+
[1.8.1](https://github.com/bazelbuild/bazel-skylib/releases/tag/1.8.1)
156+
to remove deprecation warnings.
157+
158+
{#v1-5-2-fixed}
159+
### Fixed
160+
* (pypi) Correctly pull `sdist` distributions using `pip`
161+
([#3131](https://github.com/bazel-contrib/rules_python/pull/3131)).
162+
* (core) builds work again on `7.x` `WORKSPACE` configurations
163+
([#3119](https://github.com/bazel-contrib/rules_python/issues/3119)).
164+
147165
{#1-5-1}
148166
## [1.5.1] - 2025-07-06
149167

MODULE.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ module(
55
)
66

77
bazel_dep(name = "bazel_features", version = "1.21.0")
8-
bazel_dep(name = "bazel_skylib", version = "1.7.1")
8+
bazel_dep(name = "bazel_skylib", version = "1.8.1")
99
bazel_dep(name = "rules_cc", version = "0.0.16")
1010
bazel_dep(name = "platforms", version = "0.0.11")
1111

docs/toolchains.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -432,20 +432,19 @@ interpreter, then introspect its installation to generate a full toolchain.
432432
local_runtime_repo = use_repo_rule(
433433
"@rules_python//python/local_toolchains:repos.bzl",
434434
"local_runtime_repo",
435-
dev_dependency = True,
436435
)
437436

438437
local_runtime_toolchains_repo = use_repo_rule(
439438
"@rules_python//python/local_toolchains:repos.bzl",
440439
"local_runtime_toolchains_repo",
441-
dev_dependency = True,
442440
)
443441

444442
# Step 1: Define the Python runtime
445443
local_runtime_repo(
446444
name = "local_python3",
447445
interpreter_path = "python3",
448446
on_failure = "fail",
447+
dev_dependency = True
449448
)
450449

451450
# Step 2: Create toolchains for the runtimes
@@ -454,6 +453,7 @@ local_runtime_toolchains_repo(
454453
runtimes = ["local_python3"],
455454
# TIP: The `target_settings` arg can be used to activate them based on
456455
# command line flags; see docs below.
456+
dev_dependency = True
457457
)
458458

459459
# Step 3: Register the toolchains

python/private/py_executable.bzl

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -796,6 +796,7 @@ def _create_stage1_bootstrap(
796796
is_for_zip,
797797
runtime_details,
798798
venv = None):
799+
"""Create a legacy bootstrap script that is written in Python."""
799800
runtime = runtime_details.effective_runtime
800801

801802
if venv:
@@ -805,8 +806,11 @@ def _create_stage1_bootstrap(
805806

806807
python_binary_actual = venv.interpreter_actual_path if venv else ""
807808

808-
# Runtime may be None on Windows due to the --python_path flag.
809-
if runtime and runtime.supports_build_time_venv:
809+
# Guard against the following:
810+
# * Runtime may be None on Windows due to the --python_path flag.
811+
# * Runtime may not have 'supports_build_time_venv' if a really old version is autoloaded
812+
# on bazel 7.6.x.
813+
if runtime and getattr(runtime, "supports_build_time_venv", False):
810814
resolve_python_binary_at_runtime = "0"
811815
else:
812816
resolve_python_binary_at_runtime = "1"

python/private/pypi/BUILD.bazel

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,9 @@ bzl_library(
252252
bzl_library(
253253
name = "pep508_env_bzl",
254254
srcs = ["pep508_env.bzl"],
255+
deps = [
256+
"//python/private:version_bzl",
257+
],
255258
)
256259

257260
bzl_library(
@@ -263,11 +266,6 @@ bzl_library(
263266
],
264267
)
265268

266-
bzl_library(
267-
name = "pep508_platform_bzl",
268-
srcs = ["pep508_platform.bzl"],
269-
)
270-
271269
bzl_library(
272270
name = "pep508_requirement_bzl",
273271
srcs = ["pep508_requirement.bzl"],
@@ -338,6 +336,14 @@ bzl_library(
338336
],
339337
)
340338

339+
bzl_library(
340+
name = "python_tag_bzl",
341+
srcs = ["python_tag.bzl"],
342+
deps = [
343+
"//python/private:version_bzl",
344+
],
345+
)
346+
341347
bzl_library(
342348
name = "render_pkg_aliases_bzl",
343349
srcs = ["render_pkg_aliases.bzl"],

python/private/pypi/extension.bzl

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,12 @@ def _platforms(*, python_version, minor_mapping, config):
7676

7777
for platform, values in config.platforms.items():
7878
key = "{}_{}".format(abi, platform)
79-
platforms[key] = env(struct(
80-
abi = abi,
79+
platforms[key] = env(
80+
env = values.env,
8181
os = values.os_name,
8282
arch = values.arch_name,
83-
)) | values.env
83+
python_version = python_version,
84+
)
8485
return platforms
8586

8687
def _create_whl_repos(

python/private/pypi/index_sources.bzl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,12 +93,12 @@ def index_sources(line):
9393
is_known_ext = True
9494
break
9595

96-
if is_known_ext:
96+
requirement = requirement_line
97+
if filename.endswith(".whl"):
9798
requirement = maybe_requirement.strip()
98-
else:
99+
elif not is_known_ext:
99100
# could not detect filename from the URL
100101
filename = ""
101-
requirement = requirement_line
102102

103103
return struct(
104104
requirement = requirement,

python/private/pypi/pep508_env.bzl

Lines changed: 53 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,20 @@
1515
"""This module is for implementing PEP508 environment definition.
1616
"""
1717

18+
load("//python/private:version.bzl", "version")
19+
20+
_DEFAULT = "//conditions:default"
21+
22+
# Here we store the aliases in the platform so that the users can specify any valid target in
23+
# there.
24+
_cpu_aliases = {
25+
"arm": "aarch32",
26+
"arm64": "aarch64",
27+
}
28+
_os_aliases = {
29+
"macos": "osx",
30+
}
31+
1832
# See https://stackoverflow.com/a/45125525
1933
platform_machine_aliases = {
2034
# These pairs mean the same hardware, but different values may be used
@@ -59,7 +73,7 @@ platform_machine_select_map = {
5973
"@platforms//cpu:x86_64": "x86_64",
6074
# The value is empty string if it cannot be determined:
6175
# https://docs.python.org/3/library/platform.html#platform.machine
62-
"//conditions:default": "",
76+
_DEFAULT: "",
6377
}
6478

6579
# Platform system returns results from the `uname` call.
@@ -73,7 +87,7 @@ _platform_system_values = {
7387
"linux": "Linux",
7488
"netbsd": "NetBSD",
7589
"openbsd": "OpenBSD",
76-
"osx": "Darwin",
90+
"osx": "Darwin", # NOTE: macos is an alias to osx, we handle it through _os_aliases
7791
"windows": "Windows",
7892
}
7993

@@ -83,7 +97,7 @@ platform_system_select_map = {
8397
} | {
8498
# The value is empty string if it cannot be determined:
8599
# https://docs.python.org/3/library/platform.html#platform.machine
86-
"//conditions:default": "",
100+
_DEFAULT: "",
87101
}
88102

89103
# The copy of SO [answer](https://stackoverflow.com/a/13874620) containing
@@ -123,72 +137,78 @@ _sys_platform_values = {
123137
"ios": "ios",
124138
"linux": "linux",
125139
"openbsd": "openbsd",
126-
"osx": "darwin",
140+
"osx": "darwin", # NOTE: macos is an alias to osx, we handle it through _os_aliases
127141
"wasi": "wasi",
128142
"windows": "win32",
129143
}
130144

131145
sys_platform_select_map = {
146+
# These values are decided by the sys.platform docs.
132147
"@platforms//os:{}".format(bazel_os): py_platform
133148
for bazel_os, py_platform in _sys_platform_values.items()
134149
} | {
135150
# For lack of a better option, use empty string. No standard doc/spec
136151
# about sys_platform value.
137-
"//conditions:default": "",
152+
_DEFAULT: "",
138153
}
139154

140155
# The "java" value is documented, but with Jython defunct,
141156
# shouldn't occur in practice.
142157
# The os.name value is technically a property of the runtime, not the
143158
# targetted runtime OS, but the distinction shouldn't matter if
144159
# things are properly configured.
145-
_os_name_values = {
146-
"linux": "posix",
147-
"osx": "posix",
148-
"windows": "nt",
149-
}
150-
151160
os_name_select_map = {
152-
"@platforms//os:{}".format(bazel_os): py_os
153-
for bazel_os, py_os in _os_name_values.items()
154-
} | {
155-
"//conditions:default": "posix",
161+
"@platforms//os:windows": "nt",
162+
_DEFAULT: "posix",
156163
}
157164

158-
def env(target_platform, *, extra = None):
165+
def _set_default(env, env_key, m, key):
166+
"""Set the default value in the env if it is not already set."""
167+
default = m.get(key, m[_DEFAULT])
168+
env.setdefault(env_key, default)
169+
170+
def env(*, env = None, os, arch, python_version = "", extra = None):
159171
"""Return an env target platform
160172
161173
NOTE: This is for use during the loading phase. For the analysis phase,
162174
`env_marker_setting()` constructs the env dict.
163175
164176
Args:
165-
target_platform: {type}`str` the target platform identifier, e.g.
166-
`cp33_linux_aarch64`
177+
env: {type}`str` the environment.
178+
os: {type}`str` the OS name.
179+
arch: {type}`str` the CPU name.
180+
python_version: {type}`str` the full python version.
167181
extra: {type}`str` the extra value to be added into the env.
168182
169183
Returns:
170184
A dict that can be used as `env` in the marker evaluation.
171185
"""
172-
env = create_env()
186+
env = env or {}
187+
env = env | create_env()
173188
if extra != None:
174189
env["extra"] = extra
175190

176-
if target_platform.abi:
177-
minor_version, _, micro_version = target_platform.abi[3:].partition(".")
178-
micro_version = micro_version or "0"
179-
env = env | {
180-
"implementation_version": "3.{}.{}".format(minor_version, micro_version),
181-
"python_full_version": "3.{}.{}".format(minor_version, micro_version),
182-
"python_version": "3.{}".format(minor_version),
183-
}
184-
if target_platform.os and target_platform.arch:
185-
os = target_platform.os
191+
if python_version:
192+
v = version.parse(python_version)
193+
major = v.release[0]
194+
minor = v.release[1]
195+
micro = v.release[2] if len(v.release) > 2 else 0
186196
env = env | {
187-
"os_name": _os_name_values.get(os, ""),
188-
"platform_machine": target_platform.arch,
189-
"platform_system": _platform_system_values.get(os, ""),
190-
"sys_platform": _sys_platform_values.get(os, ""),
197+
"implementation_version": "{}.{}.{}".format(major, minor, micro),
198+
"python_full_version": "{}.{}.{}".format(major, minor, micro),
199+
"python_version": "{}.{}".format(major, minor),
191200
}
201+
202+
if os:
203+
os = "@platforms//os:{}".format(_os_aliases.get(os, os))
204+
_set_default(env, "os_name", os_name_select_map, os)
205+
_set_default(env, "platform_system", platform_system_select_map, os)
206+
_set_default(env, "sys_platform", sys_platform_select_map, os)
207+
208+
if arch:
209+
arch = "@platforms//cpu:{}".format(_cpu_aliases.get(arch, arch))
210+
_set_default(env, "platform_machine", platform_machine_select_map, arch)
211+
192212
set_missing_env_defaults(env)
193213

194214
return env

python/private/pypi/pep508_platform.bzl

Lines changed: 0 additions & 57 deletions
This file was deleted.

0 commit comments

Comments
 (0)