Skip to content

Commit

Permalink
Fix template bug (#21)
Browse files Browse the repository at this point in the history
* Fix template bug

* Add importlib-resources backport
  • Loading branch information
Cadair authored Aug 2, 2023
1 parent 905e311 commit 58a3c5d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
1 change: 1 addition & 0 deletions changelog/21.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix opening towncrier templates.
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ setup_requires = setuptools_scm
install_requires =
sphinx
towncrier==23.6.0
importlib-resources>=5; python_version<'3.10'

[options.extras_require]
all =
Expand Down
15 changes: 10 additions & 5 deletions sphinx_changelog/towncrier.py
Original file line number Diff line number Diff line change
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 58a3c5d

Please sign in to comment.