0

We have example_package, which is a Python module itself, so we can access example_package.my_module in code. We also defined example_package.math, since we have some simple math routines. We have some tests, which Bazel will effectively place in the same directory as these submodule files.

When we do this, any tests that Bazel generates in that directory which are Python binaries will have math shadowed on Mac, but not on Ubuntu.

Reproduction steps: https://github.com/EricCousineau-TRI/repro/blob/b08bc47/bug/mac_builtin_shadow/test.sh#L38

Why is this?

Bazel Background

In Bazel, we you decide to effectively place our unittests in the same package (BUILD.bazel file) as our modules. Bazel will generate wrapper Python scripts (for adjusting environment variables, unpacking archives, etc.), and place them according to the name of the test.

As an example, in //example_package, if I define py_library(name = "my_module", ...), and then define py_test(name = "my_module_test", srcs = ["test/my_module_test.py"], ...) in that same package, Bazel will generate a file ./bazel-bin/example_package/my_module_test (which is reflecting what is in .runfiles) - note that it is not under ./bazel-bin/example_package/test/my_module_test.

Eric Cousineau
  • 1,944
  • 14
  • 23

1 Answers1

0

The answer stems from these posts: https://bugs.python.org/issue32845 https://github.com/RobotLocomotion/drake/issues/8041

Quoting a summary from the GitHub post:

According to Eric V. Smith and Ned Deily on the Python bug tracker, this is expected behavior. math is a standard library, but not a builtin library per the standards. Ubuntu is adding extra modules to the builtins list, while Mac stays true to the "truth".

Ned posted an example showing math being builtin on Ubuntu, but a non-builtin on Mac. If you print sys.builtin_module_names, you'll see that Ubuntu does this for a few other libraries.

Eric Cousineau
  • 1,944
  • 14
  • 23