Skip to content

An unusual issue arising from the manner in which rules_python manages namespace packages. #1886

Closed
@Agent-Hellboy

Description

@Agent-Hellboy

🐞 bug report

Affected Rule

The issue is caused by the rule:

Is this a regression?

Yes, the previous version in which this bug was not present was: ....

Description

A clear and concise description of the problem...

Hi,

I'm relatively new to Bazel and have only started using it a few days ago. I've gone through some introductory documentation.

In rules_python, I've noticed that it adds init.py files to every namespace package. I assume this is done to convert Python packages into Bazel packages with a BUILD file. However, I'm puzzled as to why it adds init.py to namespace package.

Recently, I encountered an issue where an unnecessary init.py file was added. Specifically, it was added to python_local_deps_pyqt5/site-packages/PyQt5/uic/widget-plugins. I'm not sure why this was done, as it doesn't seem necessary.

PyQt5 dynamically loads these plugins at runtime using Python's exec API, which assumes a certain structure. Because of this, You can't simply add the init.py file without proper justification.

It seems that rules_python adds init.py files primarily to include a path variable. However, I believe rules_python should only add init.py files when converting a package into a Bazel package.

If you have any insights into why rules_python behaves this way or how I can resolve the issue with the unnecessary init.py file, I would greatly appreciate your input. (I guess only way is to avoid adding init.py or i need to patch the load_plugin method of pyqt5 library)

🔬 Minimal Reproduction

Install PyQt5 as an external dependency using rules_python. Then, attempt to load a .ui file using uic. This process will require loading a plugin, which may result in an error.

🔥 Exception or Error




 File "/var/tmp/proshan/c7b4a059b4e2be58/cpu/applications/bazel_output_base/execroot/cap/bazel-out/k8-opt-a3-bn_h10/bin/hwio/dma/scheduler/dma_scheduler.runfiles/python_local_deps_pyqt5/site-packages/PyQt5/uic/objcreator.py", line 158, in load_plugin
    raise WidgetPluginError("%s: %s" % (e.__class__, str(e)))
PyQt5.uic.exceptions.WidgetPluginError: : name '__path__' is not defined

🌍 Your Environment

Operating System:

  
Linux aws-devel-02 5.4.0-1103-aws #111~18.04.1-Ubuntu SMP Tue May 23 20:04:10 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux
  

Output of bazel version:

  
bazel 6.1.1
  

Rules_python version:

  
rules_python-0.31.0
  

Anything else relevant?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions