No project description provided
Project description
This is a Bazel Runfiles lookup library for Bazel-built Python binaries and tests.
Learn about runfiles: read Runfiles guide or watch Fabian’s BazelCon talk.
Typical Usage
Add the ‘bazel-runfiles’ dependency along with other third-party dependencies, for example in your requirements.txt file.
Depend on this runfiles library from your build rule, like you would other third-party libraries:
py_binary( name = "my_binary", ... deps = [requirement("bazel-runfiles")], )
Import the runfiles library:
import runfiles # not "from runfiles import runfiles"
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, 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, ...)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
File details
Details for the file bazel_runfiles-0.25.0-py3-none-any.whl
.
File metadata
- Download URL: bazel_runfiles-0.25.0-py3-none-any.whl
- Upload date:
- Size: 7.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f74c1865bbb27824c21775a76d6939206eaa3be75106093ee11615875dd2c935 |
|
MD5 | 848e96ac36bec3517032ed3ae9d99310 |
|
BLAKE2b-256 | 3c87acb2d68ebd96d7abbc44507dd1903b3c0dc130a7de3efa629f9daeed1c19 |