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, architecture arm64
Describe the bug
UvConfigaccepts acompile_bytecodeparameter that defaults toTrueand stores it on theinstance, but
to_uv_args()never emits a corresponding flag. The value is written and neverread, 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:Every other field on the class has a branch in
to_uv_args().compile_bytecodeis the onlyone that does not.
DESIGN.mdlists the option as active:Steps to reproduce
Build any function with
Metadata: BuildMethod: python-uv:Count the compiled files in the artifact:
Observed result
0. No bytecode is produced, despitecompile_bytecodedefaulting toTrue.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:
Expected result
Either
to_uv_args()emits--compile-bytecodewhen the flag is true (and--no-compile-bytecodewhen false), or the parameter and the
DESIGN.mdentry are removed so the API does not advertisean 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/taskis read-only at runtime, so a Lambdafunction that ships no
.pycrecompiles its entire dependency tree on every cold start and cannever cache the result — but it is a behaviour change and larger artifacts, so it may warrant
defaulting to
Falseuntil 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
python3.14, architecturearm64