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

Integrate towncrier changelog draft sphinx ext #1640

Conversation

webknjaz
Copy link
Contributor

This change vendors the sphinx extension from https://github.com/ansible/pylibssh/blob/8b21ad7/docs/_ext/towncrier_draft_ext.py replacing the conf.py hack. Closes #1639.

Contribution checklist:

(also see CONTRIBUTING.rst for details)

  • wrote descriptive pull request text
  • added/updated test(s)
  • updated/extended the documentation
  • added relevant issue keyword
    in message body
  • added news fragment in changelog folder
    • fragment name: <issue number>.<type>.rst for example (588.bugfix.rst)
    • <type> is must be one of bugfix, feature, deprecation,breaking, doc, misc
    • if PR has no issue: consider creating one first or change it to the PR number after creating the PR
    • "sign" fragment with "by :user:<your username>"
    • please use full sentences with correct case and punctuation, for example: "Fix issue with non-ascii contents in doctest text files - by :user:superuser."
    • also see examples
  • added yourself to CONTRIBUTORS (preserving alphabetical order)

@webknjaz
Copy link
Contributor Author

(no change note because it's not public-facing)

@webknjaz
Copy link
Contributor Author

@webknjaz webknjaz force-pushed the docs/towncrier-changelog-draft-sphinx-ext branch from 204fcec to 4664a30 Compare July 31, 2020 23:04
Comment on lines -27 to -32
for pattern, replacement in (
(r"[^`]@([^,\s]+)", r"`@\1 <{}/\1>`_".format(home)),
(r"[^`]#([\d]+)", r"`#pr\1 <{}/\1>`_".format(issue)),
):
for path in fragments_path.glob("*.rst"):
path.write_text(re.sub(pattern, replacement, path.read_text()))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gaborbernat is this really necessary?

if "No significant changes" in changelog:
content = ""
else:
note = "*Changes in master, but not released yet are under the draft section*."
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gaborbernat the only difference is that the extension does not implement this (I simply missed it). Is it vital if this line is missing?

This change implements injecting the Towncrier draft change notes
RST output into the Sphinx-managed docs site.

It is heavily inspired by the work of @gaborbernat in tox and
reinvented as a native Sphinx extension.
Refs:
* tox-dev#859
* ansible/pylibssh@f5f9ef1

In internally generates an unreleased changelog for the next
unpublished project version (by calling `towncrier` in a subprocess)
and provides it for injection as an RST directive
called "towncrier-draft-entries".

To start using it, first, add it to extensions in `conf.py`:

    extensions.append('towncrier_draft_ext')

Then, optionally, set the global extensions options:

    towncrier_draft_autoversion_mode = 'scm-draft'  # or: 'scm', 'draft', 'sphinx-version', 'sphinx-release'
    towncrier_draft_include_empty = True
    towncrier_draft_working_directory = PROJECT_ROOT_DIR
    towncrier_draft_config_path = 'pyproject.toml'  # relative to cwd

Their meaning is as follows:

    * towncrier_draft_autoversion_mode -- mechanism for the fallback
      version detection. It kicks in if, when using the directive, you
      don't specify the version argument and then will be passed to the
      `towncrier` invocation.

      Possible values are:

          * 'scm-draft' -- default, use setuptools-scm followed by a
            string "[UNRELEASED DRAFT]"
          * 'scm' -- use setuptools-scm
          * 'draft' -- use just a string "[UNRELEASED DRAFT]"
          * 'sphinx-version' -- use value of the "version" var in
            as set in `conf.py`
          * 'sphinx-release' -- use value of the "release" var in
            as set in `conf.py`

    * towncrier_draft_include_empty -- control whether the directive
      injects anything if there's no fragments in the repo. Boolean,
      defaults to `True`.

    * towncrier_draft_working_directory -- if set, this will be the
      current working directory of the `towncrier` invocation.

    * towncrier_draft_config_path -- path of the custom config to use
      for the invocation. Should be relative to the working directory.
      Not yet supported: the corresponding Towncrier CLI option is in
      their master but is not yet released. Don't use it unless you
      install a bleading-edge towncrier copy (or they make a release).

Finally, use the directive in your RST source as follows:

    .. towncrier-draft-entries:: |release| [UNRELEASED DRAFT]

The inline argument of the directive is what is passed to towncrier as
a target version. It is optional and if not set, the fallback from the
global config will be used.

Pro tip: you can use RST substitutions like `|release|` or `|version|`
in order to match the version with what's set in Sphinx and other
release-related configs.

src:
https://github.com/ansible/pylibssh/blob/8b21ad7/docs/_ext/towncrier_draft_ext.py

Resolves tox-dev#1639
@webknjaz webknjaz force-pushed the docs/towncrier-changelog-draft-sphinx-ext branch from 4664a30 to 95eea48 Compare July 31, 2020 23:07
Copy link
Member

@gaborbernat gaborbernat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry I don't want to vendor anything in my projects. I thought we'll release this as a separate package on pypi and refer to it as dependency.

@@ -7,7 +7,7 @@ Versions follow `Semantic Versioning <https://semver.org/>`_ (``<major>.<minor>.
Backward incompatible (breaking) changes will only be introduced in major versions
with advance notice in the **Deprecations** section of releases.

.. include:: _draft.rst
.. towncrier-draft-entries:: DRAFT
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gaborbernat DRAFT here is a string argument that is passed to towncrier --draft --version '{THIS VALUE}'. It can be anything. For example, it could be |release| (EXPLANATION THAT IT'S A DRAFT) and then it'd be rendered like 3.88.99 (EXPLANATION THAT IT'S A DRAFT).

I tried to keep the behavior as it is now but you have options FYI.

@gaborbernat gaborbernat closed this Aug 1, 2020
@webknjaz
Copy link
Contributor Author

webknjaz commented Aug 1, 2020

Ah, okay. Release will take a while. But at least you could preview it and see if anything is missing.

@gaborbernat
Copy link
Member

@webknjaz When you make the first PR for the release just tag me to review 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

docs refactoring: towncrier draft + sphinx as an ext
2 participants