python_uv: `UvConfig.compile_bytecode` is never passed to uv, so the option has no effect
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
-
Build any function with
Metadata: BuildMethod: python-uv:sam build MyFunction --beta-features -
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, architecturearm64
- Dominant language
- Python
- Stars
- 381
- Forks
- 162
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 2
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from aws/aws-lambda-builders
-
Difficulty 4/5 3-5 days Newbie friendliness 64/100
aws/aws-lambda-builders#924 · 1 comment ·
-
Bug: PythonUvBuilder fails to build app with dependencies on editable installs in the workspace Openstage/needs-triage
Difficulty 3/5 1-2 days Newbie friendliness 25/100
aws/aws-lambda-builders#892 ·
-
stage/needs-triage type/feature
Difficulty 4/5 3-5 days Newbie friendliness 38/100
aws/aws-lambda-builders#839 · 2 comments · 1 reaction ·
-
area/build contributors/good-first-issue contributors/welcome type/feature
Difficulty 4/5 3-5 days Newbie friendliness 38/100
aws/aws-lambda-builders#831 · 3 comments ·
-
blocked/more-info-needed type/feature
Difficulty 5/5 Over a week Newbie friendliness 25/100
aws/aws-lambda-builders#713 · 2 comments ·
All issues in aws/aws-lambda-builders
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
syfoud/Simulated_Scepter#172 ·
-
A cancelled tests run makes the coverage comment workflow fail and reports it as a red check on main Openarea: ci bug perceived difficulty: 3
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Nitjsefnie-Harness-Commons/daedalus#921 · 1 comment ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
EleutherAI/lm-evaluation-harness#4207 ·
-
Difficulty 1/5 Under an hour Newbie friendliness 92/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
ClickHouse/clickhouse-connect#1057 ·