Skip to content

Commit

Permalink
fix(release): minimum needed to run twine to publish (#1021)
Browse files Browse the repository at this point in the history
* 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/

* fixup! fix(release): minimum needed to run twine to publish

* refactor: move twine deps to its own folder

* Update WORKSPACE

Co-authored-by: Thulio Ferraz Assis <[email protected]>

* Update python/runfiles/BUILD.bazel

Co-authored-by: Thulio Ferraz Assis <[email protected]>

* show CI failure

* remove actual publish for this PR

* chore: exclude requirements test on RBE

* Add darwin requirements

---------

Co-authored-by: Thulio Ferraz Assis <[email protected]>
  • Loading branch information
alexeagle and f0rmiga authored Feb 7, 2023
1 parent e7b51d7 commit 68ede14
Show file tree
Hide file tree
Showing 10 changed files with 753 additions and 10 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
docs/*.md linguist-generated=true
tools/publish/*.txt linguist-generated=true
19 changes: 19 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,22 @@ load("@rules_python_gazelle_plugin//:deps.bzl", _py_gazelle_deps = "gazelle_deps
# This rule loads and compiles various go dependencies that running gazelle
# for python requirements.
_py_gazelle_deps()

#####################
# Install twine for our own runfiles wheel publishing.
# Eventually we might want to install twine automatically for users too, see:
# https://github.com/bazelbuild/rules_python/issues/1016.
load("@python//3.11.1:defs.bzl", "interpreter")
load("@rules_python//python:pip.bzl", "pip_parse")

pip_parse(
name = "publish_deps",
python_interpreter_target = interpreter,
requirements_darwin = "//tools/publish:requirements_darwin.txt",
requirements_lock = "//tools/publish:requirements.txt",
requirements_windows = "//tools/publish:requirements_windows.txt",
)

load("@publish_deps//:requirements.bzl", "install_deps")

install_deps()
19 changes: 17 additions & 2 deletions python/runfiles/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

load("//python:defs.bzl", "py_library")
load("//python:defs.bzl", "py_binary", "py_library")
load("//python:packaging.bzl", "py_wheel")

filegroup(
Expand Down Expand Up @@ -40,12 +40,27 @@ py_wheel(
"Development Status :: 5 - Production/Stable",
"License :: OSI Approved :: Apache Software License",
],
description_file = "README.md",
description_file = "README.rst",
dist_folder = "dist",
distribution = "bazel_runfiles",
homepage = "https://github.com/bazelbuild/rules_python",
strip_path_prefixes = ["python"],
# this can be replaced by building with --stamp --embed_label=1.2.3
version = "{BUILD_EMBED_LABEL}",
visibility = ["//visibility:public"],
deps = [":runfiles"],
)

# TODO(alexeagle): carry forward #1015 to make this part of the py_wheel macro
py_binary(
name = "wheel.publish",
srcs = ["@publish_deps_twine//:rules_python_wheel_entry_point_twine.py"],
args = [
"upload",
"$(execpath :wheel.dist)/*",
],
data = [":wheel.dist"],
imports = ["."],
main = "@publish_deps_twine//:rules_python_wheel_entry_point_twine.py",
deps = ["@publish_deps_twine//:pkg"],
)
17 changes: 9 additions & 8 deletions python/runfiles/README.md → python/runfiles/README.rst
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@
# bazel-runfiles library
bazel-runfiles library
======================

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

Typical Usage
-------------

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

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

py_binary(
name = "my_binary",
...
deps = [requirement("runfiles")],
)

3. Import the runfiles library.
3. Import the runfiles library::

import runfiles # not "from runfiles import runfiles"

4. Create a Runfiles object and use rlocation to look up runfile paths:
4. Create a Runfiles object and use rlocation to look up runfile paths::

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

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

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

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

If you wnat to start subprocesses, and the subprocess can't automatically
If you want to start subprocesses, and the subprocess can't automatically
find the correct runfiles directory, you can explicitly set the right
environment variables for them:
environment variables for them::

import subprocess
import runfiles
Expand Down
15 changes: 15 additions & 0 deletions tools/publish/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
load("//python:pip.bzl", "compile_pip_requirements")

compile_pip_requirements(
name = "requirements",
requirements_darwin = "requirements_darwin.txt",
requirements_windows = "requirements_windows.txt",
# This fails on RBE right now, and we don't need coverage there:
# WARNING: Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None))
# after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.HTTPSConnection object at 0x7f3784e08110>:
# Failed to establish a new connection: [Errno -3] Temporary failure in name resolution')': /simple/twine/
#
# ERROR: Could not find a version that satisfies the requirement twine==4.0.2
# (from -r tools/publish/requirements.in (line 1)) (from versions: none)
tags = ["no-remote-exec"],
)
6 changes: 6 additions & 0 deletions tools/publish/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Publish to pypi with twine

https://packaging.python.org/en/latest/tutorials/packaging-projects/ indicates that the twine
package is used to publish wheels to pypi.

See more: https://twine.readthedocs.io/en/stable/
1 change: 1 addition & 0 deletions tools/publish/requirements.in
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
twine
Loading

0 comments on commit 68ede14

Please sign in to comment.