From b5f6722ac69ec30f7fbaaa08126d3b4b0e92cf57 Mon Sep 17 00:00:00 2001 From: Mike Bland Date: Tue, 15 Oct 2024 12:18:58 -0400 Subject: [PATCH] Remove `modules.apparent_repo_label_string` 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. --- docs/modules_doc.md | 23 ------------------- lib/modules.bzl | 18 --------------- tests/modules_test.bzl | 50 ------------------------------------------ 3 files changed, 91 deletions(-) diff --git a/docs/modules_doc.md b/docs/modules_doc.md index 9cf61073..6a995706 100755 --- a/docs/modules_doc.md +++ b/docs/modules_doc.md @@ -2,29 +2,6 @@ Skylib module containing utilities for Bazel modules and module extensions. - - -## modules.apparent_repo_label_string - -
-modules.apparent_repo_label_string(label)
-
- -Return a Label string starting with its apparent repo name. - -**PARAMETERS** - - -| Name | Description | Default Value | -| :------------- | :------------- | :------------- | -| label | a Label instance | none | - -**RETURNS** - -str(label) with its canonical repository name replaced with its apparent - repository name - - ## modules.apparent_repo_name diff --git a/lib/modules.bzl b/lib/modules.bzl index f8b8f146..3ae708bb 100644 --- a/lib/modules.bzl +++ b/lib/modules.bzl @@ -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, ) diff --git a/tests/modules_test.bzl b/tests/modules_test.bzl index 193aa06f..a9ba0797 100644 --- a/tests/modules_test.bzl +++ b/tests/modules_test.bzl @@ -143,55 +143,6 @@ 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.""" @@ -199,7 +150,6 @@ def modules_test_suite(): unittest.suite( "modules_tests", apparent_repo_name_test, - apparent_repo_label_string_test, ) if not _is_bzlmod_enabled: