1

Trying to build a set up Python package dependencies with rules_python per these instructions but when running bazel build I get this error:

ERROR: error loading package under directory '':
error loading package 'zzz':
Unable to find package for @my_deps//:requirements.bzl:
The repository '@my_deps' could not be resolved:
Repository '@my_deps' is not defined.

WORKSPACE file:

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

rules_python_version = "740825b7f74930c62f44af95c9a4c1bd428d2c53" # Latest @ 2021-06-23
http_archive(
    name = "rules_python",
    sha256 = "3474c5815da4cb003ff22811a36a11894927eda1c2e64bf2dac63e914bfdf30f",
    strip_prefix = "rules_python-{}".format(rules_python_version),
    url = "https://github.com/bazelbuild/rules_python/archive/{}.zip".format(rules_python_version),
)

and the BUILD file:

load("@rules_python//python:pip.bzl", "pip_parse")

pip_parse(
   name = "my_deps",
   requirements_lock = "requirements.txt",
)
load("@my_deps//:requirements.bzl", "install_deps", "requirement")
install_deps()

Is pip_parse responsible for creating the repository @my_deps? If so, why can't it be found by load?

If it matters, this is on Windows 10.

tomocafe
  • 1,425
  • 4
  • 20
  • 35

1 Answers1

2

pip_parse should go into the WORKSPACE file, not the BUILD file.

If you put it in the BUILD file by mistake, you might get this error.

Hopefully this helps a future searcher who might make the same mistake.

tomocafe
  • 1,425
  • 4
  • 20
  • 35
  • But what if you really have to call pip_parse on various requirement.txts present in various python project folders , how can we load a specific .bzl with a function like req_parse() which in turn will call pip_parse and appropriate install_deps() ? – a k Mar 16 '23 at 13:43
  • I'm a Bazel newbie, but my project does have multiple sub-packages with their own requirements.txt files and I just put them all in my workspace. The sequence of `pip_parse`, `load`, and `install_deps` is just repeated for the different sub-packages. – tomocafe Mar 17 '23 at 15:20
  • thanks for the reply, wondering what the design pattern would look like if I cannot put all these various python apps with their individual requriement.txt at the top workspace file and instead have only one entry point in WORKSPACE file for python projects so that I can deal with my reqs internally in .bzl files and functions. – a k Mar 17 '23 at 18:49