diff --git a/examples/build-package/README.md b/examples/build-package/README.md index 5509290c..ca7d0b1a 100644 --- a/examples/build-package/README.md +++ b/examples/build-package/README.md @@ -5,6 +5,7 @@ Configuration in this directory creates deployment packages in a variety of comb This example demonstrates various packaging scenarios including: - Python packages with pip requirements - Poetry-based Python packages +- UV-based Python packages - Node.js packages with npm - Docker-based builds - Quiet packaging - suppressing Poetry/pip/npm output during builds using `quiet_archive_local_exec = true` @@ -46,12 +47,15 @@ Note that this example may create resources which cost money. Run `terraform des | [lambda\_layer](#module\_lambda\_layer) | ../../ | n/a | | [lambda\_layer\_pip\_requirements](#module\_lambda\_layer\_pip\_requirements) | ../.. | n/a | | [lambda\_layer\_poetry](#module\_lambda\_layer\_poetry) | ../../ | n/a | +| [lambda\_layer\_uv](#module\_lambda\_layer\_uv) | ../../ | n/a | | [npm\_package\_with\_commands\_and\_patterns](#module\_npm\_package\_with\_commands\_and\_patterns) | ../../ | n/a | | [package\_dir](#module\_package\_dir) | ../../ | n/a | | [package\_dir\_pip\_dir](#module\_package\_dir\_pip\_dir) | ../../ | n/a | | [package\_dir\_poetry](#module\_package\_dir\_poetry) | ../../ | n/a | | [package\_dir\_poetry\_no\_docker](#module\_package\_dir\_poetry\_no\_docker) | ../../ | n/a | | [package\_dir\_poetry\_quiet](#module\_package\_dir\_poetry\_quiet) | ../../ | n/a | +| [package\_dir\_uv](#module\_package\_dir\_uv) | ../../ | n/a | +| [package\_dir\_uv\_no\_docker](#module\_package\_dir\_uv\_no\_docker) | ../../ | n/a | | [package\_dir\_with\_npm\_install](#module\_package\_dir\_with\_npm\_install) | ../../ | n/a | | [package\_dir\_with\_npm\_install\_lock\_file](#module\_package\_dir\_with\_npm\_install\_lock\_file) | ../../ | n/a | | [package\_dir\_without\_npm\_install](#module\_package\_dir\_without\_npm\_install) | ../../ | n/a | diff --git a/examples/build-package/main.tf b/examples/build-package/main.tf index ec843b68..8de4b005 100644 --- a/examples/build-package/main.tf +++ b/examples/build-package/main.tf @@ -137,6 +137,67 @@ module "package_dir_poetry_quiet" { quiet_archive_local_exec = true # Suppress Poetry/pip output during packaging } +# Create zip-archive of a single directory where "uv export" & "pip install" will be executed (using docker) +module "package_dir_uv" { + source = "../../" + + create_function = false + + build_in_docker = true + runtime = "python3.12" + docker_image = "build-python-uv" + docker_file = "${path.module}/../fixtures/python-app-uv/docker/Dockerfile" + + source_path = [ + { + path = "${path.module}/../fixtures/python-app-uv" + uv_install = true + } + ] + artifacts_dir = "${path.root}/builds/package_dir_uv/" +} + +# Create zip-archive of a single directory where "uv export" & "pip install" will be executed (not using docker) +module "package_dir_uv_no_docker" { + source = "../../" + + create_function = false + + runtime = "python3.12" + + source_path = [ + { + path = "${path.module}/../fixtures/python-app-uv" + uv_install = true + } + ] + artifacts_dir = "${path.root}/builds/package_dir_uv_no_docker/" +} + +# Create a Lambda Layer using uv for dependency management (using docker) +module "lambda_layer_uv" { + source = "../../" + + create_layer = true + layer_name = "${random_pet.this.id}-layer-uv" + compatible_runtimes = ["python3.12"] + runtime = "python3.12" + + build_in_docker = true + docker_image = "build-python-uv" + docker_file = "${path.module}/../fixtures/python-app-uv/docker/Dockerfile" + + source_path = [ + { + path = "${path.module}/../fixtures/python-app-uv" + uv_install = true + prefix_in_zip = "python" + } + ] + hash_extra = "uv-extra-hash-to-prevent-conflicts-with-module.package_dir" + artifacts_dir = "${path.root}/builds/lambda_layer_uv/" +} + # Create zip-archive of a single directory without running "pip install" (which is default for python runtime) module "package_dir_without_pip_install" { source = "../../" diff --git a/examples/fixtures/python-app-uv/docker/Dockerfile b/examples/fixtures/python-app-uv/docker/Dockerfile new file mode 100644 index 00000000..3d3a94cd --- /dev/null +++ b/examples/fixtures/python-app-uv/docker/Dockerfile @@ -0,0 +1,7 @@ +FROM public.ecr.aws/sam/build-python3.12 + +LABEL description="AWS Lambda build container with uv" + +RUN pip install uv==0.9.21 + +WORKDIR /var/task diff --git a/examples/fixtures/python-app-uv/index.py b/examples/fixtures/python-app-uv/index.py new file mode 100644 index 00000000..9dd6364d --- /dev/null +++ b/examples/fixtures/python-app-uv/index.py @@ -0,0 +1,5 @@ +def lambda_handler(event, context): + import requests + + print("Hello from uv-managed Lambda!") + return {"statusCode": 200} diff --git a/examples/fixtures/python-app-uv/pyproject.toml b/examples/fixtures/python-app-uv/pyproject.toml new file mode 100644 index 00000000..1be3d4ee --- /dev/null +++ b/examples/fixtures/python-app-uv/pyproject.toml @@ -0,0 +1,14 @@ +[project] +name = "uv-lambda" +version = "0.1.0" +requires-python = ">=3.12" +dependencies = [ + "requests==2.31.0", +] + +[tool.uv] +# This marker is for our Terraform parser to detect UV + +[build-system] +requires = ["hatchling"] +build-backend = "hatchling.build" diff --git a/examples/fixtures/python-app-uv/uv.lock b/examples/fixtures/python-app-uv/uv.lock new file mode 100644 index 00000000..a689331b --- /dev/null +++ b/examples/fixtures/python-app-uv/uv.lock @@ -0,0 +1,97 @@ +version = 1 +revision = 3 +requires-python = ">=3.12" + +[[package]] +name = "certifi" +version = "2026.1.4" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/e0/2d/a891ca51311197f6ad14a7ef42e2399f36cf2f9bd44752b3dc4eab60fdc5/certifi-2026.1.4.tar.gz", hash = "sha256:ac726dd470482006e014ad384921ed6438c457018f4b3d204aea4281258b2120", size = 154268, upload-time = "2026-01-04T02:42:41.825Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/e6/ad/3cc14f097111b4de0040c83a525973216457bbeeb63739ef1ed275c1c021/certifi-2026.1.4-py3-none-any.whl", hash = "sha256:9943707519e4add1115f44c2bc244f782c0249876bf51b6599fee1ffbedd685c", size = 152900, upload-time = "2026-01-04T02:42:40.15Z" }, +] + +[[package]] +name = "charset-normalizer" +version = "3.4.4" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/13/69/33ddede1939fdd074bce5434295f38fae7136463422fe4fd3e0e89b98062/charset_normalizer-3.4.4.tar.gz", hash = "sha256:94537985111c35f28720e43603b8e7b43a6ecfb2ce1d3058bbe955b73404e21a", size = 129418, upload-time = "2025-10-14T04:42:32.879Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/97/45/4b3a1239bbacd321068ea6e7ac28875b03ab8bc0aa0966452db17cd36714/charset_normalizer-3.4.4-cp313-cp313-macosx_10_13_universal2.whl", hash = "sha256:e1f185f86a6f3403aa2420e815904c67b2f9ebc443f045edd0de921108345794", size = 208091, upload-time = "2025-10-14T04:41:13.346Z" }, + { url = "https://files.pythonhosted.org/packages/7d/62/73a6d7450829655a35bb88a88fca7d736f9882a27eacdca2c6d505b57e2e/charset_normalizer-3.4.4-cp313-cp313-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:6b39f987ae8ccdf0d2642338faf2abb1862340facc796048b604ef14919e55ed", size = 147936, upload-time = "2025-10-14T04:41:14.461Z" }, + { url = "https://files.pythonhosted.org/packages/89/c5/adb8c8b3d6625bef6d88b251bbb0d95f8205831b987631ab0c8bb5d937c2/charset_normalizer-3.4.4-cp313-cp313-manylinux2014_armv7l.manylinux_2_17_armv7l.manylinux_2_31_armv7l.whl", hash = "sha256:3162d5d8ce1bb98dd51af660f2121c55d0fa541b46dff7bb9b9f86ea1d87de72", size = 144180, upload-time = "2025-10-14T04:41:15.588Z" }, + { url = "https://files.pythonhosted.org/packages/91/ed/9706e4070682d1cc219050b6048bfd293ccf67b3d4f5a4f39207453d4b99/charset_normalizer-3.4.4-cp313-cp313-manylinux2014_ppc64le.manylinux_2_17_ppc64le.manylinux_2_28_ppc64le.whl", hash = "sha256:81d5eb2a312700f4ecaa977a8235b634ce853200e828fbadf3a9c50bab278328", size = 161346, upload-time = "2025-10-14T04:41:16.738Z" }, + { url = "https://files.pythonhosted.org/packages/d5/0d/031f0d95e4972901a2f6f09ef055751805ff541511dc1252ba3ca1f80cf5/charset_normalizer-3.4.4-cp313-cp313-manylinux2014_s390x.manylinux_2_17_s390x.manylinux_2_28_s390x.whl", hash = "sha256:5bd2293095d766545ec1a8f612559f6b40abc0eb18bb2f5d1171872d34036ede", size = 158874, upload-time = "2025-10-14T04:41:17.923Z" }, + { url = "https://files.pythonhosted.org/packages/f5/83/6ab5883f57c9c801ce5e5677242328aa45592be8a00644310a008d04f922/charset_normalizer-3.4.4-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:a8a8b89589086a25749f471e6a900d3f662d1d3b6e2e59dcecf787b1cc3a1894", size = 153076, upload-time = "2025-10-14T04:41:19.106Z" }, + { url = "https://files.pythonhosted.org/packages/75/1e/5ff781ddf5260e387d6419959ee89ef13878229732732ee73cdae01800f2/charset_normalizer-3.4.4-cp313-cp313-manylinux_2_31_riscv64.manylinux_2_39_riscv64.whl", hash = "sha256:bc7637e2f80d8530ee4a78e878bce464f70087ce73cf7c1caf142416923b98f1", size = 150601, upload-time = "2025-10-14T04:41:20.245Z" }, + { url = "https://files.pythonhosted.org/packages/d7/57/71be810965493d3510a6ca79b90c19e48696fb1ff964da319334b12677f0/charset_normalizer-3.4.4-cp313-cp313-musllinux_1_2_aarch64.whl", hash = "sha256:f8bf04158c6b607d747e93949aa60618b61312fe647a6369f88ce2ff16043490", size = 150376, upload-time = "2025-10-14T04:41:21.398Z" }, + { url = "https://files.pythonhosted.org/packages/e5/d5/c3d057a78c181d007014feb7e9f2e65905a6c4ef182c0ddf0de2924edd65/charset_normalizer-3.4.4-cp313-cp313-musllinux_1_2_armv7l.whl", hash = "sha256:554af85e960429cf30784dd47447d5125aaa3b99a6f0683589dbd27e2f45da44", size = 144825, upload-time = "2025-10-14T04:41:22.583Z" }, + { url = "https://files.pythonhosted.org/packages/e6/8c/d0406294828d4976f275ffbe66f00266c4b3136b7506941d87c00cab5272/charset_normalizer-3.4.4-cp313-cp313-musllinux_1_2_ppc64le.whl", hash = "sha256:74018750915ee7ad843a774364e13a3db91682f26142baddf775342c3f5b1133", size = 162583, upload-time = "2025-10-14T04:41:23.754Z" }, + { url = "https://files.pythonhosted.org/packages/d7/24/e2aa1f18c8f15c4c0e932d9287b8609dd30ad56dbe41d926bd846e22fb8d/charset_normalizer-3.4.4-cp313-cp313-musllinux_1_2_riscv64.whl", hash = "sha256:c0463276121fdee9c49b98908b3a89c39be45d86d1dbaa22957e38f6321d4ce3", size = 150366, upload-time = "2025-10-14T04:41:25.27Z" }, + { url = "https://files.pythonhosted.org/packages/e4/5b/1e6160c7739aad1e2df054300cc618b06bf784a7a164b0f238360721ab86/charset_normalizer-3.4.4-cp313-cp313-musllinux_1_2_s390x.whl", hash = "sha256:362d61fd13843997c1c446760ef36f240cf81d3ebf74ac62652aebaf7838561e", size = 160300, upload-time = "2025-10-14T04:41:26.725Z" }, + { url = "https://files.pythonhosted.org/packages/7a/10/f882167cd207fbdd743e55534d5d9620e095089d176d55cb22d5322f2afd/charset_normalizer-3.4.4-cp313-cp313-musllinux_1_2_x86_64.whl", hash = "sha256:9a26f18905b8dd5d685d6d07b0cdf98a79f3c7a918906af7cc143ea2e164c8bc", size = 154465, upload-time = "2025-10-14T04:41:28.322Z" }, + { url = "https://files.pythonhosted.org/packages/89/66/c7a9e1b7429be72123441bfdbaf2bc13faab3f90b933f664db506dea5915/charset_normalizer-3.4.4-cp313-cp313-win32.whl", hash = "sha256:9b35f4c90079ff2e2edc5b26c0c77925e5d2d255c42c74fdb70fb49b172726ac", size = 99404, upload-time = "2025-10-14T04:41:29.95Z" }, + { url = "https://files.pythonhosted.org/packages/c4/26/b9924fa27db384bdcd97ab83b4f0a8058d96ad9626ead570674d5e737d90/charset_normalizer-3.4.4-cp313-cp313-win_amd64.whl", hash = "sha256:b435cba5f4f750aa6c0a0d92c541fb79f69a387c91e61f1795227e4ed9cece14", size = 107092, upload-time = "2025-10-14T04:41:31.188Z" }, + { url = "https://files.pythonhosted.org/packages/af/8f/3ed4bfa0c0c72a7ca17f0380cd9e4dd842b09f664e780c13cff1dcf2ef1b/charset_normalizer-3.4.4-cp313-cp313-win_arm64.whl", hash = "sha256:542d2cee80be6f80247095cc36c418f7bddd14f4a6de45af91dfad36d817bba2", size = 100408, upload-time = "2025-10-14T04:41:32.624Z" }, + { url = "https://files.pythonhosted.org/packages/2a/35/7051599bd493e62411d6ede36fd5af83a38f37c4767b92884df7301db25d/charset_normalizer-3.4.4-cp314-cp314-macosx_10_13_universal2.whl", hash = "sha256:da3326d9e65ef63a817ecbcc0df6e94463713b754fe293eaa03da99befb9a5bd", size = 207746, upload-time = "2025-10-14T04:41:33.773Z" }, + { url = "https://files.pythonhosted.org/packages/10/9a/97c8d48ef10d6cd4fcead2415523221624bf58bcf68a802721a6bc807c8f/charset_normalizer-3.4.4-cp314-cp314-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:8af65f14dc14a79b924524b1e7fffe304517b2bff5a58bf64f30b98bbc5079eb", size = 147889, upload-time = "2025-10-14T04:41:34.897Z" }, + { url = "https://files.pythonhosted.org/packages/10/bf/979224a919a1b606c82bd2c5fa49b5c6d5727aa47b4312bb27b1734f53cd/charset_normalizer-3.4.4-cp314-cp314-manylinux2014_armv7l.manylinux_2_17_armv7l.manylinux_2_31_armv7l.whl", hash = "sha256:74664978bb272435107de04e36db5a9735e78232b85b77d45cfb38f758efd33e", size = 143641, upload-time = "2025-10-14T04:41:36.116Z" }, + { url = "https://files.pythonhosted.org/packages/ba/33/0ad65587441fc730dc7bd90e9716b30b4702dc7b617e6ba4997dc8651495/charset_normalizer-3.4.4-cp314-cp314-manylinux2014_ppc64le.manylinux_2_17_ppc64le.manylinux_2_28_ppc64le.whl", hash = "sha256:752944c7ffbfdd10c074dc58ec2d5a8a4cd9493b314d367c14d24c17684ddd14", size = 160779, upload-time = "2025-10-14T04:41:37.229Z" }, + { url = "https://files.pythonhosted.org/packages/67/ed/331d6b249259ee71ddea93f6f2f0a56cfebd46938bde6fcc6f7b9a3d0e09/charset_normalizer-3.4.4-cp314-cp314-manylinux2014_s390x.manylinux_2_17_s390x.manylinux_2_28_s390x.whl", hash = "sha256:d1f13550535ad8cff21b8d757a3257963e951d96e20ec82ab44bc64aeb62a191", size = 159035, upload-time = "2025-10-14T04:41:38.368Z" }, + { url = "https://files.pythonhosted.org/packages/67/ff/f6b948ca32e4f2a4576aa129d8bed61f2e0543bf9f5f2b7fc3758ed005c9/charset_normalizer-3.4.4-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:ecaae4149d99b1c9e7b88bb03e3221956f68fd6d50be2ef061b2381b61d20838", size = 152542, upload-time = "2025-10-14T04:41:39.862Z" }, + { url = "https://files.pythonhosted.org/packages/16/85/276033dcbcc369eb176594de22728541a925b2632f9716428c851b149e83/charset_normalizer-3.4.4-cp314-cp314-manylinux_2_31_riscv64.manylinux_2_39_riscv64.whl", hash = "sha256:cb6254dc36b47a990e59e1068afacdcd02958bdcce30bb50cc1700a8b9d624a6", size = 149524, upload-time = "2025-10-14T04:41:41.319Z" }, + { url = "https://files.pythonhosted.org/packages/9e/f2/6a2a1f722b6aba37050e626530a46a68f74e63683947a8acff92569f979a/charset_normalizer-3.4.4-cp314-cp314-musllinux_1_2_aarch64.whl", hash = "sha256:c8ae8a0f02f57a6e61203a31428fa1d677cbe50c93622b4149d5c0f319c1d19e", size = 150395, upload-time = "2025-10-14T04:41:42.539Z" }, + { url = "https://files.pythonhosted.org/packages/60/bb/2186cb2f2bbaea6338cad15ce23a67f9b0672929744381e28b0592676824/charset_normalizer-3.4.4-cp314-cp314-musllinux_1_2_armv7l.whl", hash = "sha256:47cc91b2f4dd2833fddaedd2893006b0106129d4b94fdb6af1f4ce5a9965577c", size = 143680, upload-time = "2025-10-14T04:41:43.661Z" }, + { url = "https://files.pythonhosted.org/packages/7d/a5/bf6f13b772fbb2a90360eb620d52ed8f796f3c5caee8398c3b2eb7b1c60d/charset_normalizer-3.4.4-cp314-cp314-musllinux_1_2_ppc64le.whl", hash = "sha256:82004af6c302b5d3ab2cfc4cc5f29db16123b1a8417f2e25f9066f91d4411090", size = 162045, upload-time = "2025-10-14T04:41:44.821Z" }, + { url = "https://files.pythonhosted.org/packages/df/c5/d1be898bf0dc3ef9030c3825e5d3b83f2c528d207d246cbabe245966808d/charset_normalizer-3.4.4-cp314-cp314-musllinux_1_2_riscv64.whl", hash = "sha256:2b7d8f6c26245217bd2ad053761201e9f9680f8ce52f0fcd8d0755aeae5b2152", size = 149687, upload-time = "2025-10-14T04:41:46.442Z" }, + { url = "https://files.pythonhosted.org/packages/a5/42/90c1f7b9341eef50c8a1cb3f098ac43b0508413f33affd762855f67a410e/charset_normalizer-3.4.4-cp314-cp314-musllinux_1_2_s390x.whl", hash = "sha256:799a7a5e4fb2d5898c60b640fd4981d6a25f1c11790935a44ce38c54e985f828", size = 160014, upload-time = "2025-10-14T04:41:47.631Z" }, + { url = "https://files.pythonhosted.org/packages/76/be/4d3ee471e8145d12795ab655ece37baed0929462a86e72372fd25859047c/charset_normalizer-3.4.4-cp314-cp314-musllinux_1_2_x86_64.whl", hash = "sha256:99ae2cffebb06e6c22bdc25801d7b30f503cc87dbd283479e7b606f70aff57ec", size = 154044, upload-time = "2025-10-14T04:41:48.81Z" }, + { url = "https://files.pythonhosted.org/packages/b0/6f/8f7af07237c34a1defe7defc565a9bc1807762f672c0fde711a4b22bf9c0/charset_normalizer-3.4.4-cp314-cp314-win32.whl", hash = "sha256:f9d332f8c2a2fcbffe1378594431458ddbef721c1769d78e2cbc06280d8155f9", size = 99940, upload-time = "2025-10-14T04:41:49.946Z" }, + { url = "https://files.pythonhosted.org/packages/4b/51/8ade005e5ca5b0d80fb4aff72a3775b325bdc3d27408c8113811a7cbe640/charset_normalizer-3.4.4-cp314-cp314-win_amd64.whl", hash = "sha256:8a6562c3700cce886c5be75ade4a5db4214fda19fede41d9792d100288d8f94c", size = 107104, upload-time = "2025-10-14T04:41:51.051Z" }, + { url = "https://files.pythonhosted.org/packages/da/5f/6b8f83a55bb8278772c5ae54a577f3099025f9ade59d0136ac24a0df4bde/charset_normalizer-3.4.4-cp314-cp314-win_arm64.whl", hash = "sha256:de00632ca48df9daf77a2c65a484531649261ec9f25489917f09e455cb09ddb2", size = 100743, upload-time = "2025-10-14T04:41:52.122Z" }, + { url = "https://files.pythonhosted.org/packages/0a/4c/925909008ed5a988ccbb72dcc897407e5d6d3bd72410d69e051fc0c14647/charset_normalizer-3.4.4-py3-none-any.whl", hash = "sha256:7a32c560861a02ff789ad905a2fe94e3f840803362c84fecf1851cb4cf3dc37f", size = 53402, upload-time = "2025-10-14T04:42:31.76Z" }, +] + +[[package]] +name = "idna" +version = "3.11" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/6f/6d/0703ccc57f3a7233505399edb88de3cbd678da106337b9fcde432b65ed60/idna-3.11.tar.gz", hash = "sha256:795dafcc9c04ed0c1fb032c2aa73654d8e8c5023a7df64a53f39190ada629902", size = 194582, upload-time = "2025-10-12T14:55:20.501Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/0e/61/66938bbb5fc52dbdf84594873d5b51fb1f7c7794e9c0f5bd885f30bc507b/idna-3.11-py3-none-any.whl", hash = "sha256:771a87f49d9defaf64091e6e6fe9c18d4833f140bd19464795bc32d966ca37ea", size = 71008, upload-time = "2025-10-12T14:55:18.883Z" }, +] + +[[package]] +name = "requests" +version = "2.31.0" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "certifi" }, + { name = "charset-normalizer" }, + { name = "idna" }, + { name = "urllib3" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/9d/be/10918a2eac4ae9f02f6cfe6414b7a155ccd8f7f9d4380d62fd5b955065c3/requests-2.31.0.tar.gz", hash = "sha256:942c5a758f98d790eaed1a29cb6eefc7ffb0d1cf7af05c3d2791656dbd6ad1e1", size = 110794, upload-time = "2023-05-22T15:12:44.175Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/70/8e/0e2d847013cb52cd35b38c009bb167a1a26b2ce6cd6965bf26b47bc0bf44/requests-2.31.0-py3-none-any.whl", hash = "sha256:58cd2187c01e70e6e26505bca751777aa9f2ee0b7f4300988b709f44e013003f", size = 62574, upload-time = "2023-05-22T15:12:42.313Z" }, +] + +[[package]] +name = "urllib3" +version = "2.6.2" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/1e/24/a2a2ed9addd907787d7aa0355ba36a6cadf1768b934c652ea78acbd59dcd/urllib3-2.6.2.tar.gz", hash = "sha256:016f9c98bb7e98085cb2b4b17b87d2c702975664e4f060c6532e64d1c1a5e797", size = 432930, upload-time = "2025-12-11T15:56:40.252Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/6d/b9/4095b668ea3678bf6a0af005527f39de12fb026516fb3df17495a733b7f8/urllib3-2.6.2-py3-none-any.whl", hash = "sha256:ec21cddfe7724fc7cb4ba4bea7aa8e2ef36f607a4bab81aa6ce42a13dc3f03dd", size = 131182, upload-time = "2025-12-11T15:56:38.584Z" }, +] + +[[package]] +name = "uv-lambda" +version = "0.1.0" +source = { virtual = "." } +dependencies = [ + { name = "requests" }, +] + +[package.metadata] +requires-dist = [{ name = "requests", specifier = "==2.31.0" }] diff --git a/package.py b/package.py index 3261a282..c103e1d8 100644 --- a/package.py +++ b/package.py @@ -654,6 +654,8 @@ def get_build_system_from_pyproject_toml(pyproject_file): continue if bs and line.startswith("build-backend") and "poetry" in line: return "poetry" + if line.startswith("[tool.uv]"): + return "uv" class BuildPlanManager: @@ -711,6 +713,25 @@ def pip_requirements_step(path, prefix=None, required=False, tmp_dir=None): step("pip", runtime, requirements, prefix, tmp_dir) hash(requirements) + def uv_install_step( + path, uv_export_extra_args=[], prefix=None, required=False, tmp_dir=None + ): + uv_lock_file = path + if os.path.isdir(path): + uv_lock_file = os.path.join(path, "uv.lock") + + if not os.path.isfile(uv_lock_file): + if required: + raise RuntimeError("uv.lock not found: {}".format(uv_lock_file)) + else: + step("uv", runtime, path, uv_export_extra_args, prefix, tmp_dir) + hash(uv_lock_file) + + uv_project_path = os.path.dirname(uv_lock_file) + pyproject_file = os.path.join(uv_project_path, "pyproject.toml") + if os.path.isfile(pyproject_file): + hash(pyproject_file) + def poetry_install_step( path, poetry_export_extra_args=[], prefix=None, required=False, tmp_dir=None ): @@ -814,8 +835,11 @@ def commands_step(path, commands): ) runtime = query.runtime if runtime.startswith("python"): - pip_requirements_step(os.path.join(path, "requirements.txt")) - poetry_install_step(path) + if os.path.isfile(os.path.join(path, "uv.lock")): + uv_install_step(path) + else: + pip_requirements_step(os.path.join(path, "requirements.txt")) + poetry_install_step(path) elif runtime.startswith("nodejs"): npm_requirements_step(os.path.join(path, "package.json")) step("zip", path, None) @@ -832,6 +856,8 @@ def commands_step(path, commands): else: prefix = claim.get("prefix_in_zip") pip_requirements = claim.get("pip_requirements") + uv_install = claim.get("uv_install") + uv_export_extra_args = claim.get("uv_export_extra_args", []) poetry_install = claim.get("poetry_install") poetry_export_extra_args = claim.get("poetry_export_extra_args", []) npm_requirements = claim.get( @@ -855,6 +881,16 @@ def commands_step(path, commands): tmp_dir=claim.get("pip_tmp_dir"), ) + if uv_install and runtime.startswith("python"): + if path: + uv_install_step( + path, + prefix=prefix, + uv_export_extra_args=uv_export_extra_args, + required=True, + tmp_dir=claim.get("uv_tmp_dir"), + ) + if poetry_install and runtime.startswith("python"): if path: poetry_install_step( @@ -978,6 +1014,20 @@ def execute(self, build_plan, zip_stream, query): else: # XXX: timestamp=0 - what actually do with it? zs.write_dirs(rd, prefix=prefix, timestamp=0) + elif cmd == "uv": + (runtime, path, uv_export_extra_args, prefix, tmp_dir) = action[1:] + log.info("uv_export_extra_args: %s", uv_export_extra_args) + with install_uv_dependencies( + query, path, uv_export_extra_args, tmp_dir + ) as rd: + if rd: + if pf: + self._zip_write_with_filter( + zs, pf, rd, prefix, timestamp=0 + ) + else: + zs.write_dirs(rd, prefix=prefix, timestamp=0) + elif cmd == "npm": runtime, npm_requirements, prefix, tmp_dir = action[1:] with install_npm_requirements( @@ -1378,6 +1428,145 @@ def copy_file_to_target(file, temp_dir): yield temp_dir +@contextmanager +def install_uv_dependencies(query, path, uv_export_extra_args, tmp_dir): + # uv.lock is required for uv + uv_lock_file = path + if os.path.isdir(path): + uv_lock_file = os.path.join(path, "uv.lock") + if not os.path.exists(uv_lock_file): + yield + return + + # pyproject.toml is required by uv + project_path = os.path.dirname(uv_lock_file) + pyproject_file = os.path.join(project_path, "pyproject.toml") + if not os.path.isfile(pyproject_file): + yield + return + + runtime = query.runtime + artifacts_dir = query.artifacts_dir + docker = query.docker + docker_image_tag_id = None + + if docker: + docker_file = docker.docker_file + docker_image = docker.docker_image + docker_build_root = docker.docker_build_root + + if docker_image: + ok = False + while True: + output = check_output(docker_image_id_command(docker_image)) + if output: + docker_image_tag_id = output.decode().strip() + log.debug( + "DOCKER TAG ID: %s -> %s", docker_image, docker_image_tag_id + ) + ok = True + if ok: + break + docker_cmd = docker_build_command( + build_root=docker_build_root, + docker_file=docker_file, + tag=docker_image, + ) + check_call(docker_cmd) + ok = True + elif docker_file or docker_build_root: + raise ValueError( + "docker_image must be specified for a custom image future references" + ) + + working_dir = os.getcwd() + + log.info("Installing python dependencies with uv & pip: %s", uv_lock_file) + with tempdir(tmp_dir) as temp_dir: + + def copy_file_to_target(file, temp_dir): + filename = os.path.basename(file) + target_file = os.path.join(temp_dir, filename) + shutil.copyfile(file, target_file) + return target_file + + pyproject_target_file = copy_file_to_target(pyproject_file, temp_dir) + uv_lock_target_file = copy_file_to_target(uv_lock_file, temp_dir) + + uv_exec = "uv" + python_exec = runtime + subproc_env = None + + if not docker: + if WINDOWS: + uv_exec = "uv.exe" + + with cd(temp_dir): + uv_export = [ + uv_exec, + "export", + "--frozen", + "--no-dev", + "-o", + "requirements.txt", + ] + uv_export_extra_args + + uv_commands = [ + uv_export, + [ + python_exec, + "-m", + "pip", + "install", + "--no-compile", + "--target=.", + "--requirement=requirements.txt", + ], + ] + + if docker: + with_ssh_agent = docker.with_ssh_agent + chown_mask = "{}:{}".format(os.getuid(), os.getgid()) + uv_commands += [["chown", "-R", chown_mask, "."]] + shell_commands = [shlex_join(cmd) for cmd in uv_commands] + shell_command = [" && ".join(shell_commands)] + check_call( + docker_run_command( + ".", + shell_command, + runtime, + image=docker_image_tag_id, + shell=True, + ssh_agent=with_ssh_agent, + docker=docker, + ) + ) + else: + cmd_log.info(uv_commands) + log_handler and log_handler.flush() + for uv_command in uv_commands: + try: + if query.quiet: + check_call( + uv_command, + env=subproc_env, + stdout=subprocess.DEVNULL, + stderr=subprocess.DEVNULL, + ) + else: + check_call(uv_command, env=subproc_env) + except FileNotFoundError as e: + raise RuntimeError( + "UV executable must be installed and available in PATH " + "for runtime ({})".format(runtime) + ) from e + + os.remove(pyproject_target_file) + os.remove(uv_lock_target_file) + + yield temp_dir + + @contextmanager def install_npm_requirements(query, requirements_file, tmp_dir): # TODO: diff --git a/tests/test_package_toml.py b/tests/test_package_toml.py index 9eba3f4a..0953ac11 100644 --- a/tests/test_package_toml.py +++ b/tests/test_package_toml.py @@ -39,3 +39,12 @@ def test_get_build_system_from_pyproject_toml_poetry(): ) == "poetry" ) + + +def test_get_build_system_from_pyproject_toml_uv(): + assert ( + get_build_system_from_pyproject_toml( + "examples/fixtures/python-app-uv/pyproject.toml" + ) + == "uv" + )