Skip to main content

No project description provided

Project description

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 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

bazel_runfiles-0.18.0-py3-none-any.whl (6.9 kB view details)

Uploaded Python 3

File details

Details for the file bazel_runfiles-0.18.0-py3-none-any.whl.

File metadata

File hashes

Hashes for bazel_runfiles-0.18.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6a01db9f6677505db864db0362ff4a4e8cd6f0b593ef2fbe73e6501391ff9753
MD5 513b481a08ebb9fdf13629afbcbbb9ce
BLAKE2b-256 a1e6c844df5c8701b9a6cb6597f095ccfd832972ffbaf7dd40f9aba8e1c19e65

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page