soniaai / rules_poetry

Bazel rules that use Poetry for Python package management
MIT License
72 stars 22 forks source link

target 'library_pytest' not declared in package '' #19

Open ibolit opened 1 year ago

ibolit commented 1 year ago

What I am doing: I copied the WORKSPACE setup verbatim and added a poetry dependency to one of my targets. This configuration worked, then I worked on some other Bazel functionality for my project. When I tried running tests after I was done with my other functionality, the rules_poetry seem to no longer work.

That other functionality has nothing to do with poetry or pip, but it does involve building wheels from my source code, it uses the standard python_rules py_package and py_wheel for that.

What is the problem: When I run bazel test ..., I get this error:

bazel test ...
ERROR: /Users/me/Work/dialog_platform/_experimental_lib_for_bazel/BUILD.bazel:16:8: no such target '@poetry//:library_fastapi': target 'library_fastapi' not declared in package '' defined by /private/var/tmp/_bazel_me/69e3e7ed8e1fbf19ba79afe448a27e50/external/poetry/BUILD and referenced by '//_experimental_lib_for_bazel:test_experimental_lib_for_bazel'
ERROR: /Users/me/Work/dialog_platform/_experimental_lib_for_bazel/BUILD.bazel:16:8: no such target '@poetry//:library_pytest': target 'library_pytest' not declared in package '' defined by /private/var/tmp/_bazel_me/69e3e7ed8e1fbf19ba79afe448a27e50/external/poetry/BUILD and referenced by '//_experimental_lib_for_bazel:test_experimental_lib_for_bazel'
ERROR: Analysis of target '//_experimental_lib_for_bazel:test_experimental_lib_for_bazel' failed; build aborted: Analysis failed
INFO: Elapsed time: 0.432s
INFO: 0 processes.
FAILED: Build did NOT complete successfully (0 packages loaded, 0 targets configured)
FAILED: Build did NOT complete successfully (0 packages loaded, 0 targets configured)

This is the complete output of the command.

I tried reproducing this problem on another computer, but couldn't.

I tried running bazel clean and cleaning my poetry caches as well. It did not help

NathanHowell commented 1 year ago

what is in the generated build file private/var/tmp/_bazel_me/69e3e7ed8e1fbf19ba79afe448a27e50/external/poetry/BUILD ?

ibolit commented 1 year ago

Hello, sorry, I was off work.

Here are the contents of /private/var/tmp/_bazel_me/69e3e7ed8e1fbf19ba79afe448a27e50/external/poetry/BUILD

load("//:defs.bzl", "download_wheel")
load("//:defs.bzl", "noop")
load("//:defs.bzl", "pip_install")
NathanHowell commented 1 year ago

@ibolit can you make a self contained repro? do you know if you have multiple repo rules named poetry that could lead to one being overwritten?

ibolit commented 1 year ago

@NathanHowell I am not sure I can, I will try some time later. I seriously suspect something "got broken" while I was working on my own rules, because, for one thing, the "regular" poetry stopped installing some packages (like, pytest), it just hung and did nothing, but that stopped when I cleaned poetry caches.

About other rules named poetry — I did have that at some point. I am using an inhouse tool that seemed to require a poetry executable, which only checked that an executable named poetry existed and that it was indeed executable, but didn't use it, so I wrote an sh_binary with the name poetry to satisfy that. However, it turned out that I could use that inouse tool without it checking for poetry, so I removed that sh_binary altogether.

For now, I have replaced rules_poetry with rules_python/pip_parse, but using poetry would be much more preferable. I will try and check if the commits with poetry_rules work on my colleagues' machines.

Are there any more files I could check or caches I could clean besides bazel clean?

ibolit commented 1 year ago

@NathanHowell After I wrote the previous thing, I asked myself that last question and then googled it. I found this:

rm -r $(bazel info repository_cache)

After that, my commits that still have rule_poetry in them, started working again.

In fact, you mentioning other targets named poetry helped me a lot. Thank you for your patience.

ibolit commented 1 year ago

Sorry, I checked again. It didn't start working

Some more information that might be useful:

Our poetry version is 1.2.2

When I try to run bazel test on my py_test target, I get a lot of these lines in my bazel stderr:

DEBUG: /private/var/tmp/_bazel_me/69e3e7ed8e1fbf19ba79afe448a27e50/external/com_sonia_rules_poetry/rules_poetry/poetry.bzl:80:18: Skipping pytest

Seemingly, for all of the dependencies in my pyproject.toml, not just pytest