| 1 |
"""Changelog fragment discovery helpers.""" |
| 2 |
|
| 3 |
|
| 4 |
from functoolsscip-python python python-stdlib 3.11 functools/__init__: import lru_cachescip-python python python-stdlib 3.11 functools/lru_cache(). |
| •5 |
from importlib.metadatascip-python python python-stdlib 3.11 `importlib.metadata`/__init__: import version |
| 6 |
from pathlibscip-python python python-stdlib 3.11 pathlib/__init__: import Pathscip-python python python-stdlib 3.11 pathlib/Path# |
| 7 |
from typingscip-python python python-stdlib 3.11 typing/__init__: import Optionalscip-python python python-stdlib 3.11 typing/Optional., Setscip-python python python-stdlib 3.11 typing/Set. |
| 8 |
|
| 9 |
from sphinx.utilscip-python python Sphinx 9.1.0 `sphinx.util`/__init__: import loggingscip-python python Sphinx 9.1.0 `sphinx.util.logging`/__init__: |
| 10 |
|
| •11 |
from packaging.versionscip-python python packaging 26.2 `packaging.version`/__init__: import Version |
| 12 |
|
| 13 |
|
| 14 |
try: |
| 15 |
# pylint: disable=no-name-in-module |
| 16 |
from towncrier.buildscip-python python towncrier 24.8.0 `towncrier.build`/__init__: import find_fragments # noqa: WPS433 |
| 17 |
except ImportErrorscip-python python python-stdlib 3.11 builtins/ImportError#: |
| 18 |
# pylint: disable=import-self,no-name-in-module |
| 19 |
from towncrierscip-python python towncrier 24.8.0 towncrier/__init__: import ( # type: ignore[attr-defined] # noqa: WPS433,WPS440 |
| 20 |
find_fragments, |
| 21 |
) |
| 22 |
|
| •23 |
from ._towncrierscip-python python sphinxcontrib-towncrier 0.4.0a0 _towncrier/__init__: import ( # noqa: WPS436 |
| 24 |
get_towncrier_configscip-python python sphinxcontrib-towncrier 0.4.0a0 `src.sphinxcontrib.towncrier._towncrier`/get_towncrier_config()., get_towncrier_config_as_dictscip-python python sphinxcontrib-towncrier 0.4.0a0 `src.sphinxcontrib.towncrier._towncrier`/get_towncrier_config_as_dict()., |
| 25 |
) |
| 26 |
|
| 27 |
|
| 28 |
loggerscip-python python sphinxcontrib-towncrier 0.4.0a0 `src.sphinxcontrib.towncrier._fragment_discovery`/logger. = loggingscip-python python Sphinx 9.1.0 `sphinx.util.logging`/__init__:.getLogger(__name__scip-python python sphinxcontrib-towncrier 0.4.0a0 `src.sphinxcontrib.towncrier._fragment_discovery`/) |
| 29 |
|
| 30 |
|
| 31 |
def _resolve_spec_configscip-python python sphinxcontrib-towncrier 0.4.0a0 `src.sphinxcontrib.towncrier._fragment_discovery`/_resolve_spec_config().( |
| 32 |
basescip-python python sphinxcontrib-towncrier 0.4.0a0 `src.sphinxcontrib.towncrier._fragment_discovery`/_resolve_spec_config().(base): Pathscip-python python python-stdlib 3.11 pathlib/Path#, spec_namescip-python python sphinxcontrib-towncrier 0.4.0a0 `src.sphinxcontrib.towncrier._fragment_discovery`/_resolve_spec_config().(spec_name): Optionalscip-python python python-stdlib 3.11 typing/Optional.[strscip-python python python-stdlib 3.11 builtins/str#] = None, |
| 33 |
) -> Optionalscip-python python python-stdlib 3.11 typing/Optional.[Pathscip-python python python-stdlib 3.11 pathlib/Path#]: |
| 34 |
return basescip-python python sphinxcontrib-towncrier 0.4.0a0 `src.sphinxcontrib.towncrier._fragment_discovery`/_resolve_spec_config().(base) / spec_namescip-python python sphinxcontrib-towncrier 0.4.0a0 `src.sphinxcontrib.towncrier._fragment_discovery`/_resolve_spec_config().(spec_name) if spec_namescip-python python sphinxcontrib-towncrier 0.4.0a0 `src.sphinxcontrib.towncrier._fragment_discovery`/_resolve_spec_config().(spec_name) is not None else None |
| 35 |
|
| 36 |
|
| 37 |
# pylint: disable=fixme |
| 38 |
# FIXME: consider consolidating this logic upstream in towncrier |
| 39 |
def _find_config_filescip-python python sphinxcontrib-towncrier 0.4.0a0 `src.sphinxcontrib.towncrier._fragment_discovery`/_find_config_file().(basescip-python python sphinxcontrib-towncrier 0.4.0a0 `src.sphinxcontrib.towncrier._fragment_discovery`/_find_config_file().(base): Pathscip-python python python-stdlib 3.11 pathlib/Path#) -> Pathscip-python python python-stdlib 3.11 pathlib/Path#: |
| 40 |
"""Find the best config file.""" |
| 41 |
candidate_names = 'towncrier.toml', 'pyproject.toml' |
| 42 |
candidates = listscip-python python python-stdlib 3.11 builtins/list#(mapscip-python python python-stdlib 3.11 builtins/map#(basescip-python python sphinxcontrib-towncrier 0.4.0a0 `src.sphinxcontrib.towncrier._fragment_discovery`/_find_config_file().(base).joinpathscip-python python python-stdlib 3.11 pathlib/PurePath#joinpath()., candidate_names)) |
| 43 |
extant = filterscip-python python python-stdlib 3.11 builtins/filter#(Pathscip-python python python-stdlib 3.11 pathlib/Path#.is_filescip-python python python-stdlib 3.11 pathlib/Path#is_file()., candidates) |
| 44 |
return nextscip-python python python-stdlib 3.11 builtins/next().(extant, candidates[-1]) |
| 45 |
|
| 46 |
|
| 47 |
# pylint: disable=fixme |
| 48 |
# FIXME: refactor `lookup_towncrier_fragments` to drop noqas |
| 49 |
@lru_cachescip-python python python-stdlib 3.11 functools/lru_cache().(maxsizescip-python python python-stdlib 3.11 functools/lru_cache().(maxsize)=1, typedscip-python python python-stdlib 3.11 functools/lru_cache().(typed)=True) # noqa: WPS210 |
| 50 |
def lookup_towncrier_fragmentsscip-python python sphinxcontrib-towncrier 0.4.0a0 `src.sphinxcontrib.towncrier._fragment_discovery`/lookup_towncrier_fragments().( # noqa: WPS210 |
| 51 |
working_dirscip-python python sphinxcontrib-towncrier 0.4.0a0 `src.sphinxcontrib.towncrier._fragment_discovery`/lookup_towncrier_fragments().(working_dir): Optionalscip-python python python-stdlib 3.11 typing/Optional.[strscip-python python python-stdlib 3.11 builtins/str#] = None, |
| 52 |
config_pathscip-python python sphinxcontrib-towncrier 0.4.0a0 `src.sphinxcontrib.towncrier._fragment_discovery`/lookup_towncrier_fragments().(config_path): Optionalscip-python python python-stdlib 3.11 typing/Optional.[strscip-python python python-stdlib 3.11 builtins/str#] = None, |
| 53 |
) -> Setscip-python python python-stdlib 3.11 typing/Set.[Pathscip-python python python-stdlib 3.11 pathlib/Path#]: |
| 54 |
"""Emit RST-formatted Towncrier changelog fragment paths.""" |
| •55 |
tc_version = Version(version('towncrier')) |
| 56 |
if tc_version >= Version('24.7.0'): |
| 57 |
return _lookup_towncrier_fragments_post24_7scip-python python sphinxcontrib-towncrier 0.4.0a0 `src.sphinxcontrib.towncrier._fragment_discovery`/_lookup_towncrier_fragments_post24_7().(working_dirscip-python python sphinxcontrib-towncrier 0.4.0a0 `src.sphinxcontrib.towncrier._fragment_discovery`/lookup_towncrier_fragments().(working_dir), config_pathscip-python python sphinxcontrib-towncrier 0.4.0a0 `src.sphinxcontrib.towncrier._fragment_discovery`/lookup_towncrier_fragments().(config_path)) |
| 58 |
else: |
| 59 |
return _lookup_towncrier_fragments_pre24_7scip-python python sphinxcontrib-towncrier 0.4.0a0 `src.sphinxcontrib.towncrier._fragment_discovery`/_lookup_towncrier_fragments_pre24_7().(working_dirscip-python python sphinxcontrib-towncrier 0.4.0a0 `src.sphinxcontrib.towncrier._fragment_discovery`/lookup_towncrier_fragments().(working_dir), config_pathscip-python python sphinxcontrib-towncrier 0.4.0a0 `src.sphinxcontrib.towncrier._fragment_discovery`/lookup_towncrier_fragments().(config_path)) |
| 60 |
|
| 61 |
|
| 62 |
# used for towncrier version 24.7 and above |
| 63 |
def _lookup_towncrier_fragments_post24_7scip-python python sphinxcontrib-towncrier 0.4.0a0 `src.sphinxcontrib.towncrier._fragment_discovery`/_lookup_towncrier_fragments_post24_7().( |
| 64 |
working_dirscip-python python sphinxcontrib-towncrier 0.4.0a0 `src.sphinxcontrib.towncrier._fragment_discovery`/_lookup_towncrier_fragments_post24_7().(working_dir): Optionalscip-python python python-stdlib 3.11 typing/Optional.[strscip-python python python-stdlib 3.11 builtins/str#] = None, config_pathscip-python python sphinxcontrib-towncrier 0.4.0a0 `src.sphinxcontrib.towncrier._fragment_discovery`/_lookup_towncrier_fragments_post24_7().(config_path): Optionalscip-python python python-stdlib 3.11 typing/Optional.[strscip-python python python-stdlib 3.11 builtins/str#] = None, |
| 65 |
) -> Setscip-python python python-stdlib 3.11 typing/Set.[Pathscip-python python python-stdlib 3.11 pathlib/Path#]: |
| 66 |
project_path = Pathscip-python python python-stdlib 3.11 pathlib/Path#.cwdscip-python python python-stdlib 3.11 pathlib/Path#cwd().() if working_dirscip-python python sphinxcontrib-towncrier 0.4.0a0 `src.sphinxcontrib.towncrier._fragment_discovery`/_lookup_towncrier_fragments_post24_7().(working_dir) is None else Pathscip-python python python-stdlib 3.11 pathlib/Path#(working_dirscip-python python sphinxcontrib-towncrier 0.4.0a0 `src.sphinxcontrib.towncrier._fragment_discovery`/_lookup_towncrier_fragments_post24_7().(working_dir)) |
| 67 |
|
| 68 |
final_config_path = ( |
| 69 |
_resolve_spec_configscip-python python sphinxcontrib-towncrier 0.4.0a0 `src.sphinxcontrib.towncrier._fragment_discovery`/_resolve_spec_config().(project_path, config_pathscip-python python sphinxcontrib-towncrier 0.4.0a0 `src.sphinxcontrib.towncrier._fragment_discovery`/_lookup_towncrier_fragments_post24_7().(config_path)) |
| 70 |
or _find_config_filescip-python python sphinxcontrib-towncrier 0.4.0a0 `src.sphinxcontrib.towncrier._fragment_discovery`/_find_config_file().(project_path) |
| 71 |
) |
| 72 |
|
| 73 |
try: |
| 74 |
towncrier_config = get_towncrier_configscip-python python sphinxcontrib-towncrier 0.4.0a0 `src.sphinxcontrib.towncrier._towncrier`/get_towncrier_config().( |
| 75 |
project_path, |
| 76 |
final_config_path, |
| 77 |
) |
| 78 |
except KeyErrorscip-python python python-stdlib 3.11 builtins/KeyError# as key_err: |
| 79 |
# NOTE: The error is missing key 'towncrier' or similar |
| 80 |
loggerscip-python python sphinxcontrib-towncrier 0.4.0a0 `src.sphinxcontrib.towncrier._fragment_discovery`/logger..warning( |
| 81 |
f'Missing key {key_err!s} in file {final_config_path!s}', |
| 82 |
) |
| 83 |
return setscip-python python python-stdlib 3.11 builtins/set#() |
| 84 |
|
| •85 |
fragment_base_directory = project_path / (towncrier_config.directory or 'newsfragments') |
| 86 |
|
| 87 |
_fragments, fragment_filenames = find_fragments( |
| 88 |
strscip-python python python-stdlib 3.11 builtins/str#(fragment_base_directory), towncrier_config, strict=False, |
| 89 |
) |
| 90 |
|
| 91 |
return {f[0] for f in fragment_filenames} |
| 92 |
|
| 93 |
|
| 94 |
# used for versions of towncrier before 24.7 |
| 95 |
def _lookup_towncrier_fragments_pre24_7scip-python python sphinxcontrib-towncrier 0.4.0a0 `src.sphinxcontrib.towncrier._fragment_discovery`/_lookup_towncrier_fragments_pre24_7().( |
| 96 |
working_dirscip-python python sphinxcontrib-towncrier 0.4.0a0 `src.sphinxcontrib.towncrier._fragment_discovery`/_lookup_towncrier_fragments_pre24_7().(working_dir): Optionalscip-python python python-stdlib 3.11 typing/Optional.[strscip-python python python-stdlib 3.11 builtins/str#] = None, config_pathscip-python python sphinxcontrib-towncrier 0.4.0a0 `src.sphinxcontrib.towncrier._fragment_discovery`/_lookup_towncrier_fragments_pre24_7().(config_path): Optionalscip-python python python-stdlib 3.11 typing/Optional.[strscip-python python python-stdlib 3.11 builtins/str#] = None, |
| 97 |
) -> Setscip-python python python-stdlib 3.11 typing/Set.[Pathscip-python python python-stdlib 3.11 pathlib/Path#]: |
| 98 |
project_path = Pathscip-python python python-stdlib 3.11 pathlib/Path#.cwdscip-python python python-stdlib 3.11 pathlib/Path#cwd().() if working_dirscip-python python sphinxcontrib-towncrier 0.4.0a0 `src.sphinxcontrib.towncrier._fragment_discovery`/_lookup_towncrier_fragments_pre24_7().(working_dir) is None else Pathscip-python python python-stdlib 3.11 pathlib/Path#(working_dirscip-python python sphinxcontrib-towncrier 0.4.0a0 `src.sphinxcontrib.towncrier._fragment_discovery`/_lookup_towncrier_fragments_pre24_7().(working_dir)) |
| 99 |
|
| 100 |
final_config_path = ( |
| 101 |
_resolve_spec_configscip-python python sphinxcontrib-towncrier 0.4.0a0 `src.sphinxcontrib.towncrier._fragment_discovery`/_resolve_spec_config().(project_path, config_pathscip-python python sphinxcontrib-towncrier 0.4.0a0 `src.sphinxcontrib.towncrier._fragment_discovery`/_lookup_towncrier_fragments_pre24_7().(config_path)) |
| 102 |
or _find_config_filescip-python python sphinxcontrib-towncrier 0.4.0a0 `src.sphinxcontrib.towncrier._fragment_discovery`/_find_config_file().(project_path) |
| 103 |
) |
| 104 |
|
| 105 |
try: |
| 106 |
towncrier_config = get_towncrier_config_as_dictscip-python python sphinxcontrib-towncrier 0.4.0a0 `src.sphinxcontrib.towncrier._towncrier`/get_towncrier_config_as_dict().( |
| 107 |
project_path, |
| 108 |
final_config_path, |
| 109 |
) |
| 110 |
except KeyErrorscip-python python python-stdlib 3.11 builtins/KeyError# as key_err: |
| 111 |
# NOTE: The error is missing key 'towncrier' or similar |
| 112 |
loggerscip-python python sphinxcontrib-towncrier 0.4.0a0 `src.sphinxcontrib.towncrier._fragment_discovery`/logger..warning( |
| 113 |
f'Missing key {key_err!s} in file {final_config_path!s}', |
| 114 |
) |
| 115 |
return setscip-python python python-stdlib 3.11 builtins/set#() |
| 116 |
|
| 117 |
fragment_directory: Optionalscip-python python python-stdlib 3.11 typing/Optional.[strscip-python python python-stdlib 3.11 builtins/str#] = 'newsfragments' |
| 118 |
try: |
| 119 |
fragment_base_directory = project_path / towncrier_config['directory'] |
| 120 |
except KeyErrorscip-python python python-stdlib 3.11 builtins/KeyError#: |
| 121 |
assert fragment_directory is not None |
| 122 |
fragment_base_directory = project_path / fragment_directory |
| 123 |
else: |
| 124 |
fragment_directory = None |
| 125 |
|
| 126 |
_fragments, fragment_filenames = find_fragments( |
| 127 |
strscip-python python python-stdlib 3.11 builtins/str#(fragment_base_directory), |
| 128 |
towncrier_config['sections'], |
| 129 |
fragment_directory, |
| 130 |
towncrier_config['types'], |
| 131 |
) |
| 132 |
return setscip-python python python-stdlib 3.11 builtins/set#(fragment_filenames) |