Skip to content

Commit

Permalink
Merge PR #75 into master
Browse files Browse the repository at this point in the history
  • Loading branch information
webknjaz committed Dec 22, 2022
2 parents d120086 + 7cb2716 commit c8ea949
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
17 changes: 16 additions & 1 deletion src/sphinxcontrib/towncrier/_towncrier.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
"""Towncrier related shims."""

from contextlib import suppress as _suppress_exception
from pathlib import Path
from typing import Any, Dict


with _suppress_exception(ImportError):
# NOTE: This will not raise an exception under Python >= 3.7, and is only
# NOTE: needed for Towncrier >= 22.12.0rc1 which doesn't support Python 3.6
from dataclasses import asdict as _dataclass_to_dict # noqa: WPS433


try:
# Towncrier >= 22.8.0rc1
# pylint: disable=import-error,no-name-in-module
Expand All @@ -24,7 +31,15 @@ def get_towncrier_config(
"""Return the towncrier config dictionary."""
try:
# Towncrier >= 19.9.0
return load_config_from_file(str(project_path), str(final_config_path))
config = load_config_from_file(
str(project_path), str(final_config_path),
)
except TypeError:
# Towncrier < 19.9.0
return load_config_from_file(str(final_config_path))

if isinstance(config, dict):
# Towncrier < 22.12.0rc1
return config

return _dataclass_to_dict(config)
8 changes: 4 additions & 4 deletions src/sphinxcontrib/towncrier/ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,10 @@ def _lookup_towncrier_fragments( # noqa: WPS210
fragment_directory = None

_fragments, fragment_filenames = find_fragments(
base_directory=str(fragment_base_directory),
fragment_directory=fragment_directory,
definitions=towncrier_config['types'],
sections=towncrier_config['sections'],
str(fragment_base_directory),
towncrier_config['sections'],
fragment_directory,
towncrier_config['types'],
)
return set(fragment_filenames)

Expand Down

0 comments on commit c8ea949

Please sign in to comment.