Skip to content

fix(release): minimum needed to run twine to publish #1021

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Feb 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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