Skip to content

Commit

Permalink
Add args to venv rule (#165)
Browse files Browse the repository at this point in the history
Add uv_args to venv. This is useful cases when you need to pass
`index-strategy` when using more than one index-url
  • Loading branch information
ewianda authored Nov 6, 2024
1 parent 0960711 commit 96a2c12
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
2 changes: 1 addition & 1 deletion uv/private/create_venv.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion uv/private/venv.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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),
},
)

Expand Down Expand Up @@ -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,
)

0 comments on commit 96a2c12

Please sign in to comment.