MCPcopy Index your code
hub / github.com/pyinvoke/invoke / _make_pairs

Method _make_pairs

invoke/program.py:826–893  ·  view source on GitHub ↗
(
        self,
        coll: "Collection",
        ancestors: Optional[List[str]] = None,
    )

Source from the content-addressed store, hash-verified

824 self.display_with_columns(pairs=pairs, extra=extra)
825
826 def _make_pairs(
827 self,
828 coll: "Collection",
829 ancestors: Optional[List[str]] = None,
830 ) -> List[Tuple[str, Optional[str]]]:
831 if ancestors is None:
832 ancestors = []
833 pairs = []
834 indent = len(ancestors) * self.indent
835 ancestor_path = ".".join(x for x in ancestors)
836 for name, task in sorted(coll.tasks.items()):
837 is_default = name == coll.default
838 # Start with just the name and just the aliases, no prefixes or
839 # dots.
840 displayname = name
841 aliases = list(map(coll.transform, sorted(task.aliases)))
842 # If displaying a sub-collection (or if we are displaying a given
843 # namespace/root), tack on some dots to make it clear these names
844 # require dotted paths to invoke.
845 if ancestors or self.list_root:
846 displayname = ".{}".format(displayname)
847 aliases = [".{}".format(x) for x in aliases]
848 # Nested? Indent, and add asterisks to default-tasks.
849 if self.list_format == "nested":
850 prefix = indent
851 if is_default:
852 displayname += "*"
853 # Flat? Prefix names and aliases with ancestor names to get full
854 # dotted path; and give default-tasks their collection name as the
855 # first alias.
856 if self.list_format == "flat":
857 prefix = ancestor_path
858 # Make sure leading dots are present for subcollections if
859 # scoped display
860 if prefix and self.list_root:
861 prefix = "." + prefix
862 aliases = [prefix + alias for alias in aliases]
863 if is_default and ancestors:
864 aliases.insert(0, prefix)
865 # Generate full name and help columns and add to pairs.
866 alias_str = " ({})".format(", ".join(aliases)) if aliases else ""
867 full = prefix + displayname + alias_str
868 pairs.append((full, helpline(task)))
869 # Determine whether we're at max-depth or not
870 truncate = self.list_depth and (len(ancestors) + 1) >= self.list_depth
871 for name, subcoll in sorted(coll.collections.items()):
872 displayname = name
873 if ancestors or self.list_root:
874 displayname = ".{}".format(displayname)
875 if truncate:
876 tallies = [
877 "{} {}".format(len(getattr(subcoll, attr)), attr)
878 for attr in ("tasks", "collections")
879 if getattr(subcoll, attr)
880 ]
881 displayname += " [{}]".format(", ".join(tallies))
882 if self.list_format == "nested":
883 pairs.append((indent + displayname, helpline(subcoll)))

Callers 2

list_flatMethod · 0.95
list_nestedMethod · 0.95

Calls 2

joinMethod · 0.80
helplineFunction · 0.70

Tested by

no test coverage detected