bazelbuild / bazelbuild/bazel-skylib

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

Open
#30 1 comment 2 reactions 0 assignees View on GitHub
good first issue P3 type: feature request
Dominant language
Starlark
Stars
444
Forks
202
PR merge metrics
No merged PRs in 30d

Description

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 `..`.

Contributor guide

Open the contributing guide

Research direction

Start at the paths.relativize entry point and inspect how the current implementation handles paths that are not fully under start. Use the three examples in the issue as the behavioral checks; done means each returns the shown relative path instead of failing, without changing fully nested behavior.

Written by the indexing model from the issue text.

Assessment

Domain
build-system
Issue type
Feature
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.