Source code for sphinxcontrib.towncrier._towncrier
"""Towncrier related shims."""fromcontextlibimportsuppressassuppress_exceptionsfrompathlibimportPathfromtypingimportSet,Unionfromtowncrier._settings.loadimportConfig# noqa: WPS436fromtowncrier._settings.loadimportload_config_from_file# noqa: WPS436fromtowncrier._settings.loadimport(# noqa: WPS436ConfigErrorasTowncrierConfigError,)fromtowncrier.buildimportfind_fragments
[docs]deffind_towncrier_fragments(base_directory:str,towncrier_config:Config,)->Set[str]:"""Look up the change note file paths."""withsuppress_exceptions(TypeError):# Towncrier >= 24.7.0rc1_fragments,fragment_filenames=find_fragments(base_directory=base_directory,config=towncrier_config,strict=False,)return{fname[0]forfnameinfragment_filenames}# Towncrier < 24.7.0rc1try:# pylint: disable-next=no-value-for-parameter,unexpected-keyword-arg_fragments,fragment_filenames=find_fragments(# noqa: WPS121base_directory=base_directory,sections=towncrier_config.sections,fragment_directory=towncrier_config.directory,frag_type_names=towncrier_config.types,orphan_prefix='+',)exceptTowncrierConfigErroraslookup_err:raiseLookupError('Towncrier was unable to perform change note lookup: 'f'{lookup_err!s}',)fromlookup_errreturnset(fragment_filenames)
[docs]defget_towncrier_config(project_path:Path,final_config_path:Union[Path,None],)->Config:"""Return the towncrier config in native format."""try:returnload_config_from_file(str(project_path),str(final_config_path))except(FileNotFoundError,TowncrierConfigError)asconfig_load_err:raiseLookupError('Towncrier was unable to load the configuration from file 'f'`{final_config_path!s}`: {config_load_err!s}',)fromconfig_load_err