Skip to content

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

@chulkilee

Description

@chulkilee

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinghelp wantedAspect isn't prioritizing this, but the community couldneed: investigationInvestigation required to proceed further

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions