bazelbuild / bazelbuild/bazel-skylib
Add strs.bzl and some additional path functions
- Dominant language
- Starlark
- Stars
- 444
- Forks
- 202
- PR merge metrics
- No merged PRs in 30d
Description
While working some Google bzl code, I've ended up implementing several functions a few times over, and it'd be nice if these were in skylib directly. I'd like to add the following:
* `strs.bzl`: for string utility functions. Initially seeded with `strip_suffix` and `strip_prefix`
* Add these to `paths.bzl`:
* `get_stem(path)`: returns the base name of a file without extension, e.g. "`foo/bar/__init__.py`" -> "`__init__`". The "stem" term comes from Python's pathlib.Path.stem api. This function comes in handy when processing Python paths, where the stem of a file determines if something is a package or not.
* `strip_all_extensions(path)`: returns the path with all extensions stripped. e.g. "foo/bar/baz.abi3.so" -> "foo/bar/baz". Paths with multiple extensions occur when dealing with Python paths (e.g. foo.cpython-37.pyc, foo.abi3.so).
* `strip_last_extension`: returns the path with only the last extension dropped. e.g. "foo/bar/baz.tar.gz" -> "foo/bar/baz.tar". This is basically a more readable version of `paths.split_extension(path)[0]`. For me, it came in handy because I have to check that there's no dots in a path, but have to remove the extension before doing so.
* `get_last_extension(path)`: returns the last extension without the dot. This is basically a more readable version of `paths.split_extension(path)[1][1:]`. For me, this comes in handy when filtering/validating paths when they didn't come from File objects.
* `split_first_extension(path)`: like split_extension, but splits at the first dot, not last. e.g. "foo/bar/baz.abi3.so" -> "foo/bar/baz", "abi3.so"
Contributor guide
Research direction
Start by reading paths.bzl, especially split_extension, and review how existing path helpers are organized. Add strs.bzl with strip_suffix and strip_prefix, then add the five requested helpers to paths.bzl; verify the examples and extension edge cases described in the issue.
Written by the indexing model from the issue text.
Assessment
- Domain
- build-system, tooling
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100