bazelbuild / rules_python

Bazel Python Rules
https://rules-python.readthedocs.io
Apache License 2.0
516 stars 532 forks source link

Namespace package __path__ manipulation breaks packages using __init__.py to define code #1464

Open dzbarsky opened 11 months ago

dzbarsky commented 11 months ago

🐞 bug report

Affected Rule

https://github.com/bazelbuild/rules_python/blob/fe33a4582c37499f3caeb49a07a78fc7948a8949/python/pip_install/tools/wheel_installer/namespace_pkgs.py#L90-L99

Is this a regression?

Not sure, first time I have tried this.

Description

The code in the package's source init.py seems to get overwritten. I'm not fully sure why, it appears that https://github.com/bazelbuild/rules_python/blob/fe33a4582c37499f3caeb49a07a78fc7948a8949/python/pip_install/tools/wheel_installer/namespace_pkgs.py#L87-L88 is trying to guard against it.

If possible, it would be nice to lay out a site_packages that is less hacky.

πŸ”¬ Minimal Reproduction

https://github.com/dzbarsky/rules_python_pylink_bug

bazel test //:flink_import_test

πŸ”₯ Exception or Error


ImportError: cannot import name 'add_version_doc' from 'pyflink' (/private/var/tmp/_bazel_zbarsky/45e7e567ddccd93ad1b41c75488b912d/sandbox/darwin-sandbox/13/execroot/__main__/bazel-out/darwin-fastbuild/bin/flink_import_test.runfiles/pip_apache_flink_libraries/site-packages/pyflink/__init__.py)

🌍 Your Environment

Operating System:

  

  

Output of bazel version:

  
Bazelisk version: development
Build label: 6.3.2
Build target: bazel-out/darwin-opt/bin/src/main/java/com/google/devtools/build/lib/bazel/BazelServer_deploy.jar
Build time: Tue Aug 8 15:58:06 2023 (1691510286)
Build timestamp: 1691510286
Build timestamp as int: 1691510286
  

Rules_python version:

  
0.25
  

Anything else relevant?

github-actions[bot] commented 5 months ago

This issue has been automatically marked as stale because it has not had any activity for 180 days. It will be closed if no further activity occurs in 30 days. Collaborators can add an assignee to keep this open indefinitely. Thanks for your contributions to rules_python!

dzbarsky commented 4 months ago

This is still an active issues, please keep open

groodt commented 2 weeks ago

Potentially related: https://github.com/bazelbuild/rules_python/issues/2156

I'm not completely sure that this is caused by lack of site-packages, so I won't close this as a duplicate.