diff --git a/docs/pages/docs/providers/python.md b/docs/pages/docs/providers/python.md index 950a24350..1f60e14ce 100644 --- a/docs/pages/docs/providers/python.md +++ b/docs/pages/docs/providers/python.md @@ -11,6 +11,8 @@ Python is detected if any of the following files are found - `pyproject.toml` - `Pipfile` +A venv is created at `/opt/venv` and `PATH` is modified to use the venv python binary. + ## Setup The following Python versions are available @@ -21,12 +23,20 @@ The following Python versions are available - `3.10` - `3.11` (Default) - `3.12` +- `3.13` The version can be overridden by - Setting the `NIXPACKS_PYTHON_VERSION` environment variable - Setting the version in a `.python-version` file - Setting the version in a `runtime.txt` file +- Setting the version in a `.tool-versions` file + +You also specify the exact poetry, pdm, and uv versions: + +- The `NIXPACKS_POETRY_VERSION` environment variable or `poetry` in a `.tool-versions` file +- The `NIXPACKS_PDM_VERSION` environment variable +- The `NIXPACKS_UV_VERSION` environment variable or `uv` in a `.tool-versions` file ## Install @@ -60,6 +70,12 @@ If `Pipfile` (w/ `Pipfile.lock`) PIPENV_VENV_IN_PROJECT=1 pipenv install --deploy ``` +if `uv.lock`: + +``` +uv sync --no-dev --frozen +``` + ## Start if Django Application @@ -85,6 +101,8 @@ python main.py These directories are cached between builds - Install: `~/.cache/pip` +- Install: `~/.cache/uv` +- Install: `~/.cache/pdm` ## Environment Variables diff --git a/examples/python-uv/.python-version b/examples/python-uv/.python-version new file mode 100644 index 000000000..e4fba2183 --- /dev/null +++ b/examples/python-uv/.python-version @@ -0,0 +1 @@ +3.12 diff --git a/examples/python-uv/README.md b/examples/python-uv/README.md new file mode 100644 index 000000000..e69de29bb diff --git a/examples/python-uv/main.py b/examples/python-uv/main.py new file mode 100644 index 000000000..c2af0d40b --- /dev/null +++ b/examples/python-uv/main.py @@ -0,0 +1 @@ +print("Hello from Python-Uv") diff --git a/examples/python-uv/pyproject.toml b/examples/python-uv/pyproject.toml new file mode 100644 index 000000000..72886e14c --- /dev/null +++ b/examples/python-uv/pyproject.toml @@ -0,0 +1,14 @@ +[project] +name = "python-uv" +version = "0.1.0" +description = "Add your description here" +readme = "README.md" +requires-python = ">=3.12" +dependencies = [ + "flask>=3.0.3", +] + +[dependency-groups] +dev = [ + "pytest>=8.3.3", +] diff --git a/examples/python-uv/uv.lock b/examples/python-uv/uv.lock new file mode 100644 index 000000000..3a82a5d95 --- /dev/null +++ b/examples/python-uv/uv.lock @@ -0,0 +1,180 @@ +version = 1 +requires-python = ">=3.12" + +[[package]] +name = "blinker" +version = "1.9.0" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/21/28/9b3f50ce0e048515135495f198351908d99540d69bfdc8c1d15b73dc55ce/blinker-1.9.0.tar.gz", hash = "sha256:b4ce2265a7abece45e7cc896e98dbebe6cead56bcf805a3d23136d145f5445bf", size = 22460 } +wheels = [ + { url = "https://files.pythonhosted.org/packages/10/cb/f2ad4230dc2eb1a74edf38f1a38b9b52277f75bef262d8908e60d957e13c/blinker-1.9.0-py3-none-any.whl", hash = "sha256:ba0efaa9080b619ff2f3459d1d500c57bddea4a6b424b60a91141db6fd2f08bc", size = 8458 }, +] + +[[package]] +name = "click" +version = "8.1.7" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "colorama", marker = "platform_system == 'Windows'" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/96/d3/f04c7bfcf5c1862a2a5b845c6b2b360488cf47af55dfa79c98f6a6bf98b5/click-8.1.7.tar.gz", hash = "sha256:ca9853ad459e787e2192211578cc907e7594e294c7ccc834310722b41b9ca6de", size = 336121 } +wheels = [ + { url = "https://files.pythonhosted.org/packages/00/2e/d53fa4befbf2cfa713304affc7ca780ce4fc1fd8710527771b58311a3229/click-8.1.7-py3-none-any.whl", hash = "sha256:ae74fb96c20a0277a1d615f1e4d73c8414f5a98db8b799a7931d1582f3390c28", size = 97941 }, +] + +[[package]] +name = "colorama" +version = "0.4.6" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/d8/53/6f443c9a4a8358a93a6792e2acffb9d9d5cb0a5cfd8802644b7b1c9a02e4/colorama-0.4.6.tar.gz", hash = "sha256:08695f5cb7ed6e0531a20572697297273c47b8cae5a63ffc6d6ed5c201be6e44", size = 27697 } +wheels = [ + { url = "https://files.pythonhosted.org/packages/d1/d6/3965ed04c63042e047cb6a3e6ed1a63a35087b6a609aa3a15ed8ac56c221/colorama-0.4.6-py2.py3-none-any.whl", hash = "sha256:4f1d9991f5acc0ca119f9d443620b77f9d6b33703e51011c16baf57afb285fc6", size = 25335 }, +] + +[[package]] +name = "flask" +version = "3.0.3" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "blinker" }, + { name = "click" }, + { name = "itsdangerous" }, + { name = "jinja2" }, + { name = "werkzeug" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/41/e1/d104c83026f8d35dfd2c261df7d64738341067526406b40190bc063e829a/flask-3.0.3.tar.gz", hash = "sha256:ceb27b0af3823ea2737928a4d99d125a06175b8512c445cbd9a9ce200ef76842", size = 676315 } +wheels = [ + { url = "https://files.pythonhosted.org/packages/61/80/ffe1da13ad9300f87c93af113edd0638c75138c42a0994becfacac078c06/flask-3.0.3-py3-none-any.whl", hash = "sha256:34e815dfaa43340d1d15a5c3a02b8476004037eb4840b34910c6e21679d288f3", size = 101735 }, +] + +[[package]] +name = "iniconfig" +version = "2.0.0" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/d7/4b/cbd8e699e64a6f16ca3a8220661b5f83792b3017d0f79807cb8708d33913/iniconfig-2.0.0.tar.gz", hash = "sha256:2d91e135bf72d31a410b17c16da610a82cb55f6b0477d1a902134b24a455b8b3", size = 4646 } +wheels = [ + { url = "https://files.pythonhosted.org/packages/ef/a6/62565a6e1cf69e10f5727360368e451d4b7f58beeac6173dc9db836a5b46/iniconfig-2.0.0-py3-none-any.whl", hash = "sha256:b6a85871a79d2e3b22d2d1b94ac2824226a63c6b741c88f7ae975f18b6778374", size = 5892 }, +] + +[[package]] +name = "itsdangerous" +version = "2.2.0" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/9c/cb/8ac0172223afbccb63986cc25049b154ecfb5e85932587206f42317be31d/itsdangerous-2.2.0.tar.gz", hash = "sha256:e0050c0b7da1eea53ffaf149c0cfbb5c6e2e2b69c4bef22c81fa6eb73e5f6173", size = 54410 } +wheels = [ + { url = "https://files.pythonhosted.org/packages/04/96/92447566d16df59b2a776c0fb82dbc4d9e07cd95062562af01e408583fc4/itsdangerous-2.2.0-py3-none-any.whl", hash = "sha256:c6242fc49e35958c8b15141343aa660db5fc54d4f13a1db01a3f5891b98700ef", size = 16234 }, +] + +[[package]] +name = "jinja2" +version = "3.1.4" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "markupsafe" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/ed/55/39036716d19cab0747a5020fc7e907f362fbf48c984b14e62127f7e68e5d/jinja2-3.1.4.tar.gz", hash = "sha256:4a3aee7acbbe7303aede8e9648d13b8bf88a429282aa6122a993f0ac800cb369", size = 240245 } +wheels = [ + { url = "https://files.pythonhosted.org/packages/31/80/3a54838c3fb461f6fec263ebf3a3a41771bd05190238de3486aae8540c36/jinja2-3.1.4-py3-none-any.whl", hash = "sha256:bc5dd2abb727a5319567b7a813e6a2e7318c39f4f487cfe6c89c6f9c7d25197d", size = 133271 }, +] + +[[package]] +name = "markupsafe" +version = "3.0.2" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/b2/97/5d42485e71dfc078108a86d6de8fa46db44a1a9295e89c5d6d4a06e23a62/markupsafe-3.0.2.tar.gz", hash = "sha256:ee55d3edf80167e48ea11a923c7386f4669df67d7994554387f84e7d8b0a2bf0", size = 20537 } +wheels = [ + { url = "https://files.pythonhosted.org/packages/22/09/d1f21434c97fc42f09d290cbb6350d44eb12f09cc62c9476effdb33a18aa/MarkupSafe-3.0.2-cp312-cp312-macosx_10_13_universal2.whl", hash = "sha256:9778bd8ab0a994ebf6f84c2b949e65736d5575320a17ae8984a77fab08db94cf", size = 14274 }, + { url = "https://files.pythonhosted.org/packages/6b/b0/18f76bba336fa5aecf79d45dcd6c806c280ec44538b3c13671d49099fdd0/MarkupSafe-3.0.2-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:846ade7b71e3536c4e56b386c2a47adf5741d2d8b94ec9dc3e92e5e1ee1e2225", size = 12348 }, + { url = "https://files.pythonhosted.org/packages/e0/25/dd5c0f6ac1311e9b40f4af06c78efde0f3b5cbf02502f8ef9501294c425b/MarkupSafe-3.0.2-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:1c99d261bd2d5f6b59325c92c73df481e05e57f19837bdca8413b9eac4bd8028", size = 24149 }, + { url = "https://files.pythonhosted.org/packages/f3/f0/89e7aadfb3749d0f52234a0c8c7867877876e0a20b60e2188e9850794c17/MarkupSafe-3.0.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:e17c96c14e19278594aa4841ec148115f9c7615a47382ecb6b82bd8fea3ab0c8", size = 23118 }, + { url = "https://files.pythonhosted.org/packages/d5/da/f2eeb64c723f5e3777bc081da884b414671982008c47dcc1873d81f625b6/MarkupSafe-3.0.2-cp312-cp312-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:88416bd1e65dcea10bc7569faacb2c20ce071dd1f87539ca2ab364bf6231393c", size = 22993 }, + { url = "https://files.pythonhosted.org/packages/da/0e/1f32af846df486dce7c227fe0f2398dc7e2e51d4a370508281f3c1c5cddc/MarkupSafe-3.0.2-cp312-cp312-musllinux_1_2_aarch64.whl", hash = "sha256:2181e67807fc2fa785d0592dc2d6206c019b9502410671cc905d132a92866557", size = 24178 }, + { url = "https://files.pythonhosted.org/packages/c4/f6/bb3ca0532de8086cbff5f06d137064c8410d10779c4c127e0e47d17c0b71/MarkupSafe-3.0.2-cp312-cp312-musllinux_1_2_i686.whl", hash = "sha256:52305740fe773d09cffb16f8ed0427942901f00adedac82ec8b67752f58a1b22", size = 23319 }, + { url = "https://files.pythonhosted.org/packages/a2/82/8be4c96ffee03c5b4a034e60a31294daf481e12c7c43ab8e34a1453ee48b/MarkupSafe-3.0.2-cp312-cp312-musllinux_1_2_x86_64.whl", hash = "sha256:ad10d3ded218f1039f11a75f8091880239651b52e9bb592ca27de44eed242a48", size = 23352 }, + { url = "https://files.pythonhosted.org/packages/51/ae/97827349d3fcffee7e184bdf7f41cd6b88d9919c80f0263ba7acd1bbcb18/MarkupSafe-3.0.2-cp312-cp312-win32.whl", hash = "sha256:0f4ca02bea9a23221c0182836703cbf8930c5e9454bacce27e767509fa286a30", size = 15097 }, + { url = "https://files.pythonhosted.org/packages/c1/80/a61f99dc3a936413c3ee4e1eecac96c0da5ed07ad56fd975f1a9da5bc630/MarkupSafe-3.0.2-cp312-cp312-win_amd64.whl", hash = "sha256:8e06879fc22a25ca47312fbe7c8264eb0b662f6db27cb2d3bbbc74b1df4b9b87", size = 15601 }, + { url = "https://files.pythonhosted.org/packages/83/0e/67eb10a7ecc77a0c2bbe2b0235765b98d164d81600746914bebada795e97/MarkupSafe-3.0.2-cp313-cp313-macosx_10_13_universal2.whl", hash = "sha256:ba9527cdd4c926ed0760bc301f6728ef34d841f405abf9d4f959c478421e4efd", size = 14274 }, + { url = "https://files.pythonhosted.org/packages/2b/6d/9409f3684d3335375d04e5f05744dfe7e9f120062c9857df4ab490a1031a/MarkupSafe-3.0.2-cp313-cp313-macosx_11_0_arm64.whl", hash = "sha256:f8b3d067f2e40fe93e1ccdd6b2e1d16c43140e76f02fb1319a05cf2b79d99430", size = 12352 }, + { url = "https://files.pythonhosted.org/packages/d2/f5/6eadfcd3885ea85fe2a7c128315cc1bb7241e1987443d78c8fe712d03091/MarkupSafe-3.0.2-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:569511d3b58c8791ab4c2e1285575265991e6d8f8700c7be0e88f86cb0672094", size = 24122 }, + { url = "https://files.pythonhosted.org/packages/0c/91/96cf928db8236f1bfab6ce15ad070dfdd02ed88261c2afafd4b43575e9e9/MarkupSafe-3.0.2-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:15ab75ef81add55874e7ab7055e9c397312385bd9ced94920f2802310c930396", size = 23085 }, + { url = "https://files.pythonhosted.org/packages/c2/cf/c9d56af24d56ea04daae7ac0940232d31d5a8354f2b457c6d856b2057d69/MarkupSafe-3.0.2-cp313-cp313-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:f3818cb119498c0678015754eba762e0d61e5b52d34c8b13d770f0719f7b1d79", size = 22978 }, + { url = "https://files.pythonhosted.org/packages/2a/9f/8619835cd6a711d6272d62abb78c033bda638fdc54c4e7f4272cf1c0962b/MarkupSafe-3.0.2-cp313-cp313-musllinux_1_2_aarch64.whl", hash = "sha256:cdb82a876c47801bb54a690c5ae105a46b392ac6099881cdfb9f6e95e4014c6a", size = 24208 }, + { url = "https://files.pythonhosted.org/packages/f9/bf/176950a1792b2cd2102b8ffeb5133e1ed984547b75db47c25a67d3359f77/MarkupSafe-3.0.2-cp313-cp313-musllinux_1_2_i686.whl", hash = "sha256:cabc348d87e913db6ab4aa100f01b08f481097838bdddf7c7a84b7575b7309ca", size = 23357 }, + { url = "https://files.pythonhosted.org/packages/ce/4f/9a02c1d335caabe5c4efb90e1b6e8ee944aa245c1aaaab8e8a618987d816/MarkupSafe-3.0.2-cp313-cp313-musllinux_1_2_x86_64.whl", hash = "sha256:444dcda765c8a838eaae23112db52f1efaf750daddb2d9ca300bcae1039adc5c", size = 23344 }, + { url = "https://files.pythonhosted.org/packages/ee/55/c271b57db36f748f0e04a759ace9f8f759ccf22b4960c270c78a394f58be/MarkupSafe-3.0.2-cp313-cp313-win32.whl", hash = "sha256:bcf3e58998965654fdaff38e58584d8937aa3096ab5354d493c77d1fdd66d7a1", size = 15101 }, + { url = "https://files.pythonhosted.org/packages/29/88/07df22d2dd4df40aba9f3e402e6dc1b8ee86297dddbad4872bd5e7b0094f/MarkupSafe-3.0.2-cp313-cp313-win_amd64.whl", hash = "sha256:e6a2a455bd412959b57a172ce6328d2dd1f01cb2135efda2e4576e8a23fa3b0f", size = 15603 }, + { url = "https://files.pythonhosted.org/packages/62/6a/8b89d24db2d32d433dffcd6a8779159da109842434f1dd2f6e71f32f738c/MarkupSafe-3.0.2-cp313-cp313t-macosx_10_13_universal2.whl", hash = "sha256:b5a6b3ada725cea8a5e634536b1b01c30bcdcd7f9c6fff4151548d5bf6b3a36c", size = 14510 }, + { url = "https://files.pythonhosted.org/packages/7a/06/a10f955f70a2e5a9bf78d11a161029d278eeacbd35ef806c3fd17b13060d/MarkupSafe-3.0.2-cp313-cp313t-macosx_11_0_arm64.whl", hash = "sha256:a904af0a6162c73e3edcb969eeeb53a63ceeb5d8cf642fade7d39e7963a22ddb", size = 12486 }, + { url = "https://files.pythonhosted.org/packages/34/cf/65d4a571869a1a9078198ca28f39fba5fbb910f952f9dbc5220afff9f5e6/MarkupSafe-3.0.2-cp313-cp313t-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:4aa4e5faecf353ed117801a068ebab7b7e09ffb6e1d5e412dc852e0da018126c", size = 25480 }, + { url = "https://files.pythonhosted.org/packages/0c/e3/90e9651924c430b885468b56b3d597cabf6d72be4b24a0acd1fa0e12af67/MarkupSafe-3.0.2-cp313-cp313t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:c0ef13eaeee5b615fb07c9a7dadb38eac06a0608b41570d8ade51c56539e509d", size = 23914 }, + { url = "https://files.pythonhosted.org/packages/66/8c/6c7cf61f95d63bb866db39085150df1f2a5bd3335298f14a66b48e92659c/MarkupSafe-3.0.2-cp313-cp313t-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:d16a81a06776313e817c951135cf7340a3e91e8c1ff2fac444cfd75fffa04afe", size = 23796 }, + { url = "https://files.pythonhosted.org/packages/bb/35/cbe9238ec3f47ac9a7c8b3df7a808e7cb50fe149dc7039f5f454b3fba218/MarkupSafe-3.0.2-cp313-cp313t-musllinux_1_2_aarch64.whl", hash = "sha256:6381026f158fdb7c72a168278597a5e3a5222e83ea18f543112b2662a9b699c5", size = 25473 }, + { url = "https://files.pythonhosted.org/packages/e6/32/7621a4382488aa283cc05e8984a9c219abad3bca087be9ec77e89939ded9/MarkupSafe-3.0.2-cp313-cp313t-musllinux_1_2_i686.whl", hash = "sha256:3d79d162e7be8f996986c064d1c7c817f6df3a77fe3d6859f6f9e7be4b8c213a", size = 24114 }, + { url = "https://files.pythonhosted.org/packages/0d/80/0985960e4b89922cb5a0bac0ed39c5b96cbc1a536a99f30e8c220a996ed9/MarkupSafe-3.0.2-cp313-cp313t-musllinux_1_2_x86_64.whl", hash = "sha256:131a3c7689c85f5ad20f9f6fb1b866f402c445b220c19fe4308c0b147ccd2ad9", size = 24098 }, + { url = "https://files.pythonhosted.org/packages/82/78/fedb03c7d5380df2427038ec8d973587e90561b2d90cd472ce9254cf348b/MarkupSafe-3.0.2-cp313-cp313t-win32.whl", hash = "sha256:ba8062ed2cf21c07a9e295d5b8a2a5ce678b913b45fdf68c32d95d6c1291e0b6", size = 15208 }, + { url = "https://files.pythonhosted.org/packages/4f/65/6079a46068dfceaeabb5dcad6d674f5f5c61a6fa5673746f42a9f4c233b3/MarkupSafe-3.0.2-cp313-cp313t-win_amd64.whl", hash = "sha256:e444a31f8db13eb18ada366ab3cf45fd4b31e4db1236a4448f68778c1d1a5a2f", size = 15739 }, +] + +[[package]] +name = "packaging" +version = "24.2" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/d0/63/68dbb6eb2de9cb10ee4c9c14a0148804425e13c4fb20d61cce69f53106da/packaging-24.2.tar.gz", hash = "sha256:c228a6dc5e932d346bc5739379109d49e8853dd8223571c7c5b55260edc0b97f", size = 163950 } +wheels = [ + { url = "https://files.pythonhosted.org/packages/88/ef/eb23f262cca3c0c4eb7ab1933c3b1f03d021f2c48f54763065b6f0e321be/packaging-24.2-py3-none-any.whl", hash = "sha256:09abb1bccd265c01f4a3aa3f7a7db064b36514d2cba19a2f694fe6150451a759", size = 65451 }, +] + +[[package]] +name = "pluggy" +version = "1.5.0" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/96/2d/02d4312c973c6050a18b314a5ad0b3210edb65a906f868e31c111dede4a6/pluggy-1.5.0.tar.gz", hash = "sha256:2cffa88e94fdc978c4c574f15f9e59b7f4201d439195c3715ca9e2486f1d0cf1", size = 67955 } +wheels = [ + { url = "https://files.pythonhosted.org/packages/88/5f/e351af9a41f866ac3f1fac4ca0613908d9a41741cfcf2228f4ad853b697d/pluggy-1.5.0-py3-none-any.whl", hash = "sha256:44e1ad92c8ca002de6377e165f3e0f1be63266ab4d554740532335b9d75ea669", size = 20556 }, +] + +[[package]] +name = "pytest" +version = "8.3.3" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "colorama", marker = "sys_platform == 'win32'" }, + { name = "iniconfig" }, + { name = "packaging" }, + { name = "pluggy" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/8b/6c/62bbd536103af674e227c41a8f3dcd022d591f6eed5facb5a0f31ee33bbc/pytest-8.3.3.tar.gz", hash = "sha256:70b98107bd648308a7952b06e6ca9a50bc660be218d53c257cc1fc94fda10181", size = 1442487 } +wheels = [ + { url = "https://files.pythonhosted.org/packages/6b/77/7440a06a8ead44c7757a64362dd22df5760f9b12dc5f11b6188cd2fc27a0/pytest-8.3.3-py3-none-any.whl", hash = "sha256:a6853c7375b2663155079443d2e45de913a911a11d669df02a50814944db57b2", size = 342341 }, +] + +[[package]] +name = "python-uv" +version = "0.1.0" +source = { virtual = "." } +dependencies = [ + { name = "flask" }, +] + +[package.dev-dependencies] +dev = [ + { name = "pytest" }, +] + +[package.metadata] +requires-dist = [{ name = "flask", specifier = ">=3.0.3" }] + +[package.metadata.requires-dev] +dev = [{ name = "pytest", specifier = ">=8.3.3" }] + +[[package]] +name = "werkzeug" +version = "3.1.3" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "markupsafe" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/9f/69/83029f1f6300c5fb2471d621ab06f6ec6b3324685a2ce0f9777fd4a8b71e/werkzeug-3.1.3.tar.gz", hash = "sha256:60723ce945c19328679790e3282cc758aa4a6040e4bb330f53d30fa546d44746", size = 806925 } +wheels = [ + { url = "https://files.pythonhosted.org/packages/52/24/ab44c871b0f07f491e5d2ad12c9bd7358e527510618cb1b803a88e986db1/werkzeug-3.1.3-py3-none-any.whl", hash = "sha256:54b78bf3716d19a65be4fceccc0d1d7b89e608834989dfae50ea87564639213e", size = 224498 }, +] diff --git a/src/providers/python.rs b/src/providers/python.rs index 15cee4627..30d116556 100644 --- a/src/providers/python.rs +++ b/src/providers/python.rs @@ -22,11 +22,15 @@ use super::{Provider, ProviderMetadata}; const DEFAULT_PYTHON_PKG_NAME: &str = "python3"; const POETRY_VERSION: &str = "1.3.1"; const PDM_VERSION: &str = "2.13.3"; +const UV_VERSION: &str = "0.4.30"; + +const VENV_LOCATION: &str = "/opt/venv"; +const UV_CACHE_DIR: &str = "/root/.cache/uv"; const PIP_CACHE_DIR: &str = "/root/.cache/pip"; const PDM_CACHE_DIR: &str = "/root/.cache/pdm"; const DEFAULT_POETRY_PYTHON_PKG_NAME: &str = "python3"; -const PYTHON_NIXPKGS_ARCHIVE: &str = "bf446f08bff6814b569265bef8374cfdd3d8f0e0"; +const PYTHON_NIXPKGS_ARCHIVE: &str = "bc8f8d1be58e8c8383e683a06e1e1e57893fff87"; const LEGACY_PYTHON_NIXPKGS_ARCHIVE: &str = "5148520bfab61f99fd25fb9ff7bfbb50dad3c9db"; pub struct PythonProvider {} @@ -92,6 +96,7 @@ impl Provider for PythonProvider { version, )])); } + if app.includes_file("pdm.lock") { plan.add_variables(EnvironmentVariables::from([( "NIXPACKS_PDM_VERSION".to_string(), @@ -99,6 +104,30 @@ impl Provider for PythonProvider { )])); } + // uv version is not, as of 0.4.30, specified in the lock file or pyproject.toml + if app.includes_file("uv.lock") { + let mut version = UV_VERSION.to_string(); + + if app.includes_file(".tool-versions") { + let file_content = &app.read_file(".tool-versions")?; + + if let Some(uv_version) = + PythonProvider::parse_tool_versions_uv_version(file_content)? + { + println!("Using uv version from .tool-versions: {uv_version}"); + version = uv_version; + } + } + + plan.add_variables(EnvironmentVariables::from([ + ("NIXPACKS_UV_VERSION".to_string(), version), + ( + "UV_PROJECT_ENVIRONMENT".to_string(), + VENV_LOCATION.to_string(), + ), + ])); + } + Ok(Some(plan)) } } @@ -140,7 +169,11 @@ impl PythonProvider { if PythonProvider::is_using_postgres(app, env)? { // Postgres requires postgresql and gcc on top of the original python packages - pkgs.append(&mut vec![Pkg::new("postgresql")]); + + // .dev variant is required in order for pg_config to be available, which is needed by psycopg2 + // the .dev variant requirement is caused by this change in nix pkgs: + // https://github.com/NixOS/nixpkgs/blob/43eac3c9e618c4114a3441b52949609ea2104670/pkgs/servers/sql/postgresql/pg_config.sh + pkgs.append(&mut vec![Pkg::new("postgresql.dev")]); } if PythonProvider::is_django(app, env)? && PythonProvider::is_using_mysql(app, env)? { @@ -168,16 +201,15 @@ impl PythonProvider { } fn install(&self, app: &App, _env: &Environment) -> Result> { - let env_loc = "/opt/venv"; - let create_env = format!("python -m venv --copies {env_loc}"); - let activate_env = format!(". {env_loc}/bin/activate"); + let create_env = format!("python -m venv --copies {VENV_LOCATION}"); + let activate_env = format!(". {VENV_LOCATION}/bin/activate"); if app.includes_file("requirements.txt") { let mut install_phase = Phase::install(Some(format!( "{create_env} && {activate_env} && pip install -r requirements.txt" ))); - install_phase.add_path(format!("{env_loc}/bin")); + install_phase.add_path(format!("{VENV_LOCATION}/bin")); install_phase.add_cache_directory(PIP_CACHE_DIR.to_string()); return Ok(Some(install_phase)); @@ -188,7 +220,7 @@ impl PythonProvider { "{create_env} && {activate_env} && {install_poetry} && poetry install --no-dev --no-interaction --no-ansi" ))); - install_phase.add_path(format!("{env_loc}/bin")); + install_phase.add_path(format!("{VENV_LOCATION}/bin")); install_phase.add_cache_directory(PIP_CACHE_DIR.to_string()); @@ -199,19 +231,37 @@ impl PythonProvider { "{create_env} && {activate_env} && {install_pdm} && pdm install --prod" ))); - install_phase.add_path(format!("{env_loc}/bin")); + install_phase.add_path(format!("{VENV_LOCATION}/bin")); install_phase.add_cache_directory(PIP_CACHE_DIR.to_string()); install_phase.add_cache_directory(PDM_CACHE_DIR.to_string()); + return Ok(Some(install_phase)); + } else if app.includes_file("uv.lock") { + let install_uv = "pip install uv==$NIXPACKS_UV_VERSION".to_string(); + + // Here's how we get UV to play well with the pre-existing non-standard venv location: + // + // 1. Create a venv which allows us to use pip. pip is not installed globally with nixpkgs py + // 2. Install uv via pip + // 3. UV_PROJECT_ENVIRONMENT is specified elsewhere so `uv sync` installs packages into the same venv + + let mut install_phase = Phase::install(Some(format!( + "{create_env} && {activate_env} && {install_uv} && uv sync --no-dev --frozen" + ))); + + install_phase.add_path(format!("{VENV_LOCATION}/bin")); + install_phase.add_cache_directory(UV_CACHE_DIR.to_string()); + return Ok(Some(install_phase)); } + let mut install_phase = Phase::install(Some(format!( "{create_env} && {activate_env} && pip install --upgrade build setuptools && pip install ." ))); install_phase.add_file_dependency("pyproject.toml".to_string()); - install_phase.add_path(format!("{env_loc}/bin")); + install_phase.add_path(format!("{VENV_LOCATION}/bin")); install_phase.add_cache_directory(PIP_CACHE_DIR.to_string()); @@ -229,7 +279,7 @@ impl PythonProvider { let cmd = format!("{create_env} && {activate_env} && {cmd}"); let mut install_phase = Phase::install(Some(cmd)); - install_phase.add_path(format!("{env_loc}/bin")); + install_phase.add_path(format!("{VENV_LOCATION}/bin")); install_phase.add_cache_directory(PIP_CACHE_DIR.to_string()); return Ok(Some(install_phase)); @@ -247,6 +297,12 @@ impl PythonProvider { )))); } + // the python package is extracted from pyproject.toml, but this can often not be the desired entrypoint + // for this reason we prefer main.py to the module heuristic used in the pyproject.toml logic + if app.includes_file("main.py") { + return Ok(Some(StartPhase::new("python main.py".to_string()))); + } + if app.includes_file("pyproject.toml") { if let OkResult(meta) = PythonProvider::parse_pyproject(app) { if let Some(entry_point) = meta.entry_point { @@ -257,10 +313,6 @@ impl PythonProvider { } } } - // falls through - if app.includes_file("main.py") { - return Ok(Some(StartPhase::new("python main.py".to_string()))); - } Ok(None) } @@ -329,11 +381,11 @@ impl PythonProvider { if parts.len() == 3 { // this is the expected result, but will be unexpected to users - println!("Patch version detected in .tool-versions, but not supported in nixpkgs."); + println!("Patch python version detected in .tool-versions, but not supported in nixpkgs."); } else if parts.len() == 2 { - println!("Expected a version string in the format x.y.z from .tool-versions"); + println!("Expected a python version string in the format x.y.z from .tool-versions"); } else { - println!("Could not find a version string in the format x.y.z or x.y from .tool-versions"); + println!("Could not find a python version string in the format x.y.z or x.y from .tool-versions"); } format!("{}.{}", parts[0], parts[1]) @@ -345,12 +397,18 @@ impl PythonProvider { Ok(asdf_versions.get("poetry").cloned()) } + fn parse_tool_versions_uv_version(file_content: &str) -> Result> { + let asdf_versions = parse_tool_versions_content(file_content); + Ok(asdf_versions.get("uv").cloned()) + } + fn default_python_environment_variables() -> EnvironmentVariables { let python_variables = vec![ ("PYTHONFAULTHANDLER", "1"), ("PYTHONUNBUFFERED", "1"), ("PYTHONHASHSEED", "random"), ("PYTHONDONTWRITEBYTECODE", "1"), + // TODO I think this would eliminate the need to include the cache version ("PIP_NO_CACHE_DIR", "1"), ("PIP_DISABLE_PIP_VERSION_CHECK", "1"), ("PIP_DEFAULT_TIMEOUT", "100"), @@ -425,11 +483,13 @@ impl PythonProvider { PYTHON_NIXPKGS_ARCHIVE.into(), )); } + let matches = matches.unwrap(); let python_version = (as_default(matches.get(1)), as_default(matches.get(2))); // Match major and minor versions match python_version { + ("3", "13") => Ok((Pkg::new("python313"), PYTHON_NIXPKGS_ARCHIVE.into())), ("3", "12") => Ok((Pkg::new("python312"), PYTHON_NIXPKGS_ARCHIVE.into())), ("3", "11") => Ok((Pkg::new("python311"), PYTHON_NIXPKGS_ARCHIVE.into())), ("3", "10") => Ok((Pkg::new("python310"), PYTHON_NIXPKGS_ARCHIVE.into())), diff --git a/tests/docker_run_tests.rs b/tests/docker_run_tests.rs index ce1c49efc..42cdf8f3d 100644 --- a/tests/docker_run_tests.rs +++ b/tests/docker_run_tests.rs @@ -936,7 +936,7 @@ async fn test_python_asdf_poetry() { let name = simple_build("./examples/python-asdf-poetry").await.unwrap(); let output = run_image(&name, None).await; - assert!(output.contains("3.12.3"), "{}", output); + assert!(output.contains("3.12.7"), "{}", output); assert!(output.contains("Poetry (version 1.8.2)"), "{}", output); } @@ -1032,6 +1032,13 @@ async fn test_python_poetry() { assert!(output.contains("Hello from Python-Poetry")); } +#[tokio::test] +async fn test_python_uv() { + let name = simple_build("./examples/python-uv").await.unwrap(); + let output = run_image(&name, None).await; + assert!(output.contains("Hello from Python-Uv")); +} + #[tokio::test] async fn test_python_pdm() { let name = simple_build("./examples/python-pdm").await.unwrap(); diff --git a/tests/snapshots/generate_plan_tests__python_django.snap b/tests/snapshots/generate_plan_tests__python_django.snap index 7e547da5e..4821f83dd 100644 --- a/tests/snapshots/generate_plan_tests__python_django.snap +++ b/tests/snapshots/generate_plan_tests__python_django.snap @@ -1,6 +1,7 @@ --- source: tests/generate_plan_tests.rs expression: plan +snapshot_kind: text --- { "providers": [], @@ -35,7 +36,7 @@ expression: plan "name": "setup", "nixPkgs": [ "python3", - "postgresql", + "postgresql.dev", "gcc" ], "nixLibs": [ diff --git a/tests/snapshots/generate_plan_tests__python_postgres.snap b/tests/snapshots/generate_plan_tests__python_postgres.snap index e8920ebdf..622bd3e09 100644 --- a/tests/snapshots/generate_plan_tests__python_postgres.snap +++ b/tests/snapshots/generate_plan_tests__python_postgres.snap @@ -1,6 +1,7 @@ --- source: tests/generate_plan_tests.rs expression: plan +snapshot_kind: text --- { "providers": [], @@ -35,7 +36,7 @@ expression: plan "name": "setup", "nixPkgs": [ "python3", - "postgresql", + "postgresql.dev", "gcc" ], "nixLibs": [ diff --git a/tests/snapshots/generate_plan_tests__python_uv.snap b/tests/snapshots/generate_plan_tests__python_uv.snap new file mode 100644 index 000000000..9ab7da7b2 --- /dev/null +++ b/tests/snapshots/generate_plan_tests__python_uv.snap @@ -0,0 +1,54 @@ +--- +source: tests/generate_plan_tests.rs +expression: plan +snapshot_kind: text +--- +{ + "providers": [], + "buildImage": "[build_image]", + "variables": { + "NIXPACKS_METADATA": "python", + "NIXPACKS_UV_VERSION": "0.4.30", + "PIP_DEFAULT_TIMEOUT": "100", + "PIP_DISABLE_PIP_VERSION_CHECK": "1", + "PIP_NO_CACHE_DIR": "1", + "PYTHONDONTWRITEBYTECODE": "1", + "PYTHONFAULTHANDLER": "1", + "PYTHONHASHSEED": "random", + "PYTHONUNBUFFERED": "1", + "UV_PROJECT_ENVIRONMENT": "/opt/venv" + }, + "phases": { + "install": { + "name": "install", + "dependsOn": [ + "setup" + ], + "cmds": [ + "python -m venv --copies /opt/venv && . /opt/venv/bin/activate && pip install uv==$NIXPACKS_UV_VERSION && uv sync --no-dev --frozen" + ], + "cacheDirectories": [ + "/root/.cache/uv" + ], + "paths": [ + "/opt/venv/bin" + ] + }, + "setup": { + "name": "setup", + "nixPkgs": [ + "python312", + "gcc" + ], + "nixLibs": [ + "zlib", + "stdenv.cc.cc.lib" + ], + "nixOverlays": [], + "nixpkgsArchive": "[archive]" + } + }, + "start": { + "cmd": "python main.py" + } +}