ali5h / rules_pip

pip package rules for bazel that are fast (incremental fetch), support different python versions and work with all kinds of packages (i.e. packages with namespaces)
MIT License
60 stars 24 forks source link

google namespace import failing #10

Closed jonbuffington closed 4 years ago

jonbuffington commented 4 years ago

I am able to recreate an issue that we are seeing in our builds by running rules_pip/examples/tests:

$ bazel test //tests:all
Starting local Bazel server and connecting to it...
INFO: Analyzed target //tests:test_import (64 packages loaded, 4492 targets configured).
INFO: Found 1 test target...
FAIL: //tests:test_import (see /private/var/tmp/_bazel_jcb/13f30459fa9eb9eb617e119869e3a3af/execroot/__main__/bazel-out/darwin-fastbuild/testlogs/tests/test_import/test.log)
INFO: From Testing //tests:test_import:
==================== Test output for //tests:test_import:
============================= test session starts ==============================
platform darwin -- Python 3.7.6, pytest-5.3.2, py-1.8.0, pluggy-0.13.1
rootdir: /private/var/tmp/_bazel_jcb/13f30459fa9eb9eb617e119869e3a3af/sandbox/darwin-sandbox/1/execroot/__main__/bazel-out/darwin-fastbuild/bin/tests/test_import.runfiles
collected 2 items

tests/test_import.py F.                                                  [100%]

=================================== FAILURES ===================================
_________________________________ test_import __________________________________

    def test_import():
        # just try to import some packages that use namespace
>       import google.cloud.language
E       ModuleNotFoundError: No module named 'google.cloud'

tests/test_import.py:3: ModuleNotFoundError
========================= 1 failed, 1 passed in 2.29s ==========================
================================================================================
Target //tests:test_import up-to-date:
  bazel-bin/tests/test_import
INFO: Elapsed time: 133.565s, Critical Path: 5.24s
INFO: 2 processes: 2 darwin-sandbox.
INFO: Build completed, 1 test FAILED, 6 total actions
//tests:test_import                                                      FAILED in 3.2s
  /private/var/tmp/_bazel_jcb/13f30459fa9eb9eb617e119869e3a3af/execroot/__main__/bazel-out/darwin-fastbuild/testlogs/tests/test_import/test.log

INFO: Build completed, 1 test FAILED, 6 total actions

The output of bazel version:

Build label: 2.0.0
Build target: bazel-out/darwin-opt/bin/src/main/java/com/google/devtools/build/lib/bazel/BazelServer_deploy.jar
Build time: Thu Dec 19 12:33:30 2019 (1576758810)
Build timestamp: 1576758810
Build timestamp as int: 1576758810

Any ideas?

ali5h commented 4 years ago

running the test on master?

jonbuffington commented 4 years ago

running the test on master?

Yes.

ali5h commented 4 years ago

more info about python and your system would help, try using wheels only by changing pip_install in the WORKSPACE to pip_install(["--only-binary", ":all"]). I updated examples to have this argument

jonbuffington commented 4 years ago

I am testing using MacOS 10.15.2 with brew installed python 3 (3.7.6).

Are you suggesting _piptool_install_tests_3() -> _piptool_install_tests_3(["--only-binary", ":all"])? If so, the test still fails after applying that change.

BTW, thanks for looking into this with me!

jonbuffington commented 4 years ago

I pushed to our CI server (linux Python 3.7.4) and this issue appears to be a macOS homebrew-installed Python 3.7.6 issue.

jonbuffington commented 4 years ago

If I install miniconda3 and use its Python 3.7.4 installation, the tests pass. Sorry for the noise.

If someone runs into a similar issue, the root cause was brew'ssitecustomize.py that was modified during an upgrade to make existing virtual env's compatible with prior releases. To fix the issue:

  1. brew uninstall python
  2. (assuming a default brew install) rm -r /usr/local/lib/python3.7
  3. brew install python