bazel-examples icon indicating copy to clipboard operation
bazel-examples copied to clipboard

[Bug]: oci_python_image example does not copy correct prebuilt binaries

Open chulkilee opened this issue 1 year ago • 2 comments

What happened?

See https://github.com/aspect-build/bazel-examples/compare/main...chulkilee:bazel-examples:oci-py-target?expand=1

This is to show how the current oci_python_image example does not work when building on macos.

cd oci_python_image
bazel run //hello_world:tarball

docker run --rm gcr.io/oci_python_hello_world:latest
Traceback (most recent call last):
  File "/hello_world/hello_world.runfiles/_main/hello_world/__main__.py", line 1, in <module>
    from hello_world.app import Cow
  File "/hello_world/hello_world.runfiles/_main/hello_world/app.py", line 2, in <module>
    from pydantic import BaseModel
  File "/hello_world/hello_world.runfiles/.hello_world.venv/lib/python3.9/site-packages/pydantic/__init__.py", line 404, in __getattr__
    module = import_module(module_name, package=package)
  File "/hello_world/hello_world.runfiles/rules_python~~python~python_3_9_aarch64-unknown-linux-gnu/lib/python3.9/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "/hello_world/hello_world.runfiles/.hello_world.venv/lib/python3.9/site-packages/pydantic/main.py", line 27, in <module>
    import pydantic_core
  File "/hello_world/hello_world.runfiles/.hello_world.venv/lib/python3.9/site-packages/pydantic_core/__init__.py", line 6, in <module>
    from ._pydantic_core import (
ModuleNotFoundError: No module named 'pydantic_core._pydantic_core'

This is because pydantic_core's prebuilt is copied from host (macos), not for target. See the following output having darwin, not linux.

docker run --rm gcr.io/oci_python_hello_world:latest ls /hello_world/hello_world.runfiles/rules_python~~pip~pip_39_pydantic_core/site-packages/pydantic_core/

Output:

__init__.py
_pydantic_core.cpython-39-darwin.so
_pydantic_core.pyi
core_schema.py
py.typed

Interestingly, it actually did use the right python

docker run --rm gcr.io/oci_python_hello_world:latest ls /hello_world/hello_world.runfiles

Output:

_main
aspect_rules_py~~py_tools~rules_py_tools.linux_arm64
bazel_tools
rules_python~~pip~pip_39_annotated_types
rules_python~~pip~pip_39_cowsay
rules_python~~pip~pip_39_pydantic
rules_python~~pip~pip_39_pydantic_core
rules_python~~pip~pip_39_typing_extensions
rules_python~~python~python_3_9_aarch64-unknown-linux-gnu

See aarch64-unknown-linux-gnu there.

Version

Development (host) and target OS/architectures:

Output of bazel --version: 7.3.0

Version of the Aspect rules, or other relevant rules from your WORKSPACE or MODULE.bazel file: did not change from oci_python_image

Language(s) and/or frameworks involved: python

How to reproduce

See https://github.com/aspect-build/bazel-examples/compare/main...chulkilee:bazel-examples:oci-py-target?expand=1

Any other information?

It doesn't fail the test since apparently tests are running on linux machine.

chulkilee avatar Sep 05 '24 02:09 chulkilee

+1 This is exactly what I found as well! :)

antspy avatar Oct 22 '24 06:10 antspy

+1 I am having the same issue

clarenceh avatar Nov 06 '24 03:11 clarenceh

Repro'd it myself in almost all the same circumstances

bazel 8.1.1

csubj avatar Apr 26 '25 05:04 csubj