bazel-skylib icon indicating copy to clipboard operation
bazel-skylib copied to clipboard

paths.relativize doesn't support a path not fully under start

Open thomasvl opened this issue 7 years ago • 1 comments

The docs for paths.relativize compares itself to os.path.relpath, but the current implementation requires path be fully under start.

In theory it could also work for things that have a common prefix:

  • paths.relativize("foo/bar/baz", "foo/mumble") could return "../bar/baz"
  • paths.relativize("foo/bar", "foo/mumble/baz") could return "../../bar"
  • paths.relativize("foo/bar/baz", "mumble/grumble") could return "../../foo/bar/baz"

Right now these cases fail, so adding the support shouldn't break anyone. If callers want something fully nested, they could check the result to ensure it doesn't start with ...

thomasvl avatar Mar 13 '18 17:03 thomasvl

Aspect's Bazel library has this: https://docs.aspect.build/rules/aspect_bazel_lib/docs/paths/#relative_file

jfirebaugh avatar Jul 11 '23 15:07 jfirebaugh