Skip to contentSkip to conversation

utils/scanpypi: support alternative Homepage format

PATCH Applied James Hilliard 2 participants 2 messages Mar 13, 2022

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 utils/scanpypi: support alternative Homepage format

Some packages only have a home page properly set inside project_urls.

---
 utils/scanpypi | 19 +++++++++++++------
 1 file changed, 13 insertions(+), 6 deletions(-)
utils/scanpypi +13 -6
index 17d8a0017a..681758a552 100755
@@ -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,17 @@ 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)
+        if home_page is None or len(home_page) == 0:
+            project_urls = md_info.get('project_urls', {})
+            home_page = project_urls.get('Homepage', None)
+
+        if home_page is not None and len(home_page) != 0:
+            # \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)
Signature · 6 lines
2.25.1

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot
#1 lore raw

James, All,

On 2022-03-13 10:50 -0600, James Hilliard spake thusly:

Quoted 22 lines

Some packages only have a home page properly set inside project_urls.

---
 utils/scanpypi | 19 +++++++++++++------
 1 file changed, 13 insertions(+), 6 deletions(-)
utils/scanpypi +2 -1
index 17d8a0017a..681758a552 100755
@@ -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  ')
 

utils/scanpypi class BuildrootPackage(): · line 622

Quoted 10 lines
utils/scanpypi +2 -5
@@ -617,11 +618,17 @@ 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)
+        if home_page is None or len(home_page) == 0:

I think this can be shortened to:

if not home_page:
[...]

Indeed:
- None tets as False
- an empty string tests as False

So, 'not home_page' will evaluate to True if it is either None, or if its length is zero.

utils/scanpypi class BuildrootPackage(): · line 626

Quoted 4 lines
utils/scanpypi +4 -0
+            project_urls = md_info.get('project_urls', {})
+            home_page = project_urls.get('Homepage', None)
+
+        if home_page is not None and len(home_page) != 0:

Similarly, I think this could be shortened to just;

    if home_page:
        [...]

So 'home_page' will only evaluate to True if it is not None and its length is not zero.

And eventually, all this can be simplified even further:

    home_page = md_info.get('home_page', None) or \
                md_info.get('project_urls', {}).get('Homepage', None)

(and squelch flake8's E127)

Applied to master with the above simplification, thanks.

Regards,
Yann E. MORIN.

Quoted 15 lines
utils/scanpypi +5 -0
+            # \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)
Signature · 6 lines
2.25.1

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot
Signature · 10 lines
.-----------------.--------------------.------------------.--------------------.
|  Yann E. MORIN  | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: |
| +33 662 376 056 | Software  Designer | \ / CAMPAIGN     |  ___               |
| +33 561 099 427 `------------.-------:  X  AGAINST      |  \e/  There is no  |
| http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL    |   v   conspiracy.  |
'------------------------------^-------^------------------^--------------------'
_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot