theoremlp / rules_uv

Bazel rules for running uv
Apache License 2.0
32 stars 16 forks source link

Enable passing in custom py_runtime #98

Closed chrisirhc closed 2 months ago

chrisirhc commented 2 months ago

Could use some help and opinions on the attribute name. This does add rules_python as a bazel dep in order to use the PyRuntimeInfo provider. Not sure if that's undesirable. It seems to make sense since rules_uv already depends on the toolchain made available by it.

Example usage:

# in MODULE.bazel
python = use_extension("@rules_python//python/extensions:python.bzl", "python")
python.toolchain(
    python_version = "3.11",
)
use_repo(
    python,
    "python_3_11",
)

# in BUILD.bazel
pip_compile(
    name = "requirements_3_11",
    py3_runtime = "@python_3_11//:py3_runtime",
    requirements_in = "requirements.in",
    requirements_txt = "requirements_3_11.txt",
)

Fixes #97

mark-thm commented 2 months ago

It seems like there should be a way to pass a constraint to the toolchain resolution, I’m just unsure how to do it.

chrisirhc commented 2 months ago

It seems like there should be a way to pass a constraint to the toolchain resolution, I’m just unsure how to do it.

I'm not sure how to do it either, though our use of rules_uv requires multiple pip_compile rules with a different version of python for each of them. This seems to work well in our use case since we'd need to specify a different runtime for the non-default python toolchain.

I'm also not sure how to add tests for this.

mark-thm commented 2 months ago

Thanks -- this seems like something we can/should be able to get help for on Bazel slack, I'll start a thread.

mark-thm commented 2 months ago

https://bazelbuild.slack.com/archives/CA306CEV6/p1723577616413499

chrisirhc commented 2 months ago

Added an example of usage in the PR description to help with the conversation/thread.

keith commented 2 months ago

seems like this will be super nice for projects that support multiple py versions where the default is not the lowest supported version