diff --git a/changelog/21.bugfix.rst b/changelog/21.bugfix.rst new file mode 100644 index 0000000..7afdbf1 --- /dev/null +++ b/changelog/21.bugfix.rst @@ -0,0 +1 @@ +Fix opening towncrier templates. diff --git a/sphinx_changelog/directive.py b/sphinx_changelog/directive.py index 4294f2e..adf1118 100644 --- a/sphinx_changelog/directive.py +++ b/sphinx_changelog/directive.py @@ -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): diff --git a/sphinx_changelog/towncrier.py b/sphinx_changelog/towncrier.py index 4e9dc96..6ad4b92 100644 --- a/sphinx_changelog/towncrier.py +++ b/sphinx_changelog/towncrier.py @@ -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 @@ -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")