aspect-build / aspect-build/rules_py

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

Open
#1,412 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Starlark
Stars
145
Forks
97
Avg merge
1d 1h
Merged PRs (30d)
71

Description

### 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`:

```starlark
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`:

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

Generate `uv.lock`, then run:

```shell
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

Contributor guide

Open the contributing guide

Research direction

Start with py/tools/unpack/unpack.py and reproduce the issue using the provided pyside6-essentials dependency and Bazel command with pyc precompilation enabled. Trace how compileall diagnostics and its aggregate result are handled. Done means the wheel still installs and nonfatal compilation failures no longer appear as error-looking output during a successful build.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
build-system
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
68/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.