-
Notifications
You must be signed in to change notification settings - Fork 558
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
experimental_index_url
fails to import TensorFlow package correctly in the build context
#1996
Comments
In order to use the feature you need to lock the requirements file using rules uv or rules python. The index url flag currently does not support requirements files without hashes. |
@aignas Thank you for taking a moment to reply to the issue and contribute this feature to the project. Here's some additional context on the matter. I am currently locking the requirements file, as shown here, which was generated using compile_pip_requirements provided by rules_python. To clarify, the experimental index URL works with other packages such as numpy or pandas, etc., but it does not work with tensorflow. This is because tensorflow brings in dynamic packages depending on the operating system. For example, tensorflow brings in tensorflow-macos when running on darwin.
Interestingly, or I guess expectedly, if you import tensorflow using |
Ah yes, sorry for not noticing the file in the repo via github UI. Until I get time to look at this, you could use bazel cquery on the failing target to filter out py_library deps targets and add them here. What would also help to include in the example is the module.bazel.lock file. The cquery command might look something like
Give or take a few quotes. This will at least tell you if the dependency is included in the sandbox. |
Here's the output of ⋊> ~/P/py on main bazel cquery "kind(py_library, deps(//:dataset))" (base) 21:33:14
INFO: Options provided by the client:
Inherited 'common' options: --isatty=1 --terminal_columns=204
INFO: Reading rc options for 'cquery' from /Users/sundaramananthanarayanan/Projects/py/.bazelrc:
Inherited 'build' options: --announce_rc --color=yes
INFO: Analyzed target //:dataset (0 packages loaded, 0 targets configured).
INFO: Found 1 target...
@@rules_python~~pip~pypi_39_tensorflow_cp39_cp39_macosx_12_0_arm64_896bda03//:pkg (096dcc8)
@@rules_python~~pip~pypi_39_numpy_cp39_cp39_macosx_11_0_arm64_9667575f//:pkg (096dcc8)
INFO: Elapsed time: 0.269s, Critical Path: 0.00s
INFO: 0 processes.
INFO: Build completed successfully, 0 total actions |
FWIW, when I execute the same command on an earlier version of rules_python commit, I am able to use tensorflow with the ⋊> ~/P/py on main ⨯ bazel cquery "kind(py_library, deps(//:dataset))" (base) 21:40:03
INFO: Options provided by the client:
Inherited 'common' options: --isatty=1 --terminal_columns=204
INFO: Reading rc options for 'cquery' from /Users/sundaramananthanarayanan/Projects/py/.bazelrc:
Inherited 'build' options: --announce_rc --color=yes
INFO: Analyzed target //:dataset (35 packages loaded, 332 targets configured).
INFO: Found 1 target...
@@rules_python~~pip~pypi_39_tensorflow//:pkg (096dcc8)
@@rules_python~~pip~pypi_39_numpy//:pkg (096dcc8)
@@rules_python~~pip~pypi_39_tensorflow_macos//:pkg (096dcc8)
@@rules_python~~pip~pypi_39_six//:pkg (096dcc8)
@@rules_python~~pip~pypi_39_tensorflow_io_gcs_filesystem//:pkg (096dcc8)
@@rules_python~~pip~pypi_39_wrapt//:pkg (096dcc8)
@@rules_python~~pip~pypi_39_gast//:pkg (096dcc8)
@@rules_python~~pip~pypi_39_keras//:pkg (096dcc8)
@@rules_python~~pip~pypi_39_absl_py//:pkg (096dcc8)
@@rules_python~~pip~pypi_39_tensorflow_estimator//:pkg (096dcc8)
@@rules_python~~pip~pypi_39_astunparse//:pkg (096dcc8)
@@rules_python~~pip~pypi_39_google_pasta//:pkg (096dcc8)
@@rules_python~~pip~pypi_39_libclang//:pkg (096dcc8)
@@rules_python~~pip~pypi_39_flatbuffers//:pkg (096dcc8)
@@rules_python~~pip~pypi_39_packaging//:pkg (096dcc8)
@@rules_python~~pip~pypi_39_tensorboard//:pkg (096dcc8)
@@rules_python~~pip~pypi_39_setuptools//:pkg (096dcc8)
@@rules_python~~pip~pypi_39_termcolor//:pkg (096dcc8)
@@rules_python~~pip~pypi_39_opt_einsum//:pkg (096dcc8)
@@rules_python~~pip~pypi_39_protobuf//:pkg (096dcc8)
@@rules_python~~pip~pypi_39_ml_dtypes//:pkg (096dcc8)
@@rules_python~~pip~pypi_39_typing_extensions//:pkg (096dcc8)
@@rules_python~~pip~pypi_39_grpcio//:pkg (096dcc8)
@@rules_python~~pip~pypi_39_h5py//:pkg (096dcc8)
@@rules_python~~pip~pypi_39_tensorboard_data_server//:pkg (096dcc8)
@@rules_python~~pip~pypi_39_requests//:pkg (096dcc8)
@@rules_python~~pip~pypi_39_google_auth//:pkg (096dcc8)
@@rules_python~~pip~pypi_39_werkzeug//:pkg (096dcc8)
@@rules_python~~pip~pypi_39_markdown//:pkg (096dcc8)
@@rules_python~~pip~pypi_39_wheel//:pkg (096dcc8)
@@rules_python~~pip~pypi_39_google_auth_oauthlib//:pkg (096dcc8)
@@rules_python~~pip~pypi_39_urllib3//:pkg (096dcc8)
@@rules_python~~pip~pypi_39_certifi//:pkg (096dcc8)
@@rules_python~~pip~pypi_39_charset_normalizer//:pkg (096dcc8)
@@rules_python~~pip~pypi_39_rsa//:pkg (096dcc8)
@@rules_python~~pip~pypi_39_idna//:pkg (096dcc8)
@@rules_python~~pip~pypi_39_requests_oauthlib//:pkg (096dcc8)
@@rules_python~~pip~pypi_39_cachetools//:pkg (096dcc8)
@@rules_python~~pip~pypi_39_pyasn1_modules//:pkg (096dcc8)
@@rules_python~~pip~pypi_39_importlib_metadata//:pkg (096dcc8)
@@rules_python~~pip~pypi_39_markupsafe//:pkg (096dcc8)
@@rules_python~~pip~pypi_39_oauthlib//:pkg (096dcc8)
@@rules_python~~pip~pypi_39_pyasn1//:pkg (096dcc8)
@@rules_python~~pip~pypi_39_zipp//:pkg (096dcc8)
INFO: Elapsed time: 1.844s, Critical Path: 0.00s
INFO: 0 processes.
INFO: Build completed successfully, 0 total actions |
Yup, I think you've found a bug. The issue is in how we generate the
This would workaround it. The basic flow is currently:
I'll rubber duck a little here. The way we could fix it is as follows: move the overrides based on the However, the drawback is that the An alternative fix would have involved changing how we are parsing the METADATA The alternative means that users who rely on the current behaviour will get the End of rubber ducking. I think my plan to fix this would be:
Thanks for reporting this bug! |
I really appreciate your detailed response regarding the bug. Although I may not understand all the technical details, the plan sounds good to me. I am willing to assist with testing or anything else you might need from me. Currently, I am no longer facing any blockers and I am looking forward to seeing significant improvements in build times with this fix. Thanks once again for your prompt responses. |
It seems that there was a single-line bug that did not allow us to handle arch-specific deps and since the percentage of such wheels is extremely low, it went under the radar for quite some time. I am going to not implement any explicit passing of the default python version to `whl_library` as it is a much bigger change. Just doing this could be sufficient for the time being. Fixes bazelbuild#1996
I was wrong about one thing - that the change would have to be invasive. There was a one line issue that affected |
It seems that there was a single-line bug that did not allow us to handle arch-specific deps and since the percentage of such wheels is extremely low, it went under the radar for quite some time. I am going to not implement any explicit passing of the default python version to `whl_library` as it is a much bigger change. Just doing this could be sufficient for the time being. Fixes #1996
🐞 bug report
I have a Bazel Python project that depends on TensorFlow. I recently started using the newly introduced
experimental_index_url
to cache the TensorFlow dependency and hopefully save time during CI when building the package. However, I noticed that with the recently introduced versions of rules_python, this package does not seem to be imported or included correctly in the build contexts, resulting in ModuleNotFound errors. It would be great to identify this issue and get it fixed.Affected Rule
py_binary or any rules_python rule, I guess.
Is this a regression?
Yes, I believe this is a regression. When the
experimental_index_url
is not set, the TensorFlow package appears to be imported correctly in the build context, and the target runs fine. I recall that an earlier version of rules_python withexperimental_index_url
did not have this issue. Therefore, it seems that one of the recent changes introduced is causing this problem.Description
I am experiencing issues importing the tensorflow package on MacOSX when using the experimental_index_url feature.
🔬 Minimal Reproduction
Run the dataset target. You should see the target failing with
ModuleNotFoundError: No module named 'tensorflow'
.Now, remove the experimental_index_url option in MODULE.bazel and run the above target again. It should not produce the error.
🔥 Exception or Error
🌍 Your Environment
Operating System:
Output of
bazel version
:Rules_python version:
Anything else relevant?
The text was updated successfully, but these errors were encountered: