-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
39540d7
commit b4acccc
Showing
6 changed files
with
60 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,5 +6,5 @@ | |
/_build | ||
/dist | ||
/docs/_build | ||
CHANGELOG.md | ||
CHANGELOG.* | ||
__pycache__ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
========= | ||
Changelog | ||
========= | ||
|
||
.. osr:cz-changelog:: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -117,5 +117,6 @@ Specifications | |
console | ||
related-projects | ||
about | ||
changelog | ||
copyright | ||
indices |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
"""Commitizen Sphinx directives.""" | ||
|
||
from __future__ import annotations | ||
|
||
import subprocess | ||
|
||
from docutils import nodes | ||
from docutils.frontend import OptionParser | ||
from docutils.utils import new_document | ||
from sphinx.parsers import RSTParser | ||
from sphinx.util.docutils import SphinxDirective | ||
|
||
|
||
class CzChangelog(SphinxDirective): | ||
"""Commitizen changelog directive.""" | ||
|
||
has_content = False | ||
required_arguments = 0 | ||
optional_arguments = 0 | ||
|
||
def run(self) -> list[nodes.Node]: | ||
"""Run Commitizen changelog.""" | ||
changelog = self.get_changelog() | ||
|
||
return self.parse_rst(changelog) | ||
|
||
@staticmethod | ||
def get_changelog() -> str: | ||
"""Execute cz changelog and capture output.""" | ||
result = subprocess.run( | ||
["cz", "changelog", "--dry-run", "--file-name", "CHANGELOG.rst"], | ||
stdout=subprocess.PIPE, | ||
) | ||
|
||
return result.stdout.decode("utf-8") | ||
|
||
def parse_rst(self, text: str) -> list[nodes.Node]: | ||
"""Parse reStructuredText string.""" | ||
parser = RSTParser() | ||
parser.set_application(self.env.app) | ||
settings = OptionParser( | ||
defaults=self.env.settings, | ||
components=(RSTParser,), | ||
read_config_files=True, | ||
).get_default_values() | ||
|
||
document = new_document("<rst-doc>", settings=settings) | ||
parser.parse(text, document) | ||
|
||
return document.children |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters