From 2b09e05b5831541e19eb8a6cbaf216bfe08f6c8f Mon Sep 17 00:00:00 2001 From: James Hilliard Date: Sun, 13 Mar 2022 10:50:30 -0600 Subject: [PATCH] utils/scanpypi: support alternative Homepage format Some packages only have a home page properly set inside project_urls. Squelch flake8's E127, because a visual indent here is really nicer. Signed-off-by: James Hilliard [yann.morin.1998@free.fr: simplify getting home_page fallbacks] Signed-off-by: Yann E. MORIN --- utils/scanpypi | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/utils/scanpypi b/utils/scanpypi index 17d8a0017a..cc13701c0e 100755 --- a/utils/scanpypi +++ b/utils/scanpypi @@ -609,7 +609,8 @@ class BuildrootPackage(): lines.append('\thelp\n') - help_lines = textwrap.wrap(self.metadata['info']['summary'], 62, + md_info = self.metadata['info'] + help_lines = textwrap.wrap(md_info['summary'], 62, initial_indent='\t ', subsequent_indent='\t ') @@ -617,11 +618,15 @@ class BuildrootPackage(): if help_lines[-1][-1] != '.': help_lines[-1] += '.' - # \t + two spaces is 3 char long - help_lines.append('') - help_lines.append('\t ' + self.metadata['info']['home_page']) - help_lines = [x + '\n' for x in help_lines] - lines += help_lines + home_page = md_info.get('home_page', None) or \ + md_info.get('project_urls', {}).get('Homepage', None) # noqa: E127 + + if home_page: + # \t + two spaces is 3 char long + help_lines.append('') + help_lines.append('\t ' + home_page) + help_lines = [x + '\n' for x in help_lines] + lines += help_lines with open(path_to_config, 'w') as config_file: config_file.writelines(lines)