From 1ad3b1fcac68adb7da6efe025d72c0161d1196b4 Mon Sep 17 00:00:00 2001 From: Harold Sun Date: Thu, 19 Nov 2026 15:30:35 +0000 Subject: [PATCH] fix(python-uv): don't crash when bytecode is on and there is no manifest With uv_compile_bytecode (or a truthy UV_COMPILE_BYTECODE) and no pyproject.toml or requirements.txt, _uv_config_from_options called _project_name(None) and raised TypeError. Only uv_prune needs the project name, so read it only then. The build now continues without dependencies, as before #973. --- aws_lambda_builders/workflows/python_uv/workflow.py | 5 +++-- tests/unit/workflows/python_uv/test_workflow.py | 13 +++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/aws_lambda_builders/workflows/python_uv/workflow.py b/aws_lambda_builders/workflows/python_uv/workflow.py index b3e449503..6181febae 100644 --- a/aws_lambda_builders/workflows/python_uv/workflow.py +++ b/aws_lambda_builders/workflows/python_uv/workflow.py @@ -178,9 +178,10 @@ def _uv_config_from_options(self, manifest_path): f"but this build uses {os.path.basename(manifest_path) if manifest_path else 'no manifest'}" ) - project_name = self._project_name(manifest_path) + # Only uv_prune needs the project name, and it's only set here with a pyproject.toml manifest + project_name = self._project_name(manifest_path) if values.get("uv_prune") else None if project_name and any( - normalize_package_name(name) == normalize_package_name(project_name) for name in values.get("uv_prune", []) + normalize_package_name(name) == normalize_package_name(project_name) for name in values["uv_prune"] ): self._fail(f"Build option uv_prune cannot name the project being built ({project_name})") diff --git a/tests/unit/workflows/python_uv/test_workflow.py b/tests/unit/workflows/python_uv/test_workflow.py index f770f352d..3e672155b 100644 --- a/tests/unit/workflows/python_uv/test_workflow.py +++ b/tests/unit/workflows/python_uv/test_workflow.py @@ -257,6 +257,19 @@ def test_compile_bytecode_on_requirements_build_is_allowed(self): config = self._workflow({"uv_compile_bytecode": True}, manifest=requirements).actions[0].config self.assertTrue(config.compile_bytecode) + def test_compile_bytecode_without_manifest_builds_without_dependencies(self): + os.remove(self.pyproject) + workflow = self._workflow({"uv_compile_bytecode": True}, manifest=os.path.join(self.source_dir, "missing.txt")) + self.assertEqual(len(workflow.actions), 1) + self.assertIsInstance(workflow.actions[0], CopySourceAction) + + def test_truthy_env_without_manifest_builds_without_dependencies(self): + os.environ["UV_COMPILE_BYTECODE"] = "1" + os.remove(self.pyproject) + workflow = self._workflow({"build_logical_id": "Fn"}, manifest=os.path.join(self.source_dir, "missing.txt")) + self.assertEqual(len(workflow.actions), 1) + self.assertIsInstance(workflow.actions[0], CopySourceAction) + def test_export_option_with_compile_bytecode_on_requirements_build_fails(self): requirements = os.path.join(self.source_dir, "requirements.txt") open(requirements, "w").close()