Skip to content

WhlInstall prints SyntaxError for non-Python .py template during pyc precompilation #1412

Description

@TrapsterDK

What happened?

With wheel bytecode precompilation enabled, WhlInstall passes the entire installed site-packages tree to compileall. A wheel can legitimately contain non-Python template files whose names end in .py. compileall tries to parse these files and prints a misleading SyntaxError, even though the Bazel action and build succeed.

A real example is pyside6-essentials==6.11.1, which contains this Jinja template:

PySide6/scripts/deploy_lib/android/recipes/PySide6/__init__.tmpl.py

It contains {% for module in qt_modules %}, so it is not valid Python source.

There is no observed runtime impact: the template remains installed and only its .pyc file is absent. The concern is the error-looking diagnostic in otherwise successful builds.

Minimal reproduction

MODULE.bazel:

module(name = "repro")

bazel_dep(name = "aspect_rules_py", version = "2.0.0-alpha.5")

python_interpreters = use_extension(
    "@aspect_rules_py//py:extensions.bzl",
    "python_interpreters",
)
python_interpreters.toolchain(python_version = "3.13")
use_repo(python_interpreters, "python_interpreters")
register_toolchains("@python_interpreters//:all")

uv_bin = use_extension("@aspect_rules_py//uv:extensions.bzl", "uv_bin")
uv_bin.toolchain(version = "0.11.6")
use_repo(uv_bin, "uv")

uv = use_extension("@aspect_rules_py//uv:extensions.bzl", "uv")
uv.declare_hub(hub_name = "pip")
uv.project(
    name = "repro",
    hub_name = "pip",
    lock = "//:uv.lock",
    pyproject = "//:pyproject.toml",
)
use_repo(uv, "pip")

register_toolchains("@uv//:all")

pyproject.toml:

[project]
name = "repro"
version = "0"
requires-python = ">=3.13,<3.14"
dependencies = ["pyside6-essentials==6.11.1"]

Generate uv.lock, then run:

bazel build \
  --@aspect_rules_py//py:python_version=3.13 \
  --@aspect_rules_py//uv/private/pyc:precompile=True \
  --@pip//dep_group=repro \
  @pip//pyside6_essentials

Actual output

INFO: From WhlInstall external/aspect_rules_py++uv+whl_install__repro__pyside6_essentials__6_11_1/actual_install.install:
*** Error compiling '.../site-packages/PySide6/scripts/deploy_lib/android/recipes/PySide6/__init__.tmpl.py'...
  File ".../site-packages/PySide6/scripts/deploy_lib/android/recipes/PySide6/__init__.tmpl.py", line 39
    {% for module in qt_modules %}  # noqa: E999
     ^
SyntaxError: invalid syntax

INFO: Build completed successfully

Expected behavior

Nonfatal per-file bytecode compilation failures should not produce error-looking diagnostics during a successful wheel installation, or there should be a way to suppress them.

The current py/tools/unpack/unpack.py implementation deliberately retains compileall diagnostics while ignoring its aggregate false result. This may conflict with the intent of #1000, which suppressed nonfatal pyc compilation warnings.

Environment

  • aspect_rules_py: 2.0.0-alpha.5 (d802a0bc447cb4643a3924a80dd092a412816362)
  • Bazel: 9.1.1
  • Python: 3.13
  • uv: 0.11.6
  • Host: Linux x86_64

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions