-
Notifications
You must be signed in to change notification settings - Fork 541
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: publish a runfiles library as a wheel
Wire it up to GH actions so it is published for each release. Tested locally with: bazel build python/runfiles:wheel --embed_label=1.0.2 --stamp PYTHONPATH=bazel-bin/python/runfiles/bazel_runfiles-_BUILD_EMBED_LABEL_-py3-none-any.whl python >>> import runfiles >>> runfiles.Create() Note, I would have liked to call the package bazel-runfiles, but this isn't possible without either refactoring the paths in this repo, or doing some fancy starlark to copy files around to create a folder that we turn into the wheel. There is no project https://pypi.org/project/runfiles though there is a https://pypi.org/project/runfile We could try harder to get the name we prefer.
- Loading branch information
Showing
5 changed files
with
85 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
# 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. | ||
|
||
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. | ||
|
||
import runfiles | ||
|
||
4. Create a Runfiles object and use rlocation to look up runfile paths: | ||
|
||
r = runfiles.Create() | ||
... | ||
with open(r.Rlocation("my_workspace/path/to/my/data.txt"), "r") as f: | ||
contents = f.readlines() | ||
... | ||
|
||
The code above creates a manifest- or directory-based implementations based | ||
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: | ||
|
||
r1 = runfiles.CreateManifestBased("path/to/foo.runfiles_manifest") | ||
|
||
r2 = runfiles.CreateDirectoryBased("path/to/foo.runfiles/") | ||
|
||
If you want to start subprocesses that also need runfiles, you need to set | ||
the right environment variables for them: | ||
|
||
import subprocess | ||
import runfiles | ||
|
||
r = runfiles.Create() | ||
env = {} | ||
... | ||
env.update(r.EnvVars()) | ||
p = subprocess.Popen([r.Rlocation("path/to/binary")], env, ...) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from .runfiles import * |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters