Skip to content

Need a way to set the order of fragments #437

@hynek

Description

@hynek

The new way of defining custom fragments uses a dictionary that is unfortunately sorted alphabetically by tomli.

For example this is from my Markdown tutorial in #436:

{'tool': {'towncrier': {'directory': 'changelog.d',
                        'filename': 'CHANGELOG.md',
                        'fragment': {'added': {'name': 'Added'},
                                     'changed': {'name': 'Changed'},
                                     'deprecated': {'name': 'Deprecated'},
                                     'fixed': {'name': 'Fixed'},
                                     'removed': {'name': 'Removed'},
                                     'security': {'name': 'Security'}},
                        'issue_format': '[#{issue}](https://github.com/twisted/my-project/issues/{issue})',
                        'start_string': '<!-- towncrier release notes start '
                                        '-->\n',
                        'template': 'changelog.d/changelog_template.jinja',
                        'title_format': '## '
                                        '[{version}](https://github.com/twisted/my-project/tree/{version}) '
                                        '- {project_date}',
                        'underlines': ['', '', '']}}}

The fragment types are defined as:

[tool.towncrier.fragment.security]
name = "Security"

[tool.towncrier.fragment.removed]
name = "Removed"

[tool.towncrier.fragment.deprecated]
name = "Deprecated"

[tool.towncrier.fragment.added]
name = "Added"

[tool.towncrier.fragment.changed]
name = "Changed"

[tool.towncrier.fragment.fixed]
name = "Fixed"

In hindsight, it's unfortunate we've switched away from using a list for that but it is what it is.

I can think of two way to solve this:

  1. add an order key to the fragments:
[tool.towncrier.fragment.security]
name = "Security"
order = 1

[tool.towncrier.fragment.removed]
name = "Removed"
order = 2
  1. add an option:
[tool.towncrier]
category_order = ["security", "removed", "..."]

I think I prefer option 2, because you don't have to re-number all entries if you change the order.

The question is what would happen if a catefory is missing – I would suggest an error.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions