From 96a2c121c757e2df9f36efa075647787f5b20301 Mon Sep 17 00:00:00 2001 From: "Elvis M. Wianda" <7077790+ewianda@users.noreply.github.com> Date: Wed, 6 Nov 2024 15:09:23 -0500 Subject: [PATCH] Add args to venv rule (#165) Add uv_args to venv. This is useful cases when you need to pass `index-strategy` when using more than one index-url --- uv/private/create_venv.sh | 2 +- uv/private/venv.bzl | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/uv/private/create_venv.sh b/uv/private/create_venv.sh index 1d4141e..10edaf4 100644 --- a/uv/private/create_venv.sh +++ b/uv/private/create_venv.sh @@ -28,7 +28,7 @@ fi "$UV" venv "$BUILD_WORKSPACE_DIRECTORY/$target" --python "$PYTHON" source "$BUILD_WORKSPACE_DIRECTORY/$target/bin/activate" -"$UV" pip install -r "$REQUIREMENTS_TXT" +"$UV" pip install -r "$REQUIREMENTS_TXT" {{args}} site_packages_extra_files=({{site_packages_extra_files}}) if [ ! -z ${site_packages_extra_files+x} ]; then diff --git a/uv/private/venv.bzl b/uv/private/venv.bzl index 1cc298c..77e7907 100644 --- a/uv/private/venv.bzl +++ b/uv/private/venv.bzl @@ -16,6 +16,7 @@ def _uv_template(ctx, template, executable): "{{resolved_python}}": py_toolchain.py3_runtime.interpreter.short_path, "{{destination_folder}}": ctx.attr.destination_folder, "{{site_packages_extra_files}}": " ".join(["'" + file.short_path + "'" for file in ctx.files.site_packages_extra_files]), + "{{args}}": " \\\n ".join(ctx.attr.uv_args), }, ) @@ -43,17 +44,19 @@ _venv = rule( "requirements_txt": attr.label(mandatory = True, allow_single_file = True), "_uv": attr.label(default = "@multitool//tools/uv", executable = True, cfg = transition_to_target), "_template": attr.label(default = "//uv/private:create_venv.sh", allow_single_file = True), + "uv_args": attr.string_list(default = []), }, toolchains = [_PY_TOOLCHAIN], implementation = _venv_impl, executable = True, ) -def create_venv(name, requirements_txt = None, target_compatible_with = None, destination_folder = None, site_packages_extra_files = []): +def create_venv(name, requirements_txt = None, target_compatible_with = None, destination_folder = None, site_packages_extra_files = [], uv_args = []): _venv( name = name, destination_folder = destination_folder, site_packages_extra_files = site_packages_extra_files, requirements_txt = requirements_txt or "//:requirements.txt", target_compatible_with = target_compatible_with, + uv_args = uv_args, )