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 9505116

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

File tree

Expand file treeCollapse file tree

5 files changed

+48
-10
lines changed
Filter options
Expand file treeCollapse file tree

5 files changed

+48
-10
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
+26-9Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"""Public API for for building wheels."""
1616

1717
load("//python:py_binary.bzl", "py_binary")
18+
load("//python/private:bzlmod_enabled.bzl", "BZLMOD_ENABLED")
1819
load("//python/private:py_package.bzl", "py_package_lib")
1920
load("//python/private:py_wheel.bzl", _PyWheelInfo = "PyWheelInfo", _py_wheel = "py_wheel")
2021
load("//python/private:util.bzl", "copy_propagating_kwargs")
@@ -115,19 +116,21 @@ def py_wheel(name, twine = None, publish_args = [], **kwargs):
115116
)
116117
```
117118
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.
119+
To publish the wheel to PyPI, the twine package is required and it is installed
120+
by default on `bzlmod` setups. On legacy `WORKSPACE`, `rules_python`
121+
doesn't provide `twine` itself
122+
(see https://github.com/bazelbuild/rules_python/issues/1016), but
123+
you can install it with `pip_parse`, just like we do any other dependencies.
121124
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.
125+
Once you've installed twine, you can pass its label to the `twine`
126+
attribute of this macro, to get a "[name].publish" target.
124127
125128
Example:
126129
127130
```python
128131
py_wheel(
129132
name = "my_wheel",
130-
twine = "@publish_deps_twine//:pkg",
133+
twine = "@publish_deps//twine",
131134
...
132135
)
133136
```
@@ -158,13 +161,17 @@ def py_wheel(name, twine = None, publish_args = [], **kwargs):
158161

159162
_py_wheel(name = name, **kwargs)
160163

164+
twine_args = []
165+
if twine or BZLMOD_ENABLED:
166+
twine_args = ["upload"]
167+
twine_args.extend(publish_args)
168+
twine_args.append("$(rootpath :{})/*".format(_dist_target))
169+
161170
if twine:
162171
if not twine.endswith(":pkg"):
163172
fail("twine label should look like @my_twine_repo//:pkg")
173+
164174
twine_main = twine.replace(":pkg", ":rules_python_wheel_entry_point_twine.py")
165-
twine_args = ["upload"]
166-
twine_args.extend(publish_args)
167-
twine_args.append("$(rootpath :{})/*".format(_dist_target))
168175

169176
# TODO: use py_binary from //python:defs.bzl after our stardoc setup is less brittle
170177
# buildifier: disable=native-py
@@ -179,5 +186,15 @@ def py_wheel(name, twine = None, publish_args = [], **kwargs):
179186
visibility = kwargs.get("visibility"),
180187
**copy_propagating_kwargs(kwargs)
181188
)
189+
elif BZLMOD_ENABLED:
190+
native_binary(
191+
name = "{}.publish".format(name),
192+
src = Label("//tools/publish:twine"),
193+
out = "{}.publish",
194+
args = twine_args,
195+
data = [_dist_target],
196+
visibility = kwargs.get("visibility"),
197+
**copy_propagating_kwargs(kwargs)
198+
)
182199

183200
py_wheel_rule = _py_wheel

‎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.