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

(Bazel) AttributeError: module 'mmh3' has no attribute 'hash' #50

Closed
vonschultz opened this issue Aug 18, 2023 · 3 comments
Closed

(Bazel) AttributeError: module 'mmh3' has no attribute 'hash' #50

vonschultz opened this issue Aug 18, 2023 · 3 comments
Assignees
Labels

Comments

@vonschultz
Copy link

vonschultz commented Aug 18, 2023

Consider: mmh3.hash("Hello World").

Expected behavior: returns 427197390

Actual behavior: raises exception AttributeError: module 'mmh3' has no attribute 'hash'

Regression: This works in version 4.0.0. The error is triggered in version 4.0.1.

Environment: Curiously, this seems to happen when running the test through Bazel, not when installing into a virtual environment. Not sure if the bug is on the mmh3 side or the Bazel side, but something changed between 4.0.0 and 4.0.1. Can you help me figure out what?

To reproduce, get the gist from https://gist.github.com/vonschultz/18b4e58a697d56c8cc421528e0a4ef13 and run

bazelisk test --test_output=streamed //...

Get bazelisk from https://github.com/bazelbuild/bazelisk/releases if you don't already have it.

I'm running Ubuntu 20.04.

@hajimes
Copy link
Owner

hajimes commented Aug 23, 2023

Hi, I honestly appreciate your detailed report! It has helped me a lot to reproduce the issue. Currently I'm still trying to figure out how to fix the problem. Since 4.0.1 is functionally identical to 4.0.0, I suggest you to use the previous version at the moment.

What I found so far is that for 4.0.1, __init__.py files are auto-generated in /mmh3 and /mmh3/_mmh3 under the directory ./bazel-bin/mmh3_401_test.runfiles/pip_dependencies_401_mmh3/site-packages. However, for 4.0.0, these files are not generated automatically by Bazel. I'm not sure what causes this difference.

The following issue report may or may not be related to this problem. I will continue to investigate the issue, but I'll be thankful if someone who is familiar with the implementation details of Bazel can give me advice.
bazelbuild/rules_python#381

@hajimes hajimes self-assigned this Aug 23, 2023
@hajimes hajimes added the bug label Aug 23, 2023
@hajimes
Copy link
Owner

hajimes commented Aug 24, 2023

I finally identified the cause of the problem.

Notice to Bazel users

Please use 4.0.0 at the moment, which is functionally identical to 4.0.1.

Technical issues

The decision process of the auto-generation of __init__.py (which leads to raise AttributeError) is described in the following pull request.
bazelbuild/rules_python#483

  • Because src/mmh3/_mmh3 (newly added in 4.0.1) includes refresh.py, it is recognized as a package.
  • src/mmh3 is now recognized as a namespace package, because it is the parent of a directory that is a package (src/mmh3/_mmh3).
  • So Bazel auto-generates __init__.py in src/mmh3/, which prevents the loading of mmh3.(...).so.

Since refresh.py is just a utility file to generate C files, there is no reason to keep it in the production. I plan to remove this file from MANIFEST.in and release 4.0.2 until around the middle of the next week.

@hajimes
Copy link
Owner

hajimes commented Jan 9, 2024

I am so sorry for being this late but the fix was finally incorporated into the main branch and released as 4.1.0. Thank you very much again for providing detailed information and helpful files to reproduce the issue!

@hajimes hajimes closed this as completed Jan 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants