[Python] What is the right way to refer bazel data files in python?

Discussão em 'Python' iniciado por Stack, Abril 14, 2025.

  1. Stack

    Stack Membro Participativo

    Suppose I have the following BUILD file

    py_library(
    name = "foo",
    src = ["foo.py"],
    data = ["//bar:data.json"],
    )


    How should I refer to the data.json in foo.py file? I wanted to have something like below, what should I use for some_path?

    with open(os.path.join(some_path, "bar/data.json"), 'r') as fp:
    data = json.load(fp)


    I couldn't find much general documentation about *.runfiles online -- any pointer will be appreciated!

    Continue reading...

Compartilhe esta Página