Skip to content

Commit e3a7e48

Browse files
committed
fix(release): minimum needed to run twine to publish
Earlier attempts to publish 0.17 have failed mysteriously at the pypa/gh-action-pypi-publish step. This PR replaces that with a command that I can test locally. TWINE_USERNAME=__token__ TWINE_PASSWORD=pypi-*** bazel run --stamp --embed_label=1.2.4 //python/runfiles:wheel.publish -- --repository testpypi Uploading bazel_runfiles-1.2.4-py3-none-any.whl 100% ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 11.0/11.0 kB • 00:00 • 27.3 MB/s View at: https://test.pypi.org/project/bazel-runfiles/1.2.4/
1 parent d196451 commit e3a7e48

File tree

6 files changed

+353
-16
lines changed

6 files changed

+353
-16
lines changed

.github/workflows/release.yml

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,15 @@ jobs:
1414
uses: actions/checkout@v2
1515
- name: Prepare workspace snippet
1616
run: .github/workflows/workspace_snippet.sh > release_notes.txt
17-
- name: Build wheel dist
18-
run: bazel build --stamp --embed_label=${{ github.ref_name }} //python/runfiles:wheel.dist
19-
- name: Publish runfiles package to PyPI
20-
uses: pypa/gh-action-pypi-publish@release/v1
21-
with:
17+
- name: Publish wheel dist
18+
env:
19+
# This special value tells pypi that the user identity is supplied within the token
20+
TWINE_USERNAME: __token__
2221
# Note, the PYPI_API_TOKEN was added on
2322
# https://github.com/bazelbuild/rules_python/settings/secrets/actions
2423
# and currently uses a token which authenticates as https://pypi.org/user/alexeagle/
25-
password: ${{ secrets.PYPI_API_TOKEN }}
26-
packages_dir: bazel-bin/python/runfiles/dist
24+
TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}
25+
run: bazel run --stamp --embed_label=${{ github.ref_name }} //python/runfiles:wheel.publish
2726
- name: Release
2827
uses: softprops/action-gh-release@v1
2928
with:

WORKSPACE

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,3 +67,21 @@ load("@rules_python_gazelle_plugin//:deps.bzl", _py_gazelle_deps = "gazelle_deps
6767
# This rule loads and compiles various go dependencies that running gazelle
6868
# for python requirements.
6969
_py_gazelle_deps()
70+
71+
load("@python//3.11.1:defs.bzl", "interpreter")
72+
73+
#####################
74+
# Install twine for our own runfiles wheel publishing
75+
# Eventually we might want to install twine automatically for users too, see:
76+
# See https://github.com/bazelbuild/rules_python/issues/1016
77+
load("@rules_python//python:pip.bzl", "pip_parse")
78+
79+
pip_parse(
80+
name = "publish_deps",
81+
python_interpreter_target = interpreter,
82+
requirements_lock = "//python/runfiles:requirements.txt",
83+
)
84+
85+
load("@publish_deps//:requirements.bzl", "install_deps")
86+
87+
install_deps()

python/runfiles/BUILD.bazel

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,14 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
load("@rules_python//python:defs.bzl", "py_binary")
1516
load("//python:defs.bzl", "py_library")
1617
load("//python:packaging.bzl", "py_wheel")
18+
load("//python:pip.bzl", "compile_pip_requirements")
19+
20+
compile_pip_requirements(
21+
name = "requirements",
22+
)
1723

1824
filegroup(
1925
name = "distribution",
@@ -40,12 +46,27 @@ py_wheel(
4046
"Development Status :: 5 - Production/Stable",
4147
"License :: OSI Approved :: Apache Software License",
4248
],
43-
description_file = "README.md",
49+
description_file = "README.rst",
4450
dist_folder = "dist",
4551
distribution = "bazel_runfiles",
4652
homepage = "https://github.com/bazelbuild/rules_python",
4753
strip_path_prefixes = ["python"],
54+
# this can be replaced by building with --stamp --embed_label=1.2.3
4855
version = "{BUILD_EMBED_LABEL}",
4956
visibility = ["//visibility:public"],
5057
deps = [":runfiles"],
5158
)
59+
60+
# TODO(alexeagle): carry forward #1015 to make this part of the py_wheel macro
61+
py_binary(
62+
name = "wheel.publish",
63+
srcs = ["@publish_deps_twine//:rules_python_wheel_entry_point_twine.py"],
64+
args = [
65+
"upload",
66+
"$(location :wheel.dist)/*",
67+
],
68+
data = [":wheel.dist"],
69+
imports = ["."],
70+
main = "@publish_deps_twine//:rules_python_wheel_entry_point_twine.py",
71+
deps = ["@publish_deps_twine//:pkg"],
72+
)

python/runfiles/README.md renamed to python/runfiles/README.rst

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,27 @@
1-
# bazel-runfiles library
1+
bazel-runfiles library
2+
======================
23

34
This is a Bazel Runfiles lookup library for Bazel-built Python binaries and tests.
45

56
Typical Usage
67
-------------
78

89
1. Add the 'runfiles' dependency along with other third-party dependencies, for example in your
9-
`requirements.txt` file.
10+
``requirements.txt`` file.
1011

11-
2. Depend on this runfiles library from your build rule, like you would other third-party libraries.
12+
2. Depend on this runfiles library from your build rule, like you would other third-party libraries::
1213

1314
py_binary(
1415
name = "my_binary",
1516
...
1617
deps = [requirement("runfiles")],
1718
)
1819

19-
3. Import the runfiles library.
20+
3. Import the runfiles library::
2021

2122
import runfiles # not "from runfiles import runfiles"
2223

23-
4. Create a Runfiles object and use rlocation to look up runfile paths:
24+
4. Create a Runfiles object and use rlocation to look up runfile paths::
2425

2526
r = runfiles.Create()
2627
...
@@ -32,15 +33,15 @@ Typical Usage
3233
on the environment variables in os.environ. See `Create()` for more info.
3334

3435
If you want to explicitly create a manifest- or directory-based
35-
implementations, you can do so as follows:
36+
implementations, you can do so as follows::
3637

3738
r1 = runfiles.CreateManifestBased("path/to/foo.runfiles_manifest")
3839

3940
r2 = runfiles.CreateDirectoryBased("path/to/foo.runfiles/")
4041

41-
If you wnat to start subprocesses, and the subprocess can't automatically
42+
If you want to start subprocesses, and the subprocess can't automatically
4243
find the correct runfiles directory, you can explicitly set the right
43-
environment variables for them:
44+
environment variables for them::
4445

4546
import subprocess
4647
import runfiles

python/runfiles/requirements.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
twine

0 commit comments

Comments
 (0)