theoremlp / rules_uv

Bazel rules for running uv
Apache License 2.0
19 stars 7 forks source link

feat: Enable header generation #35

Closed honnix closed 1 month ago

honnix commented 2 months ago

Use --custom-compile-command together with label to enable header generation.

This will help users understand what bazel command to run in order to regenerate.

mark-thm commented 1 month ago

You can safely ignore the reviewbot/autosquash failures -- our automation doesn't work well with contributions from forks and we're apparently still not suppressing the runs well enough.

There is a legit CI failure in there, though.

honnix commented 1 month ago

You can safely ignore the reviewbot/autosquash failures -- our automation doesn't work well with contributions from forks and we're apparently still not suppressing the runs well enough.

There is a legit CI failure in there, though.

Hmm, this is a bit tricky:

-#    bazel run @@//:generate_requirements_linux_txt
+#    bazel run @@//:generate_requirements_linux_txt_diff_test

They are different because the labels are different.

honnix commented 1 month ago

It's not ideal, but 7c1a4694de251c8980e9fcfb9aa6326de6f66ebb should fix the tests.

honnix commented 1 month ago

Alternatively we could do

diff --git a/uv/private/pip.bzl b/uv/private/pip.bzl
index 9699fd7..00797df 100644
--- a/uv/private/pip.bzl
+++ b/uv/private/pip.bzl
@@ -1,6 +1,7 @@
 "uv based pip compile rules"

 _PY_TOOLCHAIN = "@bazel_tools//tools/python:toolchain_type"
+_DIFF_TEST_SUFFIX = "_diff_test"

 _common_attrs = {
     "requirements_in": attr.label(mandatory = True, allow_single_file = True),
@@ -25,7 +26,7 @@ def _uv_pip_compile(ctx, template, executable):
             "{{requirements_txt}}": ctx.file.requirements_txt.short_path,
             "{{resolved_python}}": py_toolchain.py3_runtime.interpreter.short_path,
             "{{python_platform}}": _python_platform(ctx.attr.python_platform),
-            "{{label}}": str(ctx.label),
+            "{{label}}": str(ctx.label).removesuffix(_DIFF_TEST_SUFFIX),
         },
     )

@@ -84,7 +85,7 @@ def pip_compile(name, requirements_in = None, requirements_txt = None, target_co
     )

     _pip_compile_test(
-        name = name + "_diff_test",
+        name = name + _DIFF_TEST_SUFFIX,
         requirements_in = requirements_in or "//:requirements.in",
         requirements_txt = requirements_txt or "//:requirements.txt",
         python_platform = python_platform or "",

The benefit is we keep the suffix manipulation in the same file, but being completely paranoid, this could accidentally remove _diff_test from a user provided label name.