Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 86b630e

Browse filesBrowse files
committed
chore(twine): support 'bzlmod' users out of the box
Fixes #1369
1 parent cde1b52 commit 86b630e
Copy full SHA for 86b630e

File tree

Expand file treeCollapse file tree

5 files changed

+50
-11
lines changed
Filter options
Expand file treeCollapse file tree

5 files changed

+50
-11
lines changed

‎CHANGELOG.md

Copy file name to clipboardExpand all lines: CHANGELOG.md
+5Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ A brief description of the categories of changes:
2121

2222
[0.XX.0]: https://github.com/bazelbuild/rules_python/releases/tag/0.XX.0
2323

24+
### Added
25+
26+
* (py_wheel) `bzlmod` installations now provide a `twine` setup for the default
27+
Python toolchain in `rules_python` for version 3.11.
28+
2429
## [0.27.0] - 2023-11-16
2530

2631
[0.27.0]: https://github.com/bazelbuild/rules_python/releases/tag/0.27.0

‎MODULE.bazel

Copy file name to clipboardExpand all lines: MODULE.bazel
+9Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,15 @@ use_repo(python, "pythons_hub")
5555
# This call registers the Python toolchains.
5656
register_toolchains("@pythons_hub//:all")
5757

58+
pip = use_extension("//python/extensions:pip.bzl", "pip")
59+
pip.parse(
60+
hub_name = "publish_deps",
61+
python_version = "3.11",
62+
requirements_darwin = "//tools/publish:requirements_darwin.txt",
63+
requirements_lock = "//tools/publish:requirements.txt",
64+
requirements_windows = "//tools/publish:requirements_windows.txt",
65+
)
66+
5867
# ===== DEV ONLY SETUP =====
5968
docs_pip = use_extension(
6069
"//python/extensions:pip.bzl",

‎python/packaging.bzl

Copy file name to clipboardExpand all lines: python/packaging.bzl
+28-10Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414

1515
"""Public API for for building wheels."""
1616

17+
load("@bazel_skylib//rules:native_binary.bzl", "native_binary")
1718
load("//python:py_binary.bzl", "py_binary")
19+
load("//python/private:bzlmod_enabled.bzl", "BZLMOD_ENABLED")
1820
load("//python/private:py_package.bzl", "py_package_lib")
1921
load("//python/private:py_wheel.bzl", _PyWheelInfo = "PyWheelInfo", _py_wheel = "py_wheel")
2022
load("//python/private:util.bzl", "copy_propagating_kwargs")
@@ -115,19 +117,21 @@ def py_wheel(name, twine = None, publish_args = [], **kwargs):
115117
)
116118
```
117119
118-
To publish the wheel to Pypi, the twine package is required.
119-
rules_python doesn't provide twine itself, see https://github.com/bazelbuild/rules_python/issues/1016
120-
However you can install it with pip_parse, just like we do in the WORKSPACE file in rules_python.
120+
To publish the wheel to PyPI, the twine package is required and it is installed
121+
by default on `bzlmod` setups. On legacy `WORKSPACE`, `rules_python`
122+
doesn't provide `twine` itself
123+
(see https://github.com/bazelbuild/rules_python/issues/1016), but
124+
you can install it with `pip_parse`, just like we do any other dependencies.
121125
122-
Once you've installed twine, you can pass its label to the `twine` attribute of this macro,
123-
to get a "[name].publish" target.
126+
Once you've installed twine, you can pass its label to the `twine`
127+
attribute of this macro, to get a "[name].publish" target.
124128
125129
Example:
126130
127131
```python
128132
py_wheel(
129133
name = "my_wheel",
130-
twine = "@publish_deps_twine//:pkg",
134+
twine = "@publish_deps//twine",
131135
...
132136
)
133137
```
@@ -158,14 +162,28 @@ def py_wheel(name, twine = None, publish_args = [], **kwargs):
158162

159163
_py_wheel(name = name, **kwargs)
160164

161-
if twine:
162-
if not twine.endswith(":pkg"):
163-
fail("twine label should look like @my_twine_repo//:pkg")
164-
twine_main = twine.replace(":pkg", ":rules_python_wheel_entry_point_twine.py")
165+
twine_args = []
166+
if twine or BZLMOD_ENABLED:
165167
twine_args = ["upload"]
166168
twine_args.extend(publish_args)
167169
twine_args.append("$(rootpath :{})/*".format(_dist_target))
168170

171+
if BZLMOD_ENABLED or str(Label(twine)) == str(Label("//tools/publish:twine")):
172+
native_binary(
173+
name = "{}.publish".format(name),
174+
src = Label("//tools/publish:twine"),
175+
out = "{}.publish",
176+
args = twine_args,
177+
data = [_dist_target],
178+
visibility = kwargs.get("visibility"),
179+
**copy_propagating_kwargs(kwargs)
180+
)
181+
elif twine:
182+
if not twine.endswith(":pkg"):
183+
fail("twine label should look like @my_twine_repo//:pkg")
184+
185+
twine_main = twine.replace(":pkg", ":rules_python_wheel_entry_point_twine.py")
186+
169187
# TODO: use py_binary from //python:defs.bzl after our stardoc setup is less brittle
170188
# buildifier: disable=native-py
171189
py_binary(

‎python/runfiles/BUILD.bazel

Copy file name to clipboardExpand all lines: python/runfiles/BUILD.bazel
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ py_wheel(
5050
distribution = "bazel_runfiles",
5151
homepage = "https://github.com/bazelbuild/rules_python",
5252
strip_path_prefixes = ["python"],
53-
twine = "@publish_deps_twine//:pkg",
53+
twine = "//tools/publish:twine",
5454
# this can be replaced by building with --stamp --embed_label=1.2.3
5555
version = "{BUILD_EMBED_LABEL}",
5656
visibility = ["//visibility:public"],

‎tools/publish/BUILD.bazel

Copy file name to clipboard
+7Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
11
load("//python:pip.bzl", "compile_pip_requirements")
2+
load("//python/entry_points:py_console_script_binary.bzl", "py_console_script_binary")
23

34
compile_pip_requirements(
45
name = "requirements",
56
src = "requirements.in",
67
requirements_darwin = "requirements_darwin.txt",
78
requirements_windows = "requirements_windows.txt",
89
)
10+
11+
py_console_script_binary(
12+
name = "twine",
13+
pkg = "@publish_deps//twine",
14+
visibility = ["//visibility:public"],
15+
)

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.