Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
dzbarsky opened this issue Oct 5, 2023 · 5 comments

Comments

@dzbarsky
Copy link
Contributor

dzbarsky commented Oct 5, 2023

🐞 bug report

Affected Rule

with open(ns_pkg_init_filepath, "w") as ns_pkg_init_f:
# See https://packaging.python.org/guides/packaging-namespace-packages/#pkgutil-style-namespace-packages
ns_pkg_init_f.write(
textwrap.dedent(
"""\
# __path__ manipulation added by bazelbuild/rules_python to support namespace pkgs.
__path__ = __import__('pkgutil').extend_path(__path__, __name__)
"""
)
)

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

if os.path.isfile(ns_pkg_init_filepath):
raise ValueError("%s already contains an __init__.py file." % dir_path)
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?

Copy link

github-actions bot commented Apr 2, 2024

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!

@github-actions github-actions bot added the Can Close? Will close in 30 days if there is no new activity label Apr 2, 2024
@dzbarsky
Copy link
Contributor Author

This is still an active issues, please keep open

@aignas aignas added type: bug type: pip and removed Can Close? Will close in 30 days if there is no new activity labels Apr 20, 2024
@groodt
Copy link
Collaborator

groodt commented Aug 24, 2024

Potentially related: #2156

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

@groodt groodt closed this as completed Aug 24, 2024
@groodt groodt reopened this Aug 24, 2024
@engnatha
Copy link

I was able to get around this by setting enable_implicit_namespace_pkgs = True in the pip_parse target.

@engnatha
Copy link

engnatha commented Dec 3, 2024

To follow up on my comment above, while this does allow the import to work, it wipes any data directories that don't have any python files. There's some flink directories that contain only java archive files. Still discovering when precisely those are needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants