Skip to content

Commit

Permalink
Fix template bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Cadair committed Aug 2, 2023
1 parent 905e311 commit ce09dbc
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
1 change: 1 addition & 0 deletions changelog/21.bugfix.rst
@@ -0,0 +1 @@
Fix opening towncrier templates.
7 changes: 2 additions & 5 deletions sphinx_changelog/directive.py
Expand Up @@ -49,11 +49,8 @@ def render_towncrier(self):
config_path = self.options.get("towncrier") or "../"
config_path = self.get_absolute_path(config_path)
skip_if_empty = "towncrier-skip-if-empty" in self.options
try:
changelog = generate_changelog_for_docs(config_path, skip_if_empty=skip_if_empty,
underline=self.options.get('towncrier-title-underline-index', 0))
except Exception as exc:
raise self.severe(str(exc))
changelog = generate_changelog_for_docs(config_path, skip_if_empty=skip_if_empty,
underline=self.options.get('towncrier-title-underline-index', 0))
return statemachine.string2lines(changelog, convert_whitespace=True)

def include_changelog(self):
Expand Down
15 changes: 10 additions & 5 deletions sphinx_changelog/towncrier.py
Expand Up @@ -6,9 +6,14 @@
licenses/TOWNCRIER.rst
"""
import os
import sys
from datetime import date

import pkg_resources
if sys.version_info < (3, 10):
import importlib_resources as resources
else:
from importlib import resources

from towncrier._builder import (find_fragments, render_fragments,
split_fragments)
from towncrier._project import get_project_name, get_version
Expand Down Expand Up @@ -40,10 +45,10 @@ def generate_changelog_for_docs(directory, skip_if_empty=True, underline=1):
os.chdir(base_directory)

print("Loading template...")
if config.template is None:
template = pkg_resources.resource_string(
"towncrier", "templates/default.rst"
).decode("utf8")
if isinstance(config.template, tuple):
template = (
resources.files(config.template[0]).joinpath(config.template[1]).read_text()
)
else:
with open(config.template, "rb") as tmpl:
template = tmpl.read().decode("utf8")
Expand Down

0 comments on commit ce09dbc

Please sign in to comment.