Skip to content

Commit

Permalink
👽 Normalize Towncrier config object as a dict
Browse files Browse the repository at this point in the history
This is a compatibility change needed for Towncrier >= 22.12.0rc1
after it changed the internal object to be a `dataclass`.

Refs:
* twisted/towncrier#429
* twisted/towncrier#461

Resolves #76.

Co-Authored-By: davfsa <davfsa@gmail.com>
Co-Authored-By: Sviatoslav Sydorenko <webknjaz@redhat.com>
  • Loading branch information
3 people committed Dec 22, 2022
1 parent 12362b5 commit 952ea8a
Showing 1 changed file with 16 additions and 1 deletion.
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)

0 comments on commit 952ea8a

Please sign in to comment.