Skip to content

Commit

Permalink
Remove modules.apparent_repo_label_string
Browse files Browse the repository at this point in the history
After removing `modules.adjust_main_repo_prefix` in the previous commit,
there's no need for `modules.apparent_repo_label_string`. In other
words, if the solution to the problem is to replace `string` inputs with
`Label`s, there's no need for a special `Label` stringifier.
  • Loading branch information
mbland committed Nov 6, 2024
1 parent c8d0f67 commit b5f6722
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 91 deletions.
23 changes: 0 additions & 23 deletions docs/modules_doc.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,6 @@

Skylib module containing utilities for Bazel modules and module extensions.

<a id="modules.apparent_repo_label_string"></a>

## modules.apparent_repo_label_string

<pre>
modules.apparent_repo_label_string(<a href="#modules.apparent_repo_label_string-label">label</a>)
</pre>

Return a Label string starting with its apparent repo name.

**PARAMETERS**


| Name | Description | Default Value |
| :------------- | :------------- | :------------- |
| <a id="modules.apparent_repo_label_string-label"></a>label | a Label instance | none |

**RETURNS**

str(label) with its canonical repository name replaced with its apparent
repository name


<a id="modules.apparent_repo_name"></a>

## modules.apparent_repo_name
Expand Down
18 changes: 0 additions & 18 deletions lib/modules.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -147,26 +147,8 @@ def _apparent_repo_name(label_or_name):

return repo_name[delimiter_indices[-1] + 1:]

def _apparent_repo_label_string(label):
"""Return a Label string starting with its apparent repo name.
Args:
label: a Label instance
Returns:
str(label) with its canonical repository name replaced with its apparent
repository name
"""
repo_name = getattr(label, _repo_attr).lstrip("@")
if len(repo_name) == 0:
return str(label)

label_str = "@" + str(label).lstrip("@")
return label_str.replace(repo_name, _apparent_repo_name(label))

modules = struct(
as_extension = _as_extension,
use_all_repos = _use_all_repos,
apparent_repo_name = _apparent_repo_name,
apparent_repo_label_string = _apparent_repo_label_string,
)
50 changes: 0 additions & 50 deletions tests/modules_test.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -143,63 +143,13 @@ def _apparent_repo_name_test(ctx):

apparent_repo_name_test = unittest.make(_apparent_repo_name_test)

def _apparent_repo_label_string_test(ctx):
"""Unit tests for modules.apparent_repo_label_string."""
env = unittest.begin(ctx)

main_repo = str(Label("//:all"))
asserts.equals(
env,
main_repo,
modules.apparent_repo_label_string(Label("//:all")),
msg = "Returns top level target with leading `@` or `@@`",
)

main_module_label = Label("@bazel_skylib//:all")
asserts.equals(
env,
main_repo,
modules.apparent_repo_label_string(main_module_label),
msg = " ".join([
"Returns top level target with leading `@` or `@@`",
"for a Label containing the main module's name",
]),
)

rules_pkg = "@rules_pkg//:all"
asserts.equals(
env,
rules_pkg,
modules.apparent_repo_label_string(Label(rules_pkg)),
msg = "Returns original repo name",
)

asserts.equals(
env,
"@%s//:all" % (
"stardoc" if _is_bzlmod_enabled else "io_bazel_stardoc"
),
modules.apparent_repo_label_string(Label("@io_bazel_stardoc//:all")),
msg = " ".join([
"Returns the actual module name instead of",
"repo_name from bazel_dep() (no-op under WORKSPACE).",
]),
)

return unittest.end(env)

apparent_repo_label_string_test = unittest.make(
_apparent_repo_label_string_test,
)

# buildifier: disable=unnamed-macro
def modules_test_suite():
"""Creates the tests for modules.bzl if Bzlmod is enabled."""

unittest.suite(
"modules_tests",
apparent_repo_name_test,
apparent_repo_label_string_test,
)

if not _is_bzlmod_enabled:
Expand Down

0 comments on commit b5f6722

Please sign in to comment.