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

Fix template bug #21

Merged
merged 2 commits into from
Aug 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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