fix: Avoid else after return in mappings bzl (#923)
diff --git a/pkg/mappings.bzl b/pkg/mappings.bzl index 789c00f..9e7653a 100644 --- a/pkg/mappings.bzl +++ b/pkg/mappings.bzl
@@ -31,7 +31,7 @@ load("//pkg:providers.bzl", "PackageDirsInfo", "PackageFilegroupInfo", "PackageFilesInfo", "PackageSymlinkInfo") load("//pkg/private:util.bzl", "get_repo_mapping_manifest") -# TODO(#333): strip_prefix module functions should produce unique outputs. In +# TODO(#333): strip_prefix module functions should produce unique outputs. In # particular, this one and `_sp_from_pkg` can overlap. _PKGFILEGROUP_STRIP_ALL = "." @@ -43,14 +43,12 @@ def _sp_from_pkg(path = ""): if path.startswith("/"): return path[1:] - else: - return path + return path def _sp_from_root(path = ""): if path.startswith("/"): return path - else: - return "/" + path + return "/" + path strip_prefix = struct( _doc = """pkg_files `strip_prefix` helper. Instructs `pkg_files` what to do with directory prefixes of files. @@ -148,21 +146,20 @@ if path_norm.startswith(to_strip_norm): return path_norm[len(to_strip_norm):] - elif src_file.is_directory and (path_norm + "/") == to_strip_norm: + if src_file.is_directory and (path_norm + "/") == to_strip_norm: return "" - else: - # Avoid user surprise by failing if prefix stripping doesn't work as - # expected. - # - # We already leave enough breadcrumbs, so if File.owner() returns None, - # this won't be a problem. - failmsg = "Could not strip prefix '{}' from file {} ({})".format(to_strip, str(src_file), str(src_file.owner)) - if src_file.is_directory: - failmsg += """\n\nNOTE: prefix stripping does not operate within TreeArtifacts (directory outputs) + + # Avoid user surprise by failing if prefix stripping doesn't work as expected. + # + # We already leave enough breadcrumbs, so if File.owner() returns None, + # this won't be a problem. + failmsg = "Could not strip prefix '{}' from file {} ({})".format(to_strip, str(src_file), str(src_file.owner)) + if src_file.is_directory: + failmsg += """\n\nNOTE: prefix stripping does not operate within TreeArtifacts (directory outputs) To strip the directory named by the TreeArtifact itself, see documentation for the `renames` attribute. """ - fail(failmsg) + fail(failmsg) # The below routines make use of some path checking magic that may difficult to # understand out of the box. This following table may be helpful to demonstrate @@ -189,8 +186,7 @@ # File.owner returns a Label structure if file.owner == None: fail("File {} ({}) has no owner attribute; cannot continue".format(file, file.path)) - else: - return file.owner + return file.owner def _relative_workspace_root(label): # Helper function that returns the workspace root relative to the bazel File @@ -219,7 +215,7 @@ ) def _pkg_files_impl(ctx): - # The input sources are already known. Let's calculate the destinations... + # The input sources are already known. Let's calculate the destinations... # Exclude excludes srcs = [] # srcs is source File objects, not Targets @@ -263,7 +259,7 @@ # rename_src.files is a depset rename_src_files = rename_src.files.to_list() - # Need to do a length check before proceeding. We cannot rename + # Need to do a length check before proceeding. We cannot rename # multiple files simultaneously. if len(rename_src_files) != 1: fail(