Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Default markdown template #483

Merged
merged 38 commits into from
May 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
aee6fd2
Add default markdown template
SmileyChris Feb 22, 2023
cc27dea
Update tutorial.rst to mention markdown
SmileyChris Feb 22, 2023
c952d17
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Mar 1, 2023
94d8a26
Typing fixes, fix template issue, full test coverage
SmileyChris Mar 21, 2023
d2bb513
Add newsfragment
SmileyChris Mar 21, 2023
63b6257
Merge branch 'trunk' into feature/default-markdown-template
hynek Apr 4, 2023
c7cd296
Apply suggestions from code review
SmileyChris Apr 14, 2023
9edaf7b
Update docs/tutorial.rst
SmileyChris Apr 27, 2023
09b68f0
Update docs/configuration.rst
SmileyChris Apr 27, 2023
6d97f57
towncrier doesn't use .rst extensions for fragments
SmileyChris Apr 27, 2023
744387e
Applying suggested changes
SmileyChris Apr 27, 2023
1aaea1b
"Version" doc improvements
SmileyChris Apr 27, 2023
1b22755
Another change for consistency in docs
SmileyChris Apr 27, 2023
a9e07fa
Remove ordereddict and redundant os.mkdirs
SmileyChris Apr 27, 2023
89b72fd
Make Config.underlines a tuple by default
SmileyChris Apr 27, 2023
7740059
Fix what Github suggestions messed up
SmileyChris Apr 27, 2023
be669c0
Fix dicts that were OrderedDicts
SmileyChris May 1, 2023
d2676a9
Fix documentation link
SmileyChris May 1, 2023
438636a
Re-add the required os.mkdirs and abstract the common use case in tes…
SmileyChris May 1, 2023
d1d30b2
Merge remote-tracking branch 'upstream/trunk' into feature/default-ma…
SmileyChris May 2, 2023
64ac558
Use Python 3.10 compatible importlib_resources
SmileyChris May 2, 2023
07dab17
Fix markdown in fragment
SmileyChris May 2, 2023
7df907c
Fix comment to show what fragments actually returns now
SmileyChris May 2, 2023
cfe0595
Importlib test helper can keep using builtin
SmileyChris May 2, 2023
ed62910
Revert to old template open method to try and fix a windows error
SmileyChris May 2, 2023
8d429ac
Make ruff's sort work the same as actual isort
SmileyChris May 2, 2023
bb3c6b7
Make config.template use a tuple instead of a string if it's a resour…
SmileyChris May 2, 2023
c517e65
Improve docs for directory configuration key
SmileyChris May 3, 2023
8c4ebea
Document template configuration key
SmileyChris May 3, 2023
a6afc70
Change default start_string configuration when using markdown
SmileyChris May 3, 2023
d50a2d7
Merge commit '622ba4f8806531cb69ac0fb5364cecd69a5752dc' into feature/…
SmileyChris May 3, 2023
ea3aa66
Change newsfile docs to use `code-block`s
SmileyChris May 4, 2023
7e27001
Use helpers read/write for new tests
SmileyChris May 4, 2023
e0af6bf
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] May 4, 2023
d479924
Better configuration doc formatting
SmileyChris May 4, 2023
fb9f6cc
Document Section Path Behaviour
SmileyChris May 4, 2023
446a723
Improve configuration docs re: python projects
SmileyChris May 4, 2023
4fd6453
Fix test that was altered to use dedent
SmileyChris May 4, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
277 changes: 197 additions & 80 deletions docs/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,57 +2,206 @@ Configuration Reference
=======================

``towncrier`` has many knobs and switches you can use, to customize it to your project's needs.
The setup in the `Tutorial <tutorial.html>`_ doesn't touch on many, but this document will detail each of these options for you!
The setup in the :doc:`tutorial` doesn't touch on many, but this document will detail each of these options for you!

For how to perform common customization tasks, see `Customization <customization/index.html>`_.
For how to perform common customization tasks, see :doc:`customization/index`.

``[tool.towncrier]``
--------------------

All configuration for ``towncrier`` sits inside ``pyproject.toml``, under the ``tool.towncrier`` namespace.
All configuration for ``towncrier`` sits inside ``towncrier.toml`` or ``pyproject.toml``, under the ``tool.towncrier`` namespace.
Please see https://toml.io/ for how to write TOML.

A minimal configuration for a Python project looks like this:

.. code-block:: toml

# pyproject.toml

[tool.towncrier]
package = "myproject"

A minimal configuration for a non-Python project looks like this:

.. code-block:: toml

# towncrier.toml

[tool.towncrier]
name = "My Project"

Top level keys
~~~~~~~~~~~~~~

- ``directory`` -- If you are not storing your news fragments in your Python package, or aren't using Python, this is the path to where your newsfragments will be put.
- ``filename`` -- The filename of your news file.
``NEWS.rst`` by default.
- ``package`` -- The package name of your project.
(Python projects only)
- ``package_dir`` -- The folder your package lives. ``./`` by default, some projects might need to use ``src``.
(Python projects only)
- ``template`` -- Path to an alternate template for generating the news file, if you have one.
- ``start_string`` -- The magic string that ``towncrier`` looks for when considering where the release notes should start.
``.. towncrier release notes start`` by default.
- ``title_format`` -- A format string for the title of your project.
``{name} {version} ({project_date})`` by default.
- ``issue_format`` -- A format string for rendering the issue/ticket number in newsfiles.
``#{issue}`` by default.
- ``underlines`` -- The characters used for underlining headers.
``["=", "-", "~"]`` by default.
``name``
The name of your project.

For Python projects that provide a ``package`` key, if left empty then the name will be automatically determined.

``""`` by default.

``version``
The version of your project.

Python projects that provide the ``package`` key can have the version to be automatically determined from a ``__version__`` variable in the package's module.

If not provided or able to be determined, the version must be passed explicitly by the command line argument ``--version``.

``directory``
The directory storing your news fragments.

For Python projects that provide a ``package`` key, the default is a ``newsfragments`` directory within the package.
Otherwise the default is a ``newsfragments`` directory relative to the configuration file.

``filename``
The filename of your news file.

``"NEWS.rst"`` by default.

``template``
Path to the template for generating the news file.

If the path looks like ``<some.package>:<filename.ext>``, it is interpreted as a template bundled with an installed Python package.

``"towncrier:default.rst"`` by default unless ``filename`` ends with ``.md``, in which case the default is ``"towncrier:default.md"``.

``start_string``
The magic string that ``towncrier`` looks for when considering where the release notes should start.

``".. towncrier release notes start\n"`` by default unless ``filename`` ends with ``.md``, in which case the default is ``"<!-- towncrier release notes start -->\n"``.

``title_format``
A format string for the title of your project.

The explicit value of ``False`` will disable the title entirely.
Any other empty value means the template should render the title (the bundled templates use ``<name> <version> (<date>)``).
Strings should use the following keys to render the title dynamically: ``{name}``, ``{version}``, and ``{project_date}``.

``""`` by default.

``issue_format``
A format string for rendering the issue/ticket number in newsfiles.

If none, the issues are rendered as ``#<issue>`` if for issues that are integers, or just ``<issue>`` otherwise.
Use the ``{issue}`` key in your string render the issue number, for example Markdown projects may want to use ``"[{issue}]: https://<your bug tracker>/{issue}"``.

``None`` by default.

``underlines``
The characters used for underlining headers.

Not used in the bundled Markdown template.

``["=", "-", "~"]`` by default.

``wrap``
Boolean value indicating whether to wrap news fragments to a line length of 79.

``false`` by default.

``all_bullets``
Boolean value indicating whether the template uses bullets for each news fragment.

``true`` by default.

``single_file``
Boolean value indicating whether to write all news fragments to a single file.

If ``false``, the ``filename`` should use the following keys to render the filenames dynamically:
``{name}``, ``{version}``, and ``{project_date}``.

``true`` by default.

``orphan_prefix``
The prefix used for orphaned news fragments.

``"+"`` by default.

Extra top level keys for Python projects
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

``package``
The Python package name of your project.

Allows ``name`` and ``version`` to be automatically determined from the Python package.
Changes the default ``directory`` to be a ``newsfragments`` directory within this package.

``package_dir``
The folder your package lives.

``"."`` by default, some projects might need to use ``"src"``.


Sections
--------

``towncrier`` supports splitting fragments into multiple sections, each with its own news of fragment types.

Add an array of tables your ``.toml`` configuration file named ``[[tool.towncrier.section]]``.

Each table within this array has the following mandatory keys:


``name``
The name of the section.

``path``
The path to the directory containing the news fragments for this section, relative to the configured ``directory``.
Use ``""`` for the root directory.

For example:

.. code-block:: toml

[[tool.towncrier.section]]
name = "Main Platform"
path = ""

[[tool.towncrier.section]]
name = "Secondary"
path = "secondary"

Section Path Behaviour
~~~~~~~~~~~~~~~~~~~~~~

The path behaviour is slightly different depending on whether ``directory`` is explicitly set.

If ``directory`` is not set, "newsfragments" is added to the end of each path. For example, with the above sections, the paths would be:

:Main Platform: ./newsfragments
:Secondary: ./secondary/newsfragments

If ``directory`` *is* set, the section paths are appended to this path. For example, with ``directory = "changes"`` and the above sections, the paths would be:

:Main Platform: ./changes
:Secondary: ./changes/secondary


Custom fragment types
---------------------
``towncrier`` allows defining custom fragment types.
Custom fragment types will be used instead ``towncrier`` default ones, they are not combined.

There are two ways to add custom fragment types.
``towncrier`` has the following default fragment types: ``feature``, ``bugfix``, ``doc``, ``removal``, and ``misc``.

You can use either of the two following method to define custom types instead (you will need to redefine any of the default types you want to use).


Defining Custom Fragment Types With a TOML Mapping
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Use TOML tables (alphabetical order)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Users can configure each of their own custom fragment types by adding tables to
the pyproject.toml named ``[tool.towncrier.fragment.<a custom fragment type>]``.
Adding tables to your ``.toml`` configuration file named ``[tool.towncrier.fragment.<a custom fragment type>]``.

These tables may include the following optional keys:
These may include the following optional keys:

* ``name``: The description of the fragment type, as it must be included in the news file.
If omitted, it defaults to its fragment type, but capitalized.
* ``showcontent``: Whether if the fragment contents should be included in the news file. If omitted, it defaults to ``true``

``name``
The description of the fragment type, as it must be included in the news file.

Defaults to its fragment type, but capitalized.

``showcontent``
A boolean value indicating whether the fragment contents should be included in the news file.

``true`` by default.

For example, if you want your custom fragment types to be ``["feat", "fix", "chore",]`` and you want all of them to use the default configuration except ``"chore"`` you can do it as follows:

Expand All @@ -70,25 +219,30 @@ For example, if you want your custom fragment types to be ``["feat", "fix", "cho

.. warning::

Since TOML mappings aren't ordered, the sections are always rendered alphabetically.
Since TOML mappings aren't ordered, types defined using this method are always rendered alphabetically.


Use a TOML Array (defined order)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Defining Custom Fragment Types With an Array of TOML Tables
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Add an array of tables to your ``.toml`` configuration file named ``[[tool.towncrier.type]]``.

Users can create their own custom fragment types by adding an array of
tables to the pyproject.toml named ``[[tool.towncrier.type]]``.
If you use this way to configure custom fragment types, ensure there is no ``tool.towncrier.fragment`` table.

If you use this way to configure custom fragment types, please note that ``fragment_types`` must be empty or not provided.
Each table within this array has the following mandatory keys:

Each custom type (``[[tool.towncrier.type]]``) has the following
mandatory keys:

* ``directory``: The type / category of the fragment.
* ``name``: The description of the fragment type, as it must be included
in the news file.
* ``showcontent``: Whether if the fragment contents should be included in the
news file.
``directory``
The type / category of the fragment.

``name``
The description of the fragment type, as it must be included
in the news file.

``showcontent``
A boolean value indicating whether the fragment contents should be included in the news file.

``true`` by default.

For example:

Expand All @@ -104,40 +258,3 @@ For example:
directory = "chore"
name = "Other Tasks"
showcontent = false


All Options
-----------

``towncrier`` has the following global options, which can be specified in the toml file:

.. code-block:: toml

[tool.towncrier]
package = ""
package_dir = "."
single_file = true # if false, filename is formatted like `title_format`.
filename = "NEWS.rst"
directory = "directory/of/news/fragments"
version = "1.2.3" # project version if maintained separately
name = "arbitrary project name"
template = "path/to/template.rst"
start_string = "Text used to detect where to add the generated content in the middle of a file. Generated content added after this text. Newline auto added."
title_format = "{name} {version} ({project_date})" # or false if template includes title
issue_format = "format string for {issue} (issue is the first part of fragment name)"
underlines = "=-~"
wrap = false # Wrap text to 79 characters
all_bullets = true # make all fragments bullet points
orphan_prefix = "+" # Prefix for orphan news fragment files, set to "" to disable.

If ``single_file`` is set to ``true`` or unspecified, all changes will be written to a single fixed newsfile, whose name is literally fixed as the ``filename`` option.
In each run of ``towncrier build``, content of new changes will append at the top of old content, and after ``start_string`` if the ``start_string`` already appears in the newsfile.
If the corresponding ``top_line``, which is formatted as the option 'title_format', already exists in newsfile, ``ValueError`` will be raised to remind you "already produced newsfiles for this version".

If ``single_file`` is set to ``false`` instead, each versioned ``towncrier build`` will generate a separate newsfile, whose name is formatted as the pattern given by option ``filename``.
For example, if ``filename="{version}-notes.rst"``, then the release note with version "7.8.9" will be written to the file "7.8.9-notes.rst".
If the newsfile already exists, its content will be overwritten with new release note, without throwing a ``ValueError`` warning.

If ``title_format`` is unspecified or an empty string, the default format will be used.
If set to ``false``, no title will be created.
This can be useful if the specified template creates the title itself.
35 changes: 24 additions & 11 deletions docs/customization/newsfile.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,36 @@ Adding Content Above ``towncrier``
----------------------------------

If you wish to have content at the top of the news file (for example, to say where you can find the tickets), you can use a special rST comment to tell ``towncrier`` to only update after it.
In your existing news file (e.g. ``NEWS.rst``), add the following line above where you want ``towncrier`` to put content::
In your existing news file (e.g. ``NEWS.rst``), add the following line above where you want ``towncrier`` to put content:

.. towncrier release notes start
.. code-block:: restructuredtext

In an existing news file, it'll look something like this::
.. towncrier release notes start

This is the changelog of my project. You can find the
issue tracker at http://blah.
In an existing news file, it'll look something like this:

.. towncrier release notes start
.. code-block:: restructuredtext

myproject 1.0.2 (2018-01-01)
============================
This is the changelog of my project. You can find the
issue tracker at http://blah.

Bugfixes
--------
.. towncrier release notes start

- Fixed, etc...
myproject 1.0.2 (2018-01-01)
============================

Bugfixes
--------

- Fixed, etc...

``towncrier`` will not alter content above the comment.

Markdown
~~~~~~~~

If your news file is in Markdown (e.g. ``NEWS.md``), use the following comment instead:

.. code-block:: html

<!-- towncrier release notes start -->
6 changes: 5 additions & 1 deletion docs/tutorial.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Tutorial
========

This tutorial assumes you have a Python project with a *reStructuredText* (rst) news file (also known as changelog) file that you wish to use ``towncrier`` on, to generate its news file.
This tutorial assumes you have a Python project with a *reStructuredText* (rst) or *Markdown* (md) news file (also known as changelog) that you wish to use ``towncrier`` on, to generate its news file.
It will cover setting up your project with a basic configuration, which you can then feel free to `customize <customization/index.html>`_.

Install from PyPI::
Expand Down Expand Up @@ -144,6 +144,8 @@ You should get an output similar to this::

- #1, #2

Note: if you configure a Markdown file (for example, ``filename = "CHANGES.md"``) in your configuration file, the titles will be output in Markdown format instead.


Producing News Files In Production
----------------------------------
Expand All @@ -161,6 +163,8 @@ If you wish to have content at the top of the news file (for example, to say whe

``towncrier`` will then put the version notes after this comment, and leave your existing content that was above it where it is.

Note: if you configure a Markdown file (for example, ``filename = "CHANGES.md"``) in your configuration file, the comment should be ``<!-- towncrier release notes start -->`` instead.


Finale
------
Expand Down
Loading
Loading