theoremlp / rules_uv

Bazel rules for running uv
Apache License 2.0
31 stars 14 forks source link

output of uv pip compile has wrong syntax with extras #110

Open alexeagle opened 4 weeks ago

alexeagle commented 4 weeks ago

This may be a bug in uv, I'm not sure how to tell and haven't had time to dig in. Please forgive me filing an issue that's not well-researched :)

Installing a package with extras, such as etils[epath, epy] results in output from the pip_compile rule which has some whitespace issue.

Here's the patch one of my clients applied to workaround it:

diff --git a/uv/private/pip_compile.sh b/uv/private/pip_compile.sh
index 63b8a6d..260c31e 100644
--- a/uv/private/pip_compile.sh
+++ b/uv/private/pip_compile.sh
@@ -8,6 +8,16 @@ REQUIREMENTS_TXT="{{requirements_txt}}"

 {{uv}} pip compile \
     {{args}} \
-    --output-file="$REQUIREMENTS_TXT" \
     "$REQUIREMENTS_IN" \
-    "$@"
+    "$@" | \
+awk '{
+    if (match($0, /\[[^]]+\]/)) {
+        before = substr($0, 1, RSTART-1)
+        bracket_content = substr($0, RSTART+1, RLENGTH-2)
+        after = substr($0, RSTART+RLENGTH)
+        gsub(/[[:space:]]*,[[:space:]]*/, ",", bracket_content)
+        print before "[" bracket_content "]" after
+    } else {
+        print $0
+    }
+}' | tee "$REQUIREMENTS_TXT"
\ No newline at end of file
mark-thm commented 4 weeks ago

If you need to overwrite requirements.txt it's a uv bug, I believe.