Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion aws_lambda_builders/workflows/python_uv/packager.py
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,10 @@ def _lock_export_options(lock_path: str) -> List[str]:
args.extend([flag, options[option]])
for package, cutoff in options.get("exclude-newer-package", {}).items():
value = cutoff
if isinstance(cutoff, dict):
if cutoff is False:
# UV only accepts the lowercase TOML spelling for an opt-out.
value = "false"
elif isinstance(cutoff, dict):
value = cutoff["span"] if "span" in cutoff else cutoff["timestamp"]
args.extend(["--exclude-newer-package", f"{package}={value}"])
return args
Expand Down
27 changes: 27 additions & 0 deletions tests/integration/workflows/python_uv/test_python_uv.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ def test_workflow_uses_pyproject_toml_file(self):
("30 days", None),
("2024-01-01", "2023-01-01"),
("2024-01-01", "30 days"),
("2024-01-01", "false"),
)
for changed in (False, True)
]
Expand Down Expand Up @@ -269,6 +270,32 @@ def build():

self.assertEqual(lock_path.read_bytes(), lock_contents)

@skipIf(which("uv") is None, "uv not available")
def test_workflow_honors_package_opt_out_from_cutoff(self):
with tempfile.TemporaryDirectory() as source_dir:
manifest_path = pathlib.Path(source_dir) / "pyproject.toml"
# six 1.17.0 was released in December 2024, well after the global cutoff.
manifest_path.write_text(
'[project]\nname = "opt-out-demo"\nversion = "1.0.0"\nrequires-python = ">=3.13"\n'
'dependencies = ["six"]\n'
'\n[tool.uv]\nexclude-newer = "2020-01-01"\nexclude-newer-package = { six = false }\n',
encoding="utf-8",
)
subprocess.run(
[shutil.which("uv"), "lock", "--python", "3.13"], cwd=source_dir, check=True, capture_output=True
)

LambdaBuilder(language="python", dependency_manager="uv", application_framework=None).build(
source_dir,
self.artifacts_dir,
self.scratch_dir,
str(manifest_path),
runtime="python3.13",
experimental_flags=self.experimental_flags,
)

self.assertIn("six-1.17.0.dist-info", os.listdir(self.artifacts_dir))

@skipIf(which("uv") is None, "uv not available")
def test_workflow_with_dependencies_dir(self):
builder = LambdaBuilder(
Expand Down
11 changes: 11 additions & 0 deletions tests/unit/workflows/python_uv/test_packager.py
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,17 @@ def test_lock_export_prefers_package_span_over_placeholder(self, mock_file):
["--exclude-newer-package", "six=P30D", "--exclude-newer-package", "idna=2022-01-02T00:00:00Z"],
)

@patch(
"builtins.open",
new_callable=mock_open,
read_data=b'[options.exclude-newer-package]\nsix=false\nidna="2022-01-02T00:00:00Z"\n',
)
def test_lock_export_replays_package_opt_out_as_lowercase_false(self, mock_file):
self.assertEqual(
self.builder._lock_export_options("uv.lock"),
["--exclude-newer-package", "six=false", "--exclude-newer-package", "idna=2022-01-02T00:00:00Z"],
)

def test_build_from_requirements(self):
requirements_path = os.path.join("function", "requirements.txt")
config = UvConfig()
Expand Down
Loading