All of lore.kernel.org
 help / color / mirror / Atom feed
* [Buildroot] [RFC] scanpypi: handle packages with wrong metadata
@ 2018-01-26 13:32 yegorslists at googlemail.com
  2018-01-29 22:19 ` Thomas Petazzoni
  0 siblings, 1 reply; 3+ messages in thread
From: yegorslists at googlemail.com @ 2018-01-26 13:32 UTC (permalink / raw)
  To: buildroot

From: Yegor Yefremov <yegorslists@googlemail.com>

Some packages like python-adafruit-ads1x15 have different values in
PyPI metadata and setup.py or tar file name.

Use package name (self.pkg_name) derived from tar file name instead
of metadata_name taken from JSON.

Also output the missing key when trying to setup arguments.

Signed-off-by: Yegor Yefremov <yegorslists@googlemail.com>
---
 utils/scanpypi | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/utils/scanpypi b/utils/scanpypi
index 7392c50..0add12b 100755
--- a/utils/scanpypi
+++ b/utils/scanpypi
@@ -130,6 +130,7 @@ class BuildrootPackage():
         self.md5_sum = None
         self.metadata = None
         self.metadata_name = None
+        self.pkg_name = None
         self.metadata_url = None
         self.pkg_req = None
         self.setup_metadata = None
@@ -249,10 +250,12 @@ class BuildrootPackage():
                     os.makedirs(tmp_pkg)
                 as_tarfile.extractall(tmp_pkg)
 
+        index_of_pkg_version = self.filename.index(self.version) - 1
+        self.pkg_name = self.filename[:index_of_pkg_version]
         tmp_extract = '{folder}/{name}-{version}'
         self.tmp_extract = tmp_extract.format(
             folder=tmp_pkg,
-            name=self.metadata_name,
+            name=self.pkg_name,
             version=self.version)
 
     def load_setup(self):
@@ -265,14 +268,15 @@ class BuildrootPackage():
         s_file, s_path, s_desc = imp.find_module('setup', [self.tmp_extract])
         setup = imp.load_module('setup', s_file, s_path, s_desc)
         try:
-            self.setup_metadata = self.setup_args[self.metadata_name]
-        except KeyError:
+            self.setup_metadata = self.setup_args[self.pkg_name]
+        except KeyError as err:
+            print('Following key is missing: {}'.format(err))
             # This means setup was not called which most likely mean that it is
             # called through the if __name__ == '__main__' directive.
             # In this case, we can only pray that it is called through a
             # function called main() in setup.py.
             setup.main()  # Will raise AttributeError if not found
-            self.setup_metadata = self.setup_args[self.metadata_name]
+            self.setup_metadata = self.setup_args[self.pkg_name]
         # Here we must remove the module the hard way.
         # We must do this because of a very specific case: if a package calls
         # setup from the __main__ but does not come with a 'main()' function,
-- 
2.1.4

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [Buildroot] [RFC] scanpypi: handle packages with wrong metadata
  2018-01-26 13:32 [Buildroot] [RFC] scanpypi: handle packages with wrong metadata yegorslists at googlemail.com
@ 2018-01-29 22:19 ` Thomas Petazzoni
  2018-01-30  7:43   ` Yegor Yefremov
  0 siblings, 1 reply; 3+ messages in thread
From: Thomas Petazzoni @ 2018-01-29 22:19 UTC (permalink / raw)
  To: buildroot

Hello,

On Fri, 26 Jan 2018 14:32:50 +0100, yegorslists at googlemail.com wrote:
> From: Yegor Yefremov <yegorslists@googlemail.com>
> 
> Some packages like python-adafruit-ads1x15 have different values in
> PyPI metadata and setup.py or tar file name.
> 
> Use package name (self.pkg_name) derived from tar file name instead
> of metadata_name taken from JSON.
> 
> Also output the missing key when trying to setup arguments.
> 
> Signed-off-by: Yegor Yefremov <yegorslists@googlemail.com>

Do we really want to do this? Shouldn't we instead ask the upstream
maintainers to fix their Python package? I have the feeling that this
is a slippery road, and we could start adding lots and lots of weird
logic to support packages with wrong metadata.

If it's only fixing one specific package, I'd say the script should
instead detect the inconsistency, and bail out.

Best regards,

Thomas
-- 
Thomas Petazzoni, CTO, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Buildroot] [RFC] scanpypi: handle packages with wrong metadata
  2018-01-29 22:19 ` Thomas Petazzoni
@ 2018-01-30  7:43   ` Yegor Yefremov
  0 siblings, 0 replies; 3+ messages in thread
From: Yegor Yefremov @ 2018-01-30  7:43 UTC (permalink / raw)
  To: buildroot

On Mon, Jan 29, 2018 at 11:19 PM, Thomas Petazzoni
<thomas.petazzoni@free-electrons.com> wrote:
> Hello,
>
> On Fri, 26 Jan 2018 14:32:50 +0100, yegorslists at googlemail.com wrote:
>> From: Yegor Yefremov <yegorslists@googlemail.com>
>>
>> Some packages like python-adafruit-ads1x15 have different values in
>> PyPI metadata and setup.py or tar file name.
>>
>> Use package name (self.pkg_name) derived from tar file name instead
>> of metadata_name taken from JSON.
>>
>> Also output the missing key when trying to setup arguments.
>>
>> Signed-off-by: Yegor Yefremov <yegorslists@googlemail.com>
>
> Do we really want to do this? Shouldn't we instead ask the upstream
> maintainers to fix their Python package? I have the feeling that this
> is a slippery road, and we could start adding lots and lots of weird
> logic to support packages with wrong metadata.

That's why I sent it as RFC. I've filed an issue [1], but I doubt it
will be fixed.

> If it's only fixing one specific package, I'd say the script should
> instead detect the inconsistency, and bail out.

I'll do it.

[1] https://github.com/adafruit/Adafruit_Python_ADS1x15/issues/9

Yegor

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2018-01-30  7:43 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-01-26 13:32 [Buildroot] [RFC] scanpypi: handle packages with wrong metadata yegorslists at googlemail.com
2018-01-29 22:19 ` Thomas Petazzoni
2018-01-30  7:43   ` Yegor Yefremov

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.