bazel-runfiles

100 个版本 Python >=3.7
安装
pip install bazel-runfiles
poetry add bazel-runfiles
pipenv install bazel-runfiles
conda install bazel-runfiles
描述

bazel-runfiles library

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.

Importing

The Runfiles API is available from two sources, a direct Bazel target, and a pypi package.

Pure Bazel imports

  1. Depend on this runfiles library from your build rule, like you would other third-party libraries:

    py_binary(
        name = "my_binary",
        # ...
        deps = ["@rules_python//python/runfiles"],
    )
    
  2. Import the runfiles library:

        from python.runfiles import Runfiles
    

Pypi imports

  1. Add the 'bazel-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:

    load("@pip_deps//:requirements.bzl", "requirement")
    
    py_binary(
        name = "my_binary",
        ...
        deps = [requirement("bazel-runfiles")],
    )
    
  3. Import the runfiles library:

    from runfiles import Runfiles
    

Typical Usage

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()
    # ...

Here my_workspace is the name you specified via module(name = "...") in your MODULE.bazel file (with --enable_bzlmod, default as of Bazel 7) or workspace(name = "...") in WORKSPACE (with --noenable_bzlmod).

The code above creates a manifest- or directory-based implementation based on the environment variables in os.environ. See Runfiles.Create() for more info.

If you want to explicitly create a manifest- or directory-based implementation, 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 access runfiles, you have to set the right environment variables for them:

import subprocess
from python.runfiles import Runfiles

r = Runfiles.Create()
env = {}
# ...
env.update(r.EnvVars())
p = subprocess.run(
    [r.Rlocation("path/to/binary")],
    env=env,
    # ...
)
版本列表
2.1.0rc0 2026-06-18
2.0.3 2026-06-16
2.0.2 2026-05-23
2.0.1 2026-05-10
2.0.0 2026-04-28
2.0.0rc4 2026-04-24
2.0.0rc3 2026-04-20
2.0.0rc2 2026-04-15
2.0.0rc1 2026-04-14
2.0.0rc0 2026-04-14
1.9.1 2026-05-23
1.9.0 2026-03-04
1.9.0rc1 2026-02-23
1.9.0rc0 2026-02-23
1.8.5 2026-02-23
1.8.4 2026-02-11
1.8.3 2026-01-28
1.8.2 2026-01-25
1.8.1 2026-01-21
1.8.0 2026-01-16
1.8.0rc4 2026-01-15
1.8.0rc3 2026-01-11
1.8.0rc2 2026-01-10
1.8.0rc1 2025-12-22
1.8.0rc0 2025-12-20
1.7.0 2025-11-14
1.7.0rc6 2025-11-09
1.7.0rc5 2025-11-06
1.7.0rc4 2025-10-31
1.7.0rc3 2025-10-30
1.7.0rc2 2025-10-29
1.7.0rc0 2025-10-15
1.6.3 2025-09-21
1.6.1 2025-09-08
1.6.0 2025-09-02
1.6.0rc0 2025-08-24
1.5.4 2025-08-28
1.5.3 2025-08-11
1.5.2 2025-08-11
1.5.1 2025-07-06
1.5.0 2025-06-30
1.5.0rc4 2025-06-26
1.5.0rc3 2025-06-25
1.5.0rc2 2025-06-20
1.5.0rc1 2025-06-17
1.5.0rc0 2025-06-12
1.4.2 2025-08-18
1.4.1 2025-05-08
1.4.0 2025-05-05
1.4.0rc4 2025-04-29
1.4.0rc3 2025-04-29
1.4.0rc2 2025-04-24
1.4.0rc1 2025-04-22
1.4.0rc0 2025-04-21
1.3.0 2025-03-27
1.3.0rc1 2025-03-21
1.3.0rc0 2025-03-21
1.2.0 2025-02-27
1.2.0rc1 2025-02-22
1.2.0rc0 2025-02-14
1.1.0 2025-01-17
1.1.0rc1 2025-01-13
1.1.0rc0 2025-01-09
1.0.0 2024-12-06
1.0.0rc2 2024-11-29
1.0.0rc1 2024-11-26
1.0.0rc0 2024-11-22
0.40.0 2024-11-17
0.39.0 2024-11-13
0.38.0 2024-11-08
0.37.2 2024-10-27
0.37.1 2024-10-23
0.37.0 2024-10-18
0.36.0 2024-09-24
0.35.0 2024-08-15
0.34.0 2024-07-04
0.33.2 2024-06-19
0.33.1 2024-06-12
0.33.0 2024-06-12
0.32.2 2024-05-14
0.32.1 2024-05-13
0.32.0 2024-05-13
0.31.0 2024-02-13
0.30.0 2024-02-12
0.29.0 2024-01-22
0.28.0 2024-01-08
0.27.1 2023-12-05
0.27.0 2023-11-17
0.26.0 2023-10-06
0.25.0 2023-08-22
0.24.0 2023-07-11
0.23.1 2023-06-13
0.23.0 2023-06-12
0.22.1 2023-12-19
0.22.0 2023-05-25
0.21.0 2023-04-20
0.20.0 2023-03-20
0.19.0 2023-02-28
0.18.1 2023-02-14
0.18.0 2023-02-08