Correct handling of imports
rule attribute on py...
rules
#6599
Labels
awaiting-maintainer
Awaiting review from Bazel team on issues
product: Android Studio
Android Studio plugin
product: CLion
CLion plugin
product: GoLand
GoLand plugin
product: IntelliJ
IntelliJ plugin
product: PyCharm
PyCharm plugin
type: bug
Description of the bug:
Note: See the associated PR.
I have marked all IDEs because I assume they will all experience the same problem when handling Python targets.
Some of the
rules_python
rules such aspy_library
andpy_binary
have the ability to supply animports
attribute. For example consider the following Bazel repo setup;The
BUILD.bazel
may carry the following rule;At the point of use in
main.py
, some Python library functions in those files would be;If the rule is changed to introduce the
imports
attribute......then the associated Python module path is rooted at the same point as the
BUILD.bazel
file and includes theimports
. At the point of use inmain.py
, the reference to the library functions would become;The expected behavior of the Intelli-J plugin would be to identify the use of
imports
attribute inpy_...
rules and to adjust the module paths accordingly. The actual behavior seems to be to ignore theimports
attribute.Changes in can be made to support the
imports
feature. The data from theimports
attribute needs to be fed through from the executed aspect via the proto and can then be post-processed inAbstractPyImportResolverStrategy
to replicate the observed behavior of Bazel.Which category does this issue belong to?
Intellij, GoLand, CLion, PyCharm, Android Studio
What's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.
Please find attached a tar-ball
support-py-imports-example-20240729.tgz
.bazelisk run "//aaa/bbb/ccc:prog"
. On output you should see;BUILD.bazel
fileimports
is set toddd
main.py
The Intelli-J plugin should be accepting the paths in consideration of the
imports
.Which Intellij IDE are you using? Please provide the specific version.
Intelli-J 2024.1
What programming languages and tools are you using? Please provide specific versions.
Python 3.10
What Bazel plugin version are you using?
7.2
Have you found anything relevant by searching the web?
No response
Any other information, logs, or outputs that you want to share?
Screenshots
Screenshot before without the patch in place;
Screenshot after with the patch in place;
Further known issue
There is a further complication that occurs when intermediate module parts are empty. For example;
If the
imports
here were["d"]
then the IDE plugin would fail to recognize the module parte
because it does not contain anything. This issue does not cover this scenario; it is considered to be a separate issue.The text was updated successfully, but these errors were encountered: