Skip to contentSkip to conversation

utils/scanpypi: handle underscores in python packages

PATCH New james.hilliard1 at gmail.com 2 participants 2 messages Feb 24, 2019 – Mar 1, 2019

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 utils/scanpypi: handle underscores in python packages

From: James Hilliard <[email protected]>

Some python packages seem to use underscores in inconsistent ways, we can attempt to normalize these by always using dashes for the buildroot name and attempting to autodetect the correct metadata name format.

---
 utils/scanpypi | 7 +++++++
 1 file changed, 7 insertions(+)
utils/scanpypi +7 -0
index bdce6924b6..55b3d1e61c 100755
@@ -97,6 +97,7 @@ def pkg_buildroot_name(pkg_name):
     pkg_name -- String to rename
     """
     name = re.sub('[^\w-]', '', pkg_name.lower())
+    name = name.replace('_', '-')
     prefix = 'python-'
     pattern = re.compile('^(?!' + prefix + ')(.+?)$')
     name = pattern.sub(r'python-\1', name)
@@ -299,6 +300,12 @@ class BuildrootPackage():
         sys.path.append(self.tmp_extract)
         s_file, s_path, s_desc = imp.find_module('setup', [self.tmp_extract])
         setup = imp.load_module('setup', s_file, s_path, s_desc)
+        if self.metadata_name in self.setup_args:
+            pass
+        elif self.metadata_name.replace('_', '-') in self.setup_args:
+            self.metadata_name = self.metadata_name.replace('_', '-')
+        elif self.metadata_name.replace('-', '_') in self.setup_args:
+            self.metadata_name = self.metadata_name.replace('-', '_')
         try:
             self.setup_metadata = self.setup_args[self.metadata_name]
         except KeyError:
Signature · 1 line
2.17.1
#1 lore raw

PATCH 1/1 utils/scanpypi: handle underscores in python packages

Quoted 25 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

"james" == james hilliard1 <[email protected]> writes:

From: James Hilliard <[email protected]>
Some python packages seem to use underscores in inconsistent ways, we can attempt to normalize these by always using dashes for the buildroot name and attempting to autodetect the correct metadata name format.

---
 utils/scanpypi | 7 +++++++
 1 file changed, 7 insertions(+)
utils/scanpypi +1 -0
index bdce6924b6..55b3d1e61c 100755
@@ -97,6 +97,7 @@ def pkg_buildroot_name(pkg_name):
     pkg_name -- String to rename
     """
     name = re.sub('[^\w-]', '', pkg_name.lower())
+    name = name.replace('_', '-')
     prefix = 'python-'
     pattern = re.compile('^(?!' + prefix + ')(.+?)$')
     name = pattern.sub(r'python-\1', name)

utils/scanpypi class BuildrootPackage(): · line 308

Quoted 9 lines
utils/scanpypi +6 -0
@@ -299,6 +300,12 @@ class BuildrootPackage():
         sys.path.append(self.tmp_extract)
         s_file, s_path, s_desc = imp.find_module('setup', [self.tmp_extract])
         setup = imp.load_module('setup', s_file, s_path, s_desc)
+        if self.metadata_name in self.setup_args:
+            pass
+        elif self.metadata_name.replace('_', '-') in self.setup_args:
+            self.metadata_name = self.metadata_name.replace('_', '-')
+        elif self.metadata_name.replace('-', '_') in self.setup_args:
+            self.metadata_name = self.metadata_name.replace('-', '_')

I'm not sure we need the first if, but OK.

Committed, thanks.

Signature · 1 line
Bye, Peter Korsgaard