Skip to content

Commit 6e2d493

Browse files
asaaignas
andauthored
fix: Prevent absolute path creation in uv lock template (bazel-contrib#2769)
This change fixes a bug in the `lock` rule where, when the package is at the root level, the path to `requirements.txt` is constructed incorrectly with a leading double slash (`//requirements.txt`), causing it to be interpreted as an absolute path. This change detects if the package is empty before constructing the output path. Work towards bazel-contrib#1975 --------- Co-authored-by: Ignas Anikevicius <[email protected]>
1 parent 55d6836 commit 6e2d493

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

python/uv/private/lock.bzl

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,10 +327,15 @@ def _maybe_file(path):
327327
def _expand_template_impl(ctx):
328328
pkg = ctx.label.package
329329
update_src = ctx.actions.declare_file(ctx.attr.update_target + ".py")
330+
331+
# Fix the path construction to avoid absolute paths
332+
# If package is empty (root), don't add a leading slash
333+
dst = "{}/{}".format(pkg, ctx.attr.output) if pkg else ctx.attr.output
334+
330335
ctx.actions.expand_template(
331336
template = ctx.files._template[0],
332337
substitutions = {
333-
"{{dst}}": "{}/{}".format(pkg, ctx.attr.output),
338+
"{{dst}}": dst,
334339
"{{src}}": "{}".format(ctx.files.src[0].short_path),
335340
"{{update_target}}": "//{}:{}".format(pkg, ctx.attr.update_target),
336341
},

0 commit comments

Comments
 (0)