Add support for python deployments with uv

uv (https://docs.astral.sh/uv/) is a fast package and project manager
for python that is quickly gaining in popularity. The new deploy
functions uses uv's built in virtual environment handling, but sets the
environment path to the normal piku env path.

Since it is new, I marked it as experimental, just like the poetry one.
To not break any existing workflows, poetry is preferred if both poetry
and uv are installed.
pull/390/head
Karl Bartel 2025-01-25 09:13:03 +01:00
rodzic 29970d7ca1
commit 04dbc1e632
1 zmienionych plików z 24 dodań i 0 usunięć

24
piku.py
Wyświetl plik

@ -398,6 +398,8 @@ def do_deploy(app, deltas={}, newrev=None):
settings.update(deploy_python(app, deltas))
elif exists(join(app_path, 'pyproject.toml')) and which('poetry') and found_app("Python"):
settings.update(deploy_python_with_poetry(app, deltas))
elif exists(join(app_path, 'pyproject.toml')) and which('uv') and found_app("Python (uv)"):
settings.update(deploy_python_with_uv(app, deltas))
elif exists(join(app_path, 'Gemfile')) and found_app("Ruby Application") and check_requirements(['ruby', 'gem', 'bundle']):
settings.update(deploy_ruby(app, deltas))
elif exists(join(app_path, 'package.json')) and found_app("Node") and (
@ -750,6 +752,28 @@ def deploy_python_with_poetry(app, deltas={}):
return spawn_app(app, deltas)
def deploy_python_with_uv(app, deltas={}):
"""Deploy a Python application using Astral uv"""
echo("=====> Starting EXPERIMENTAL uv deployment for '{}'".format(app), fg='red')
env_file = join(APP_ROOT, app, 'ENV')
virtualenv_path = join(ENV_ROOT, app)
# Set unbuffered output and readable UTF-8 mapping
env = {
**environ,
'PYTHONUNBUFFERED': '1',
'PYTHONIOENCODING': 'UTF_8:replace',
'UV_PROJECT_ENVIRONMENT': virtualenv_path
}
if exists(env_file):
env.update(parse_settings(env_file, env))
echo("-----> Calling uv sync", fg='green')
call('uv sync --python-preference only-system', cwd=join(APP_ROOT, app), env=env, shell=True)
return spawn_app(app, deltas)
def deploy_identity(app, deltas={}):
env_path = join(ENV_ROOT, app)
if not exists(env_path):