def METHOD_NAME(ctx):
    if ctx.label.workspace_root:
        # We need the workspace_name for the target being visited.
        # Starlark doesn't have this - instead they have a workspace_root
        # which looks like "external/repo_name" - so grab the second path segment.
        return ctx.label.workspace_root.split("/")[1]
    else:
        return ctx.workspace_name