-
-
Notifications
You must be signed in to change notification settings - Fork 594
chore: publish a runfiles library as a wheel #995
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
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,52 @@ | ||
# 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 # not "from runfiles 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 wnat to start subprocesses, and the subprocess can't automatically | ||
find the correct runfiles directory, you can explicitly 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 hidden or 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 hidden or 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 hidden or 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,10 @@ | ||
#!/usr/bin/env bash | ||
# Manual test, run outside of Bazel, to check that our runfiles wheel should be functional | ||
# for users who install it from pypi. | ||
set -o errexit | ||
|
||
SCRIPTPATH="$( cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )" | ||
|
||
bazel 2>/dev/null build --stamp --embed_label=1.2.3 //python/runfiles:wheel | ||
wheelpath=$SCRIPTPATH/../../$(bazel 2>/dev/null cquery --output=files //python/runfiles:wheel) | ||
PYTHONPATH=$wheelpath python3 -c 'import importlib;print(importlib.import_module("runfiles"))' |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.