rules_python
rules_python copied to clipboard
pip_parse is not installing flask, asking for the packages jinja2, itsdangerous etc. for any python package like requests or pandas same issue is there.
continuoulsy asking packages for flask, if you include them in requirements.txt, it is asking for some other package. i am using bazel 7.1.1
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
http_archive( name = "rules_python", sha256 = "c68bdc4fbec25de5b5493b8819cfc877c4ea299c0dcb15c244c5a00208cde311", strip_prefix = "rules_python-0.31.0", url = "https://github.com/bazelbuild/rules_python/releases/download/0.31.0/rules_python-0.31.0.tar.gz", )
load("@rules_python//python:repositories.bzl", "py_repositories")
py_repositories()
load("@rules_python//python:repositories.bzl", "python_register_toolchains")
python_register_toolchains( name = "python3_11", # Available versions are listed in @rules_python//python:versions.bzl. python_version = "3.11", )
load("@python3_11//:defs.bzl", "interpreter")
load("@rules_python//python:pip.bzl", "pip_parse")
pip_parse( python_interpreter_target = interpreter, name = "my_deps", requirements_lock = "//third_party:requirements.txt", environment = { "PIP_REQUIRE_VIRTUALENV": "", }
)
load("@my_deps//:requirements.bzl", "install_deps")
install_deps()
workspace. bazel file
load("@my_deps//:requirements.bzl", "requirement") load("@rules_python//python:defs.bzl", "py_binary")
#load("@rules_python//python:repositories.bzl", "py_repositories")
py_binary( name = "main", srcs = ["main.py"], deps = ["//calc:calculator","@my_deps_flask//:pkg" ],
)BUILD.bazel file.
error msg: Fetching target dependencies for deps(//app:main) encountered an error: Evaluation of query "deps(//app:main)" failed: preloading transitive closure failed: no such package '@@my_deps_blinker//': The repository '@@my_deps_blinker' could not be resolved: Repository '@@my_deps_blinker' is not defined
I have found that you need to use the pip_compile_requirements rule to create the requirements_lock.txt file. If you do so, all the packages that a module depends on will be added in that requirements_lock.txt file. I have made an example when I tried to get it working https://github.com/pat-jpnk/bazel_pip_example/tree/main
We also have a examples/bzlmod
and exmples/pip_parse
examples. Consider looking at them.