Modules
This page documents importable modules and their contents.
pretty_toml_sort.tomlsort
Utility functions and classes to sort toml text.
- class pretty_toml_sort.tomlsort.TomlSort(input_toml: str, comment_config: Optional[pretty_toml_sort.tomlsort.CommentConfiguration] = None, sort_config: Optional[pretty_toml_sort.tomlsort.SortConfiguration] = None, format_config: Optional[pretty_toml_sort.tomlsort.FormattingConfiguration] = None, sort_config_overrides: Optional[Dict[str, pretty_toml_sort.tomlsort.SortOverrideConfiguration]] = None)
API to manage sorting toml files.
- aot_to_tomlsortitem(comments: List[tomlkit.items.Comment], keys: pretty_toml_sort.tomlsort.TomlSortKeys, value: tomlkit.items.AoT) Tuple[List[tomlkit.items.Comment], pretty_toml_sort.tomlsort.TomlSortItem]
Turn an AoT into a TomlSortItem, recursing down through its collections and attaching all the comments to the correct items.
- array_sort_func(value: Tuple[tomlkit.items._ArrayItemGroup, Any]) str
Sort function that operates on the .value member of an ArrayItemGroup respects the class setting for ignore_case.
- body_to_tomlsortitems(parent: List[Tuple[Optional[tomlkit.items.Key], tomlkit.items.Item]], parent_key: Optional[pretty_toml_sort.tomlsort.TomlSortKeys] = None) Tuple[List[pretty_toml_sort.tomlsort.TomlSortItem], List[tomlkit.items.Comment]]
Iterate over Container.body, recursing down into sub-containers attaching the comments that are found to the correct TomlSortItem. We need to do this iteration because TomlKit puts comments into end of the collection they appear in, instead of the start of the next collection.
For example
TomlKit would place the comment from the example into the [xyz] collection, when we would like it to be attached to the [abc] collection.
So before sorting we have to iterate over the container, correctly attaching the comments, then undo this process once everything is sorted.
- static format_key(key: tomlkit.items.Key) tomlkit.items.Key
Format a key, removing any extra whitespace, and making sure that it will be formatted like: key = value with one space on either side of the equal sign.
- key_sort_func(value: pretty_toml_sort.tomlsort.TomlSortItem) str
Sort function that looks at TomlSortItems keys, respecting the configured value for ignore_case.
- sort_array(keys: pretty_toml_sort.tomlsort.TomlSortKeys, array: tomlkit.items.Array, indent_depth: int = 0) tomlkit.items.Array
Sort and format an inline array item while preserving comments.
- sort_config(keys: Optional[pretty_toml_sort.tomlsort.TomlSortKeys] = None) pretty_toml_sort.tomlsort.SortConfiguration
Returns the SortConfiguration to use for particular TomlSortKeys.
This merges the global SortConfiguration with any matching SortOverrideConfiguration to give the full SortConfiguration that applies to this Key.
- sort_inline_table(keys: pretty_toml_sort.tomlsort.TomlSortKeys, item: tomlkit.items.Item, indent_depth: int = 0) tomlkit.items.InlineTable
Sort an inline table, recursing into its items.
- sort_item(keys: pretty_toml_sort.tomlsort.TomlSortKeys, item: tomlkit.items.Item, indent_depth: int = 0) tomlkit.items.Item
Sort an item, recursing down if the item is an inline table or array.
- sort_items(items: Iterable[pretty_toml_sort.tomlsort.TomlSortItem]) Iterable[pretty_toml_sort.tomlsort.TomlSortItem]
Sort an iterable full of TomlSortItem, making sure the key is correctly formatted and recursing into any sub-items.
- sort_keys(items: Iterable[pretty_toml_sort.tomlsort.TomlSortItem], sort_config: pretty_toml_sort.tomlsort.SortConfiguration) List[pretty_toml_sort.tomlsort.TomlSortItem]
Sorts Iterable of Tomlsort item based on keys.
The sort respects the sort_config.first setting which allows overriding the sorted order of keys.
- sorted() str
Sort a TOML string.
- sorted_children_table(parent_keys: Optional[pretty_toml_sort.tomlsort.TomlSortKeys], parent: List[pretty_toml_sort.tomlsort.TomlSortItem]) Iterable[pretty_toml_sort.tomlsort.TomlSortItem]
Get the sorted children of a table.
- static table_previous_item(parent_table, grandparent)
Finds the previous item that we should attach a comment to, in the case where the previous item is a table.
This take into account that a table may be a super table.
- table_to_tomlsortitem(comments: List[tomlkit.items.Comment], keys: pretty_toml_sort.tomlsort.TomlSortKeys, value: tomlkit.items.Table) Tuple[List[tomlkit.items.Comment], pretty_toml_sort.tomlsort.TomlSortItem]
Turn a table into a TomlSortItem, recursing down through its collections and attaching all the comments to the correct items.
- toml_doc_sorted(original: tomlkit.toml_document.TOMLDocument) tomlkit.toml_document.TOMLDocument
Sort a TOMLDocument.
- toml_elements_sorted(original: pretty_toml_sort.tomlsort.TomlSortItem, parent: tomlkit.items.Table | tomlkit.toml_document.TOMLDocument) tomlkit.items.Item
Returns a sorted item, recursing collections to their base.
- write_header_comment(from_doc_body: List[Tuple[Optional[tomlkit.items.Key], tomlkit.items.Item]], to_doc: tomlkit.toml_document.TOMLDocument) List[Tuple[Optional[tomlkit.items.Key], tomlkit.items.Item]]
Write header comment from the FROM doc to the TO doc.
Only writes comments / whitespace from the beginning of a TOML document.