python_uv: `UvConfig.compile_bytecode` is never passed to uv, so the option has no effect

Open Beginner friendly
#925 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

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

Research direction

Start in aws_lambda_builders/workflows/python_uv/utils.py, reading UvConfig.init and to_uv_args(), then review the compile_bytecode entry in DESIGN.md and the related context in #839 and #924. Reproduce with sam build MyFunction --beta-features and verify that the configured bytecode behavior is reflected in the build arguments, while accounting for the packaging limitation described in #924.

Written by the indexing model from the issue text.

Description

Describe the bug

UvConfig accepts a compile_bytecode parameter that defaults to True and stores it on the
instance, but to_uv_args() never emits a corresponding flag. The value is written and never
read, so the option silently does nothing and the documented default of "compile .pyc files"
is not what happens.

aws_lambda_builders/workflows/python_uv/utils.py:

class UvConfig:
    def __init__(
        self,
        ...
        compile_bytecode: bool = True,   # line 107
        ...
    ):
        ...
        self.compile_bytecode = compile_bytecode   # line 117

    def to_uv_args(self) -> List[str]:   # line 121
        args = []
        if self.index_url: ...
        for extra_url in self.extra_index_urls: ...
        if self.cache_dir: ...
        if self.no_cache: ...
        if self.prerelease != "disallow": ...
        if self.resolution != "highest": ...
        if self.exclude_newer: ...
        if self.generate_hashes: ...
        return args                       # line 149 — no compile_bytecode branch

Every other field on the class has a branch in to_uv_args(). compile_bytecode is the only
one that does not.

DESIGN.md lists the option as active:

"compile_bytecode": True,                # Compile .pyc files
Steps to reproduce
  1. Build any function with Metadata: BuildMethod: python-uv:

    sam build MyFunction --beta-features
    
  2. Count the compiled files in the artifact:

    find .aws-sam/build/MyFunction -name '*.pyc' | wc -l
    
Observed result

0. No bytecode is produced, despite compile_bytecode defaulting to True.

For comparison, setting the environment variable that uv reads directly does produce bytecode,
which confirms uv itself is willing and that only the flag plumbing is missing:

UV_COMPILE_BYTECODE=1 sam build MyFunction --beta-features
find .aws-sam/build/MyFunction -name '*.pyc' | wc -l
→ 718
Expected result

Either to_uv_args() emits --compile-bytecode when the flag is true (and --no-compile-bytecode
when false), or the parameter and the DESIGN.md entry are removed so the API does not advertise
an option it does not implement.

Note on the default

If the field is wired up as written, the default flips bytecode compilation on for every
python-uv build. That is probably desirable — /var/task is read-only at runtime, so a Lambda
function that ships no .pyc recompiles its entire dependency tree on every cold start and can
never cache the result — but it is a behaviour change and larger artifacts, so it may warrant
defaulting to False until it is opt-in via configuration (see #839).

There is a second problem that makes the fix incomplete on its own: bytecode compiled during the
build does not survive SAM CLI's packaging step, because the ZIP is written with no timestamps.
Filed separately as #924.

Versions
  • aws-lambda-builders 1.67.0
  • SAM CLI 1.166.2
  • Host Python 3.14.3, target runtime python3.14, architecture arm64
Dominant language
Python
Stars
381
Forks
162
Avg merge
1d 1h
Merged PRs (30d)
2

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from aws/aws-lambda-builders

All issues in aws/aws-lambda-builders

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.