File tree Expand file tree Collapse file tree 5 files changed +85
-46
lines changed Expand file tree Collapse file tree 5 files changed +85
-46
lines changed Original file line number Diff line number Diff line change 13
13
- name : Checkout
14
14
uses : actions/checkout@v2
15
15
- name : Prepare workspace snippet
16
- run : .github/workflows/workspace_snippet.sh ${{ env.GITHUB_REF_NAME }} > release_notes.txt
16
+ run : .github/workflows/workspace_snippet.sh > release_notes.txt
17
+ - name : Build wheel dist
18
+ run : bazel build --stamp --embed_label=${{ env.GITHUB_REF_NAME }} //python/runfiles:wheel
19
+ - name : Publish runfiles package to PyPI
20
+ uses : pypa/gh-action-pypi-publish@release/v1
21
+ with :
22
+ # Note, the PYPI_API_TOKEN was added on
23
+ # https://github.com/bazelbuild/rules_python/settings/secrets/actions
24
+ # 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
17
27
- name : Release
18
28
uses : softprops/action-gh-release@v1
19
29
with :
Original file line number Diff line number Diff line change 13
13
# limitations under the License.
14
14
15
15
load ("//python:defs.bzl" , "py_library" )
16
+ load ("//python:packaging.bzl" , "py_wheel" )
16
17
17
18
filegroup (
18
19
name = "distribution" ,
@@ -22,6 +23,26 @@ filegroup(
22
23
23
24
py_library (
24
25
name = "runfiles" ,
25
- srcs = ["runfiles.py" ],
26
+ srcs = [
27
+ "__init__.py" ,
28
+ "runfiles.py" ,
29
+ ],
26
30
visibility = ["//visibility:public" ],
27
31
)
32
+
33
+ # TODO(alexeagle): add some example which depends on this wheel to verify it can be used
34
+ py_wheel (
35
+ name = "wheel" ,
36
+ # From https://pypi.org/classifiers/
37
+ classifiers = [
38
+ "Development Status :: 5 - Production/Stable" ,
39
+ "License :: OSI Approved :: Apache Software License" ,
40
+ ],
41
+ description_file = "README.md" ,
42
+ distribution = "bazel_runfiles" ,
43
+ homepage = "https://github.com/bazelbuild/rules_python" ,
44
+ strip_path_prefixes = ["python" ],
45
+ version = "{BUILD_EMBED_LABEL}" ,
46
+ visibility = ["//visibility:public" ],
47
+ deps = [":runfiles" ],
48
+ )
Original file line number Diff line number Diff line change
1
+ # bazel-runfiles library
2
+
3
+ This is a Bazel Runfiles lookup library for Bazel-built Python binaries and tests.
4
+
5
+ Typical Usage
6
+ -------------
7
+
8
+ 1 . Add the 'runfiles' dependency along with other third-party dependencies, for example in your
9
+ ` requirements.txt ` file.
10
+
11
+ 2 . Depend on this runfiles library from your build rule, like you would other third-party libraries.
12
+
13
+ py_binary(
14
+ name = "my_binary",
15
+ ...
16
+ deps = [ requirement("runfiles")] ,
17
+ )
18
+
19
+ 3 . Import the runfiles library.
20
+
21
+ import runfiles
22
+
23
+ 4 . Create a Runfiles object and use rlocation to look up runfile paths:
24
+
25
+ r = runfiles.Create()
26
+ ...
27
+ with open(r.Rlocation("my_workspace/path/to/my/data.txt"), "r") as f:
28
+ contents = f.readlines()
29
+ ...
30
+
31
+ The code above creates a manifest- or directory-based implementations based
32
+ on the environment variables in os.environ. See ` Create() ` for more info.
33
+
34
+ If you want to explicitly create a manifest- or directory-based
35
+ implementations, you can do so as follows:
36
+
37
+ r1 = runfiles.CreateManifestBased("path/to/foo.runfiles_manifest")
38
+
39
+ r2 = runfiles.CreateDirectoryBased("path/to/foo.runfiles/")
40
+
41
+ If you want to start subprocesses that also need runfiles, you need to set
42
+ the right environment variables for them:
43
+
44
+ import subprocess
45
+ import runfiles
46
+
47
+ r = runfiles.Create()
48
+ env = {}
49
+ ...
50
+ env.update(r.EnvVars())
51
+ p = subprocess.Popen([ r.Rlocation("path/to/binary")] , env, ...)
Original file line number Diff line number Diff line change
1
+ from .runfiles import *
Original file line number Diff line number Diff line change 13
13
# limitations under the License.
14
14
15
15
"""Runfiles lookup library for Bazel-built Python binaries and tests.
16
-
17
- USAGE:
18
-
19
- 1. Depend on this runfiles library from your build rule:
20
-
21
- py_binary(
22
- name = "my_binary",
23
- ...
24
- deps = ["@rules_python//python/runfiles"],
25
- )
26
-
27
- 2. Import the runfiles library.
28
-
29
- from python.runfiles import runfiles
30
-
31
- 3. Create a Runfiles object and use rlocation to look up runfile paths:
32
-
33
- r = runfiles.Create()
34
- ...
35
- with open(r.Rlocation("my_workspace/path/to/my/data.txt"), "r") as f:
36
- contents = f.readlines()
37
- ...
38
-
39
- The code above creates a manifest- or directory-based implementations based
40
- on the environment variables in os.environ. See `Create()` for more info.
41
-
42
- If you want to explicitly create a manifest- or directory-based
43
- implementations, you can do so as follows:
44
-
45
- r1 = runfiles.CreateManifestBased("path/to/foo.runfiles_manifest")
46
-
47
- r2 = runfiles.CreateDirectoryBased("path/to/foo.runfiles/")
48
-
49
- If you want to start subprocesses that also need runfiles, you need to set
50
- the right environment variables for them:
51
-
52
- import subprocess
53
- from bazel_tools.tools.python.runfiles import runfiles
54
-
55
- r = runfiles.Create()
56
- env = {}
57
- ...
58
- env.update(r.EnvVars())
59
- p = subprocess.Popen([r.Rlocation("path/to/binary")], env, ...)
60
16
"""
61
17
62
18
import os
You can’t perform that action at this time.
0 commit comments